From 92b2195cbab6ec9cc09562213c2209e4973e9c91 Mon Sep 17 00:00:00 2001 From: Ferris Tseng Date: Mon, 22 Feb 2021 23:41:20 -0500 Subject: add tar and version commands --- ipfs-api-prelude/src/api.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/ipfs-api-prelude/src/api.rs b/ipfs-api-prelude/src/api.rs index 611092a..dc7e06c 100644 --- a/ipfs-api-prelude/src/api.rs +++ b/ipfs-api-prelude/src/api.rs @@ -887,6 +887,59 @@ pub trait IpfsApi: Backend { ) -> Result { self.request_empty(options, None).await } + + /// Add a tar file to Ipfs. + /// + /// Note: `data` should already be a tar file. If it isn't the Api will return + /// an error. + /// + /// ```no_run + /// use ipfs_api::{IpfsApi, IpfsClient}; + /// use std::fs::File; + /// + /// let client = IpfsClient::default(); + /// let tar = File::open("/path/to/file.tar").unwrap(); + /// let res = client.tar_add(tar); + /// ``` + /// + async fn tar_add(&self, data: R) -> Result + where + R: 'static + Read + Send + Sync, + { + let mut form = multipart::Form::default(); + + form.add_reader("file", data); + + self.request(request::TarAdd, Some(form)).await + } + + /// Export a tar file from Ipfs. + /// + /// ```no_run + /// use ipfs_api::{IpfsApi, IpfsClient}; + /// + /// let client = IpfsClient::default(); + /// let res = client.tar_cat("/ipfs/QmVrLsEDn27sScp3k23sgZNefVTjSAL3wpgW1iWPi4MgoY"); + /// ``` + /// + fn tar_cat(&self, path: &str) -> Box> + Unpin> { + impl_stream_api_response! { + (self, request::TarCat { path }, None) => request_stream_bytes + } + } + + /// Returns information about the Ipfs server version. + /// + /// ```no_run + /// use ipfs_api::{IpfsApi, IpfsClient}; + /// + /// let client = IpfsClient::default(); + /// let res = client.version(); + /// ``` + /// + async fn version(&self) -> Result { + self.request(request::Version, None).await + } } impl IpfsApi for B where B: Backend {} -- cgit v1.2.3