Properly write 'version needed' in local file header

'version made by' was used instead of version needed by accident.

Resolves #72
This commit is contained in:
Mathijs van de Nes 2018-05-22 23:30:31 +02:00
parent 806147ac9e
commit ab9667aa5c
3 changed files with 10 additions and 3 deletions

View file

@ -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)]

View file

@ -424,8 +424,7 @@ fn write_local_file_header<T: Write>(writer: &mut T, file: &ZipFileData) -> ZipR
// local file header signature
try!(writer.write_u32::<LittleEndian>(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::<LittleEndian>(version_made_by));
try!(writer.write_u16::<LittleEndian>(file.version_needed()));
// general purpose bit flag
let flag = if !file.file_name.is_ascii() { 1u16 << 11 } else { 0 };
try!(writer.write_u16::<LittleEndian>(flag));
@ -472,7 +471,7 @@ fn write_central_directory_header<T: Write>(writer: &mut T, file: &ZipFileData)
let version_made_by = (file.system as u16) << 8 | (file.version_made_by as u16);
try!(writer.write_u16::<LittleEndian>(version_made_by));
// version needed to extract
try!(writer.write_u16::<LittleEndian>(20));
try!(writer.write_u16::<LittleEndian>(file.version_needed()));
// general puprose bit flag
let flag = if !file.file_name.is_ascii() { 1u16 << 11 } else { 0 };
try!(writer.write_u16::<LittleEndian>(flag));

Binary file not shown.