Skip to content

Commit

Permalink
Doctest for upload_to_container_streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-hansen committed Aug 12, 2024
1 parent 5fe26b7 commit 0d8d171
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
41 changes: 37 additions & 4 deletions src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
&self,
container_name: &str,
Expand Down Expand Up @@ -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()
Expand All @@ -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<T>(
&self,
Expand Down

0 comments on commit 0d8d171

Please sign in to comment.