在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ferristseng/rust-ipfs-api开源软件地址:https://github.com/ferristseng/rust-ipfs-api开源编程语言:Rust 99.8%开源软件介绍:ipfs-apiComponents
Rust library for connecting to the IPFS HTTP API using Hyper/Actix. UsageUsing HyperTo use the Hyper backend, declare: [dependencies]
ipfs-api-backend-hyper = "0.4" You can specify either Using ActixTo use the Actix backend, declare: [dependencies]
ipfs-api-backend-actix = "0.5" Builder PatternWith either the Hyper or Actix backend, you can specify the Usage (DEPRECATED)[dependencies]
ipfs-api = "0.15.0" Feature Flags (DEPRECATED)You can use [dependencies]
ipfs-api = { version = "0.15.0", features = ["with-actix"], default-features = false } You also have the option of using [dependencies]
ipfs-api = { version = "0.15.0", features = ["with-hyper-rustls"], default-features = false } To enable the builder pattern (default) use the [dependencies]
ipfs-api = { version = "0.15.0", features = ["with-hyper-rustls", "with-builder"], default-features = false } ExamplesWriting a file to IPFSWith Hyperuse ipfs_api::{IpfsApi, IpfsClient};
use std::io::Cursor;
#[tokio::main]
async fn main() {
let client = IpfsClient::default();
let data = Cursor::new("Hello World!");
match client.add(data).await {
Ok(res) => println!("{}", res.hash),
Err(e) => eprintln!("error adding file: {}", e)
}
} With Actixuse ipfs_api::{IpfsApi, IpfsClient};
use std::io::Cursor;
#[actix_rt::main]
async fn main() {
let client = IpfsClient::default();
let data = Cursor::new("Hello World!");
match client.add(data).await {
Ok(res) => println!("{}", res.hash),
Err(e) => eprintln!("error adding file: {}", e)
}
} Reading a file from IPFSWith Hyperuse futures::TryStreamExt;
use ipfs_api::{IpfsApi, IpfsClient};
use std::io::{self, Write};
#[tokio::main]
async fn main() {
let client = IpfsClient::default();
match client
.get("/test/file.json")
.map_ok(|chunk| chunk.to_vec())
.try_concat()
.await
{
Ok(res) => {
let out = io::stdout();
let mut out = out.lock();
out.write_all(&res).unwrap();
}
Err(e) => eprintln!("error getting file: {}", e)
}
} With Actixuse futures::TryStreamExt;
use ipfs_api::{IpfsApi, IpfsClient};
use std::io::{self, Write};
#[actix_rt::main]
async fn main() {
let client = IpfsClient::default();
match client
.get("/test/file.json")
.map_ok(|chunk| chunk.to_vec())
.try_concat()
.await
{
Ok(res) => {
let out = io::stdout();
let mut out = out.lock();
out.write_all(&res).unwrap();
}
Err(e) => eprintln!("error getting file: {}", e)
}
} Additional ExamplesThere are also a bunch of examples included in the project, which I used for testing For a list of examples, run: $ cargo run --example You can run any of the examples with cargo: $ cargo run --example add_file LicenseLicensed under either of
at your option. ContributionUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论