From 7d85d8fb66080e4002c15fde26696243c9965461 Mon Sep 17 00:00:00 2001 From: Mihai STAN Date: Mon, 6 Mar 2017 06:22:42 +0200 Subject: [PATCH] Fix writing to buffers. Using SeekFrom::End(0) in finish_file for a buffer was movind the position the the end of the buffer, not the last written byte. --- src/write.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/write.rs b/src/write.rs index a609afaf..173eff97 100644 --- a/src/write.rs +++ b/src/write.rs @@ -53,7 +53,7 @@ enum GenericZipWriter /// Ok(()) /// } /// -/// println!("Result: {:?}", doit()); +/// println!("Result: {:?}", doit().unwrap()); /// ``` pub struct ZipWriter { @@ -226,10 +226,12 @@ impl ZipWriter }; file.crc32 = self.stats.crc32; file.uncompressed_size = self.stats.bytes_written; - file.compressed_size = try!(writer.seek(io::SeekFrom::Current(0))) - self.stats.start; + + let file_end = try!(writer.seek(io::SeekFrom::Current(0))); + file.compressed_size = file_end - self.stats.start; try!(update_local_file_header(writer, file)); - try!(writer.seek(io::SeekFrom::End(0))); + try!(writer.seek(io::SeekFrom::Start(file_end))); Ok(()) }