diff options
author | softprops <d.tangren@gmail.com> | 2016-01-18 12:52:58 -0500 |
---|---|---|
committer | softprops <d.tangren@gmail.com> | 2016-01-18 12:52:58 -0500 |
commit | 2139459d574a2704cb0756679c6e41b5232bd247 (patch) | |
tree | 9b063d88bbc3059ccae899e28addb69b83d2a36c | |
parent | b92ac2eec7ce46b65f97fd664e42582b4cb1a6c2 (diff) |
write to in memory buffer, not disk
-rw-r--r-- | src/lib.rs | 8 | ||||
-rw-r--r-- | src/tarball.rs | 15 |
2 files changed, 13 insertions, 10 deletions
@@ -143,8 +143,11 @@ impl<'a> Images<'a> { path.push(query) } - let mut f = try!(tarball::dir(&opts.path[..])); - let raw = try!(self.docker.stream_post(&path.join("?"), Some((Body::ChunkedBody(&mut f), tar())))); + let mut bytes = vec![]; + + try!(tarball::dir(&mut bytes, &opts.path[..])); + + let raw = try!(self.docker.stream_post(&path.join("?"), Some((Body::BufBody(&bytes[..], bytes.len()), tar())))); let it = jed::Iter::new(raw).into_iter().map(|j| { // fixme: better error handling debug!("{:?}", j); @@ -190,6 +193,7 @@ impl<'a> Images<'a> { Ok(try!(json::decode::<Vec<SearchResult>>(&raw))) } + // todo: should this be named `pull` to avoid confusion with build? /// Create a new docker images from an existing image pub fn create(&self, from: &str) -> Result<Box<Iterator<Item = PullOutput>>> { let query = form_urlencoded::serialize(vec![("fromImage", from)]); diff --git a/src/tarball.rs b/src/tarball.rs index f13c49f..3ad1c9e 100644 --- a/src/tarball.rs +++ b/src/tarball.rs @@ -1,16 +1,14 @@ use flate2::Compression; use flate2::write::GzEncoder; -use std::fs::{self, File, OpenOptions}; +use std::fs::{self, File}; use std::path::{Path, MAIN_SEPARATOR}; -use std::io; +use std::io::{self, Write, Read}; use tar::Archive; -// todo: factor this into its own crate -pub fn dir(path: &str) -> io::Result<File> { - let file = OpenOptions::new().read(true).write(true).create(true).open("build.tgz").unwrap(); - let zipper = GzEncoder::new(file, Compression::Best); - let archive = Archive::new(zipper); +// todo: this is pretty involved. factor this into its own crate +pub fn dir<W>(buf: W, path: &str) -> io::Result<()> where W: Write { + let archive = Archive::new(GzEncoder::new(buf, Compression::Best)); fn bundle(dir: &Path, cb: &Fn(&Path), bundle_dir: bool) -> io::Result<()> { if try!(fs::metadata(dir)).is_dir() { if bundle_dir { @@ -47,5 +45,6 @@ pub fn dir(path: &str) -> io::Result<File> { try!(bundle(Path::new(path), &append, false)); try!(archive.finish()); } - File::open("build.tgz") + + Ok(()) } |