summaryrefslogtreecommitdiffstats
path: root/ipfs-cli
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2017-11-26 15:17:44 -0500
committerFerris Tseng <ferristseng@fastmail.fm>2017-11-26 15:17:44 -0500
commit8e9a5d3f8f2e092ccf06dfd738575d40a1bb791b (patch)
tree6b1260564f46605bb651e22dd054dbf0fbbaf62d /ipfs-cli
parent43413b530a8e81cb5442cf05423def787cdf1811 (diff)
stream read responses
Diffstat (limited to 'ipfs-cli')
-rw-r--r--ipfs-cli/src/command/block.rs8
-rw-r--r--ipfs-cli/src/command/cat.rs9
-rw-r--r--ipfs-cli/src/command/files.rs9
3 files changed, 20 insertions, 6 deletions
diff --git a/ipfs-cli/src/command/block.rs b/ipfs-cli/src/command/block.rs
index 8cf004e..0a181ad 100644
--- a/ipfs-cli/src/command/block.rs
+++ b/ipfs-cli/src/command/block.rs
@@ -8,6 +8,7 @@
use clap::{App, ArgMatches};
use command::{verify_file, EXPECTED_API, EXPECTED_FILE};
+use futures::stream::Stream;
use ipfs_api::IpfsClient;
use std::fs::File;
use tokio_core::reactor::Core;
@@ -41,9 +42,12 @@ pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
match args.subcommand() {
("get", Some(args)) => {
let key = args.value_of("KEY").unwrap();
- let block = core.run(client.block_get(key)).expect(EXPECTED_API);
+ let req = client.block_get(key).for_each(|chunk| {
+ println!("{}", String::from_utf8_lossy(&chunk));
+ Ok(())
+ });
- println!("{}", String::from_utf8_lossy(&block));
+ core.run(req).expect(EXPECTED_API);
}
("put", Some(args)) => {
let path = args.value_of("INPUT").unwrap();
diff --git a/ipfs-cli/src/command/cat.rs b/ipfs-cli/src/command/cat.rs
index 55872b0..559bd24 100644
--- a/ipfs-cli/src/command/cat.rs
+++ b/ipfs-cli/src/command/cat.rs
@@ -8,6 +8,7 @@
use clap::{App, ArgMatches};
use command::EXPECTED_API;
+use futures::stream::Stream;
use ipfs_api::IpfsClient;
use tokio_core::reactor::Core;
@@ -23,7 +24,11 @@ pub fn signature<'a, 'b>() -> App<'a, 'b> {
pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
let path = args.value_of("PATH").unwrap();
- let data = core.run(client.cat(&path)).expect(EXPECTED_API);
+ let req = client.cat(&path).for_each(|chunk| {
+ println!("{}", String::from_utf8_lossy(&chunk));
- println!("{}", String::from_utf8_lossy(&data));
+ Ok(())
+ });
+
+ core.run(req).expect(EXPECTED_API);
}
diff --git a/ipfs-cli/src/command/files.rs b/ipfs-cli/src/command/files.rs
index 03bef88..7cdf3de 100644
--- a/ipfs-cli/src/command/files.rs
+++ b/ipfs-cli/src/command/files.rs
@@ -8,6 +8,7 @@
use clap::{App, ArgMatches};
use command::{verify_file, EXPECTED_API, EXPECTED_FILE};
+use futures::stream::Stream;
use ipfs_api::IpfsClient;
use std::fs::File;
use tokio_core::reactor::Core;
@@ -123,9 +124,13 @@ pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
}
("read", Some(args)) => {
let path = args.value_of("PATH").unwrap();
- let data = core.run(client.files_read(&path)).expect(EXPECTED_API);
+ let req = client.files_read(&path).for_each(|chunk| {
+ println!("{}", String::from_utf8_lossy(&chunk));
- println!("{}", String::from_utf8_lossy(&data));
+ Ok(())
+ });
+
+ core.run(req).expect(EXPECTED_API);
}
("rm", Some(args)) => {
let path = args.value_of("PATH").unwrap();