summaryrefslogtreecommitdiffstats
path: root/ipfs-api/src/client/internal.rs
diff options
context:
space:
mode:
authorArda Xi <arda@ardaxi.com>2020-05-22 17:37:20 +0200
committerArda Xi <arda@ardaxi.com>2020-05-22 17:45:01 +0200
commit96097c501be6ab10cc6ca1bab9209041d4bdf1e8 (patch)
tree2643f6e7127445a2de9906f03d812f5cdaecf390 /ipfs-api/src/client/internal.rs
parentbbc48f85bac7565a11b77313f6aed7c44b9ebeed (diff)
Expose requests module and add builder for requests like add_with_options (fixes #26)
Diffstat (limited to 'ipfs-api/src/client/internal.rs')
-rw-r--r--ipfs-api/src/client/internal.rs36
1 files changed, 34 insertions, 2 deletions
diff --git a/ipfs-api/src/client/internal.rs b/ipfs-api/src/client/internal.rs
index 2c0d2af..ffac9c9 100644
--- a/ipfs-api/src/client/internal.rs
+++ b/ipfs-api/src/client/internal.rs
@@ -444,11 +444,43 @@ impl IpfsClient {
where
R: 'static + Read + Send + Sync,
{
+ self.add_with_options(data, request::Add::default()).await
+ }
+
+ /// Add a file to IPFS with options.
+ ///
+ /// # Examples
+ ///
+ /// ```no_run
+ /// # extern crate ipfs_api;
+ /// #
+ /// use ipfs_api::IpfsClient;
+ /// use std::io::Cursor;
+ ///
+ /// # fn main() {
+ /// let client = IpfsClient::default();
+ /// let data = Cursor::new("Hello World!");
+ /// let add =
+ /// ipfs_api::request::AddBuilder::default()
+ /// .chunker("rabin-512-1024-2048").build().unwrap();
+ /// let req = client.add_with_options(data, add);
+ /// # }
+ /// ```
+ ///
+ #[inline]
+ pub async fn add_with_options<R>(
+ &self,
+ data: R,
+ add: request::Add<'_>,
+ ) -> Result<response::AddResponse, Error>
+ where
+ R: 'static + Read + Send + Sync,
+ {
let mut form = multipart::Form::default();
form.add_reader("path", data);
- self.request(request::Add, Some(form)).await
+ self.request(add, Some(form)).await
}
/// Add a path to Ipfs. Can be a file or directory.
@@ -515,7 +547,7 @@ impl IpfsClient {
}
}
- let req = self.build_base_request(request::Add, Some(form))?;
+ let req = self.build_base_request(request::Add::default(), Some(form))?;
self.request_stream_json(req).try_collect().await
}