summaryrefslogtreecommitdiffstats
path: root/ipfs-api/examples
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2017-11-24 15:46:08 -0500
committerFerris Tseng <ferristseng@fastmail.fm>2017-11-24 15:46:08 -0500
commit6a0af36df9a57f80d18fdcd33474e88d7dc1e29c (patch)
treeb0ff0715c5d0f9105ae3108bb3f105f33323c873 /ipfs-api/examples
parent759312b12344e27e9bcec318453eb9f66616d24c (diff)
add implementation for files write
Diffstat (limited to 'ipfs-api/examples')
-rw-r--r--ipfs-api/examples/mfs.rs31
1 files changed, 25 insertions, 6 deletions
diff --git a/ipfs-api/examples/mfs.rs b/ipfs-api/examples/mfs.rs
index ad8d56f..7c17738 100644
--- a/ipfs-api/examples/mfs.rs
+++ b/ipfs-api/examples/mfs.rs
@@ -9,12 +9,23 @@
extern crate ipfs_api;
extern crate tokio_core;
-use ipfs_api::IpfsClient;
+use ipfs_api::{response, IpfsClient};
+use std::fs::File;
use tokio_core::reactor::Core;
+fn print_stat(stat: response::FilesStatResponse) {
+ println!(" type : {}", stat.typ);
+ println!(" hash : {}", stat.hash);
+ println!(" size : {}", stat.size);
+ println!(" cum. size: {}", stat.cumulative_size);
+ println!(" blocks : {}", stat.blocks);
+ println!("");
+}
+
// Creates an Ipfs client, and makes some calls to the Mfs Api.
//
fn main() {
+ println!("note: this must be run in the root of the project repository");
println!("connecting to localhost:5001...");
let mut core = Core::new().expect("expected event loop");
@@ -38,13 +49,21 @@ fn main() {
let req = client.files_stat("/test/does");
let stat = core.run(req).expect("expected stat to succeed");
- println!(" type : {}", stat.typ);
- println!(" hash : {}", stat.hash);
- println!(" size : {}", stat.size);
- println!(" cum. size: {}", stat.cumulative_size);
- println!(" blocks : {}", stat.blocks);
+ print_stat(stat);
+
+ println!("writing source file to /test/mfs.rs");
println!("");
+ let src = File::open(file!()).expect("could not read source file");
+ let req = client.files_write("/test/mfs.rs", true, true, src);
+
+ core.run(req).expect("expected write to succed");
+
+ let req = client.files_stat("/test/mfs.rs");
+ let stat = core.run(req).expect("expected stat to succeed");
+
+ print_stat(stat);
+
println!("removing /test...");
println!("");