diff --git a/src/write.rs b/src/write.rs index 8f407d25..f96d24b1 100644 --- a/src/write.rs +++ b/src/write.rs @@ -74,10 +74,16 @@ impl Write for ZipWriter fn write(&mut self, buf: &[u8]) -> io::Result { if self.files.len() == 0 { return Err(io::Error::new(io::ErrorKind::Other, "No file has been started")) } - self.stats.update(buf); match self.inner.ref_mut() { - Some(ref mut w) => w.write(buf), + Some(ref mut w) => { + let write_result = w.write(buf); + if let Ok(count) = write_result { + self.stats.update(&buf[0..count]); + } + write_result + + } None => Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed")), } }