From c6dd2ad26bed4876500e0a8780e79b2edbfea9d3 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Wed, 17 Sep 2014 15:11:56 +0200 Subject: [PATCH] Update the local header instead of overwriting --- src/writer.rs | 3 +-- src/writer_spec.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/writer.rs b/src/writer.rs index 2b5f4d0b..8de35b4a 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -152,8 +152,7 @@ impl ZipWriter file.uncompressed_size = self.stats.bytes_written; file.compressed_size = try!(writer.tell()) - self.stats.start; - try!(writer.seek(file.header_start as i64, io::SeekSet)); - try!(writer_spec::write_local_file_header(writer, file)); + try!(writer_spec::update_local_file_header(writer, file)); try!(writer.seek(0, io::SeekEnd)); Ok(()) } diff --git a/src/writer_spec.rs b/src/writer_spec.rs index 2dd8c82f..54bf2e2a 100644 --- a/src/writer_spec.rs +++ b/src/writer_spec.rs @@ -25,6 +25,16 @@ pub fn write_local_file_header(writer: &mut T, file: &ZipFile) -> IoR Ok(()) } +pub fn update_local_file_header(writer: &mut T, file: &ZipFile) -> IoResult<()> +{ + static CRC32_OFFSET : i64 = 14; + try!(writer.seek(file.header_start as i64 + CRC32_OFFSET, io::SeekSet)); + try!(writer.write_le_u32(file.crc32)); + try!(writer.write_le_u32(file.compressed_size as u32)); + try!(writer.write_le_u32(file.uncompressed_size as u32)); + Ok(()) +} + pub fn write_central_directory_header(writer: &mut T, file: &ZipFile) -> IoResult<()> { try!(writer.write_le_u32(spec::CENTRAL_DIRECTORY_HEADER_SIGNATURE));