diff --git a/Cargo.toml b/Cargo.toml index 7b8c3cf9..a9e220c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,6 +82,7 @@ webpki-roots = { version = "0.26", optional = true } flate2 = "1.0" tar = "0.4" tokio = { version = "1.38", features = ["fs", "rt-multi-thread", "macros"] } +tokio-util = { version = "0.7", features = ["io"] } yup-hyper-mock = { version = "8.0.0" } once_cell = "1.19" diff --git a/src/container.rs b/src/container.rs index 8d1b97af..0ed9a71d 100644 --- a/src/container.rs +++ b/src/container.rs @@ -2138,6 +2138,35 @@ impl Docker { /// # Returns /// /// - unit type `()`, wrapped in a Future. + /// + /// # Examples + /// + /// ```rust,no_run + /// # use bollard::Docker; + /// use bollard::container::UploadToContainerOptions; + /// use futures_util::{StreamExt, TryFutureExt}; + /// use tokio::fs::File; + /// use tokio_util::io::ReaderStream; + /// + /// # #[tokio::main] + /// # async fn main() { + /// # let docker = Docker::connect_with_http_defaults().unwrap(); + /// let options = Some(UploadToContainerOptions{ + /// path: "/opt", + /// ..Default::default() + /// }); + /// + /// let file = File::open("tarball.tar.gz") + /// .map_ok(ReaderStream::new) + /// .try_flatten_stream() + /// .map(|x|x.expect("failed to stream file")); + /// + /// docker + /// .upload_to_container_streaming("my-container", options, file) + /// .await + /// .expect("upload failed"); + /// # } + /// ``` pub async fn upload_to_container_streaming( &self, container_name: &str, @@ -2179,13 +2208,13 @@ impl Docker { /// /// ```rust,no_run /// # use bollard::Docker; - /// # let docker = Docker::connect_with_http_defaults().unwrap(); /// use bollard::container::UploadToContainerOptions; - /// - /// use std::default::Default; /// use std::fs::File; /// use std::io::Read; /// + /// # #[tokio::main] + /// # async fn main() { + /// # let docker = Docker::connect_with_http_defaults().unwrap(); /// let options = Some(UploadToContainerOptions{ /// path: "/opt", /// ..Default::default() @@ -2195,7 +2224,11 @@ impl Docker { /// let mut contents = Vec::new(); /// file.read_to_end(&mut contents).unwrap(); /// - /// docker.upload_to_container("my-container", options, contents.into()); + /// docker + /// .upload_to_container("my-container", options, contents.into()) + /// .await + /// .expect("upload failed"); + /// # } /// ``` pub async fn upload_to_container( &self,