From 82315c95111affc4917f43fa97053de6776fa2eb Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Sat, 29 Oct 2016 12:30:59 +0200 Subject: [PATCH] Add comments to write.rs Clarify which field means what when writing structures --- src/write.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/write.rs b/src/write.rs index b6d419c4..97b1f88c 100644 --- a/src/write.rs +++ b/src/write.rs @@ -321,22 +321,34 @@ impl GenericZipWriter fn write_local_file_header(writer: &mut T, file: &ZipFileData) -> ZipResult<()> { + // 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)); + // general purpose bit flag let flag = if !file.file_name.is_ascii() { 1u16 << 11 } else { 0 }; try!(writer.write_u16::(flag)); + // Compression method try!(writer.write_u16::(file.compression_method.to_u16())); + // last mod file time and last mod file date let msdos_datetime = try!(file.last_modified_time.to_msdos()); try!(writer.write_u16::(msdos_datetime.timepart)); try!(writer.write_u16::(msdos_datetime.datepart)); + // crc-32 try!(writer.write_u32::(file.crc32)); + // compressed size try!(writer.write_u32::(file.compressed_size as u32)); + // uncompressed size try!(writer.write_u32::(file.uncompressed_size as u32)); + // file name length try!(writer.write_u16::(file.file_name.as_bytes().len() as u16)); + // extra field length let extra_field = try!(build_extra_field(file)); try!(writer.write_u16::(extra_field.len() as u16)); + // file name try!(writer.write_all(file.file_name.as_bytes())); + // extra field try!(writer.write_all(&extra_field)); Ok(()) @@ -354,28 +366,48 @@ fn update_local_file_header(writer: &mut T, file: &ZipFileDat fn write_central_directory_header(writer: &mut T, file: &ZipFileData) -> ZipResult<()> { + // central file header signature try!(writer.write_u32::(spec::CENTRAL_DIRECTORY_HEADER_SIGNATURE)); + // version made by try!(writer.write_u16::(0x14FF)); + // version needed to extract try!(writer.write_u16::(20)); + // general puprose bit flag let flag = if !file.file_name.is_ascii() { 1u16 << 11 } else { 0 }; try!(writer.write_u16::(flag)); + // compression method try!(writer.write_u16::(file.compression_method.to_u16())); + // last mod file time + date let msdos_datetime = try!(file.last_modified_time.to_msdos()); try!(writer.write_u16::(msdos_datetime.timepart)); try!(writer.write_u16::(msdos_datetime.datepart)); + // crc-32 try!(writer.write_u32::(file.crc32)); + // compressed size try!(writer.write_u32::(file.compressed_size as u32)); + // uncompressed size try!(writer.write_u32::(file.uncompressed_size as u32)); + // file name length try!(writer.write_u16::(file.file_name.as_bytes().len() as u16)); + // extra field length let extra_field = try!(build_extra_field(file)); try!(writer.write_u16::(extra_field.len() as u16)); + // file comment length try!(writer.write_u16::(0)); + // disk number start try!(writer.write_u16::(0)); + // internal file attribytes try!(writer.write_u16::(0)); + // external file attributes try!(writer.write_u32::(0)); + // relative offset of local header try!(writer.write_u32::(file.header_start as u32)); + // file name try!(writer.write_all(file.file_name.as_bytes())); + // extra field try!(writer.write_all(&extra_field)); + // file comment + // Ok(()) }