Update the local header instead of overwriting

This commit is contained in:
Mathijs van de Nes 2014-09-17 15:11:56 +02:00
parent 91cbe91d62
commit c6dd2ad26b
2 changed files with 11 additions and 2 deletions

View file

@ -152,8 +152,7 @@ impl<W: Writer+Seek> ZipWriter<W>
file.uncompressed_size = self.stats.bytes_written; file.uncompressed_size = self.stats.bytes_written;
file.compressed_size = try!(writer.tell()) - self.stats.start; file.compressed_size = try!(writer.tell()) - self.stats.start;
try!(writer.seek(file.header_start as i64, io::SeekSet)); try!(writer_spec::update_local_file_header(writer, file));
try!(writer_spec::write_local_file_header(writer, file));
try!(writer.seek(0, io::SeekEnd)); try!(writer.seek(0, io::SeekEnd));
Ok(()) Ok(())
} }

View file

@ -25,6 +25,16 @@ pub fn write_local_file_header<T: Writer>(writer: &mut T, file: &ZipFile) -> IoR
Ok(()) Ok(())
} }
pub fn update_local_file_header<T: Writer+Seek>(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<T: Writer>(writer: &mut T, file: &ZipFile) -> IoResult<()> pub fn write_central_directory_header<T: Writer>(writer: &mut T, file: &ZipFile) -> IoResult<()>
{ {
try!(writer.write_le_u32(spec::CENTRAL_DIRECTORY_HEADER_SIGNATURE)); try!(writer.write_le_u32(spec::CENTRAL_DIRECTORY_HEADER_SIGNATURE));