summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsoftprops <d.tangren@gmail.com>2016-01-18 12:52:58 -0500
committersoftprops <d.tangren@gmail.com>2016-01-18 12:52:58 -0500
commit2139459d574a2704cb0756679c6e41b5232bd247 (patch)
tree9b063d88bbc3059ccae899e28addb69b83d2a36c
parentb92ac2eec7ce46b65f97fd664e42582b4cb1a6c2 (diff)
write to in memory buffer, not disk
-rw-r--r--src/lib.rs8
-rw-r--r--src/tarball.rs15
2 files changed, 13 insertions, 10 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1fa6f1e..d5a9a39 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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(())
}