diff options
Diffstat (limited to 'examples/containercopyfrom.rs')
-rw-r--r-- | examples/containercopyfrom.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/examples/containercopyfrom.rs b/examples/containercopyfrom.rs index 2ebeccf..acbfa19 100644 --- a/examples/containercopyfrom.rs +++ b/examples/containercopyfrom.rs @@ -1,8 +1,10 @@ +use futures::TryStreamExt; use shiplift::Docker; use std::{env, path}; -use tokio::prelude::{Future, Stream}; +use tar::Archive; -fn main() { +#[tokio::main] +async fn main() -> Result<(), Box<dyn std::error::Error>> { let docker = Docker::new(); let id = env::args() .nth(1) @@ -10,17 +12,16 @@ fn main() { let path = env::args() .nth(2) .expect("Usage: cargo run --example containercopyfrom -- <container> <path in container>"); - let fut = docker + + let bytes = docker .containers() .get(&id) .copy_from(path::Path::new(&path)) - .collect() - .and_then(|stream| { - let tar = stream.concat(); - let mut archive = tar::Archive::new(tar.as_slice()); - archive.unpack(env::current_dir()?)?; - Ok(()) - }) - .map_err(|e| eprintln!("Error: {}", e)); - tokio::run(fut); + .try_concat() + .await?; + + let mut archive = Archive::new(&bytes[..]); + archive.unpack(env::current_dir()?)?; + + Ok(()) } |