rust-ipfs/examples/client2.rs

17 lines
579 B
Rust
Raw Normal View History

2019-02-13 23:46:55 +01:00
use futures::prelude::*;
2019-02-18 20:49:57 +01:00
use ipfs::{Block, Ipfs, IpfsOptions, Types};
2019-02-13 23:46:55 +01:00
fn main() {
2019-02-18 18:52:45 +01:00
let options = IpfsOptions::test();
env_logger::Builder::new().parse(&options.ipfs_log).init();
2019-02-18 20:49:57 +01:00
let mut ipfs = Ipfs::<Types>::new(options);
2019-02-13 23:46:55 +01:00
let block = Block::from("hello block\n");
ipfs.put_block(block);
let cid = Block::from("hello block2\n").cid();
let future = ipfs.get_block(cid).map(|block| {
2019-02-18 18:57:52 +01:00
println!("Received block with contents: '{}'",
2019-02-13 23:46:55 +01:00
String::from_utf8_lossy(&block.data()));
});
tokio::run(ipfs.join(future).map(|_| ()));
}