From ab9667aa5c4c079dc97b53fcae0d386d554c9c23 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Tue, 22 May 2018 23:30:31 +0200 Subject: [PATCH] Properly write 'version needed' in local file header 'version made by' was used instead of version needed by accident. Resolves #72 --- src/types.rs | 8 ++++++++ src/write.rs | 5 ++--- tests/data/mimetype.zip | Bin 159 -> 159 bytes 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/types.rs b/src/types.rs index 86f5dcdd..8f23b014 100644 --- a/src/types.rs +++ b/src/types.rs @@ -79,6 +79,14 @@ impl ZipFileData { path }) } + + pub fn version_needed(&self) -> u16 { + match self.compression_method { + #[cfg(feature = "bzip2")] + ::compression::CompressionMethod::Bzip2 => 46, + _ => 20, + } + } } #[cfg(test)] diff --git a/src/write.rs b/src/write.rs index 74d1df18..da4cf298 100644 --- a/src/write.rs +++ b/src/write.rs @@ -424,8 +424,7 @@ fn write_local_file_header(writer: &mut T, file: &ZipFileData) -> ZipR // local file header signature try!(writer.write_u32::(spec::LOCAL_FILE_HEADER_SIGNATURE)); // version needed to extract - let version_made_by = (file.system as u16) << 8 | (file.version_made_by as u16); - try!(writer.write_u16::(version_made_by)); + try!(writer.write_u16::(file.version_needed())); // general purpose bit flag let flag = if !file.file_name.is_ascii() { 1u16 << 11 } else { 0 }; try!(writer.write_u16::(flag)); @@ -472,7 +471,7 @@ fn write_central_directory_header(writer: &mut T, file: &ZipFileData) let version_made_by = (file.system as u16) << 8 | (file.version_made_by as u16); try!(writer.write_u16::(version_made_by)); // version needed to extract - try!(writer.write_u16::(20)); + try!(writer.write_u16::(file.version_needed())); // general puprose bit flag let flag = if !file.file_name.is_ascii() { 1u16 << 11 } else { 0 }; try!(writer.write_u16::(flag)); diff --git a/tests/data/mimetype.zip b/tests/data/mimetype.zip index d303463d84290caea2eebbb36d709a9739640e99..29f97298d7ae23aa7a876ca3a9f74175013e2e2b 100644 GIT binary patch delta 14 VcmbQwIG>R%z?+#xgkd7vOaK^}11$gm delta 14 VcmbQwIG>R%z?+#xgn1&{OaK_A126yp