From 0bb7f70f91c422705804ba1fd14411b8c07e6136 Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Thu, 9 Jul 2020 15:19:58 +0900 Subject: ipfs files read/write: add offset, count, parents --- ipfs-api/examples/mfs.rs | 2 +- ipfs-api/src/client/internal.rs | 18 ++++++++++++++---- ipfs-api/src/request/files.rs | 12 ++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) (limited to 'ipfs-api') diff --git a/ipfs-api/examples/mfs.rs b/ipfs-api/examples/mfs.rs index 3d6419c..05851d9 100644 --- a/ipfs-api/examples/mfs.rs +++ b/ipfs-api/examples/mfs.rs @@ -60,7 +60,7 @@ async fn main() { let src = File::open(file!()).expect("could not read source file"); - if let Err(e) = client.files_write("/test/mfs.rs", true, true, src).await { + if let Err(e) = client.files_write("/test/mfs.rs", true, true, false, 0, None, src).await { eprintln!("error writing source file /test/mfs.rs: {}", e); return; } diff --git a/ipfs-api/src/client/internal.rs b/ipfs-api/src/client/internal.rs index 2c0d2af..ef4e9f2 100644 --- a/ipfs-api/src/client/internal.rs +++ b/ipfs-api/src/client/internal.rs @@ -1166,13 +1166,15 @@ impl IpfsClient { /// use ipfs_api::IpfsClient; /// /// let client = IpfsClient::default(); - /// let res = client.files_read("/test/file.json"); + /// let res = client.files_read("/test/file.json", 0, None); /// ``` /// + /// Not specifying a byte `count` reads to the end of the file. + /// #[inline] - pub fn files_read(&self, path: &str) -> impl Stream> { + pub fn files_read(&self, path: &str, offset: i64, count: Option) -> impl Stream> { impl_stream_api_response! { - (self, request::FilesRead { path }, None) => request_stream_bytes + (self, request::FilesRead { path, offset, count }, None) => request_stream_bytes } } @@ -1218,15 +1220,20 @@ impl IpfsClient { /// /// let client = IpfsClient::default(); /// let file = File::open("test.json").unwrap(); - /// let res = client.files_write("/test/file.json", true, true, file); + /// let res = client.files_write("/test/file.json", true, true, true, 0, None, file); /// ``` /// + /// Not specifying a byte `count` writes the entire input. + /// #[inline] pub async fn files_write( &self, path: &str, create: bool, truncate: bool, + parents: bool, + offset: i64, + count: Option, data: R, ) -> Result where @@ -1241,6 +1248,9 @@ impl IpfsClient { path, create, truncate, + parents, + offset, + count, }, Some(form), ) diff --git a/ipfs-api/src/request/files.rs b/ipfs-api/src/request/files.rs index 3ec4186..564bd6c 100644 --- a/ipfs-api/src/request/files.rs +++ b/ipfs-api/src/request/files.rs @@ -71,6 +71,11 @@ impl<'a> ApiRequest for FilesMv<'a> { pub struct FilesRead<'a> { #[serde(rename = "arg")] pub path: &'a str, + + pub offset: i64, + + #[serde(skip_serializing_if = "Option::is_none")] + pub count: Option, } impl<'a> ApiRequest for FilesRead<'a> { @@ -107,6 +112,13 @@ pub struct FilesWrite<'a> { pub create: bool, pub truncate: bool, + + pub parents: bool, + + pub offset: i64, + + #[serde(skip_serializing_if = "Option::is_none")] + pub count: Option, } impl<'a> ApiRequest for FilesWrite<'a> { -- cgit v1.2.3