From 45a98c01b99c8161bf0096dc1b4c6fb7ee250f36 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Fri, 25 Mar 2022 12:32:41 -0400 Subject: [PATCH] Cargo fmt and cargo clippy fixes. --- src/read.rs | 11 ++++--- src/write.rs | 86 ++++++++++++++++++++++++++-------------------------- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/read.rs b/src/read.rs index ae235c9a..d76a780f 100644 --- a/src/read.rs +++ b/src/read.rs @@ -640,7 +640,7 @@ pub(crate) fn central_header_to_zip_file( archive_offset: u64, ) -> ZipResult { let central_header_start = reader.seek(io::SeekFrom::Current(0))?; - let central_header = spec::CentralDirectoryHeader::parse(reader)?; + let central_header = spec::CentralDirectoryHeader::parse(reader)?; let file_name = match central_header.flags.is_utf8() { true => String::from_utf8_lossy(&*central_header.file_name_raw).into_owned(), @@ -662,14 +662,17 @@ pub(crate) fn central_header_to_zip_file( CompressionMethod::from_u16(central_header.compression_method) }, compression_level: None, - last_modified_time: DateTime::from_msdos(central_header.last_mod_date, central_header.last_mod_time), + last_modified_time: DateTime::from_msdos( + central_header.last_mod_date, + central_header.last_mod_time, + ), crc32: central_header.crc32, compressed_size: central_header.compressed_size as u64, uncompressed_size: central_header.uncompressed_size as u64, - file_name: file_name, + file_name, file_name_raw: central_header.file_name_raw, extra_field: central_header.extra_field, - file_comment: file_comment, + file_comment, header_start: central_header.offset as u64, central_header_start, data_start: AtomicU64::new(0), diff --git a/src/write.rs b/src/write.rs index 214807a5..2e398b91 100644 --- a/src/write.rs +++ b/src/write.rs @@ -1008,28 +1008,28 @@ fn write_local_file_header(writer: &mut T, file: &ZipFileData) -> ZipR let compressed_size = file.compressed_size.min(spec::ZIP64_BYTES_THR) as u32; let uncompressed_size = file.uncompressed_size.min(spec::ZIP64_BYTES_THR) as u32; - let mut extra_field = if file.large_file { - let mut zip64_extra_field = vec![0; 20]; - write_local_zip64_extra_field(&mut zip64_extra_field, file)?; - zip64_extra_field - } else { - Vec::new() - }; - extra_field.extend_from_slice(&file.extra_field[..]); + let mut extra_field = if file.large_file { + let mut zip64_extra_field = vec![0; 20]; + write_local_zip64_extra_field(&mut zip64_extra_field, file)?; + zip64_extra_field + } else { + Vec::new() + }; + extra_field.extend_from_slice(&file.extra_field[..]); - let local_file_header = spec::LocalFileHeader { - version_to_extract: file.version_needed(), - flags: spec::GeneralPurposeBitFlags(flags), - compression_method, - last_mod_time: file.last_modified_time.timepart(), - last_mod_date: file.last_modified_time.datepart(), - crc32: file.crc32, - compressed_size, - uncompressed_size, - file_name_raw: file.file_name.as_bytes().to_vec(), - extra_field, - }; - local_file_header.write(writer)?; + let local_file_header = spec::LocalFileHeader { + version_to_extract: file.version_needed(), + flags: spec::GeneralPurposeBitFlags(flags), + compression_method, + last_mod_time: file.last_modified_time.timepart(), + last_mod_date: file.last_modified_time.datepart(), + crc32: file.crc32, + compressed_size, + uncompressed_size, + file_name_raw: file.file_name.as_bytes().to_vec(), + extra_field, + }; + local_file_header.write(writer)?; Ok(()) } @@ -1075,29 +1075,29 @@ fn write_central_directory_header(writer: &mut T, file: &ZipFileData) let uncompressed_size = file.uncompressed_size.min(spec::ZIP64_BYTES_THR) as u32; let offset = file.header_start.min(spec::ZIP64_BYTES_THR) as u32; - let mut extra_field = zip64_extra_field[..zip64_extra_field_length as usize].to_vec(); - extra_field.extend_from_slice(&file.extra_field[..]); - - let header = spec::CentralDirectoryHeader { - version_made_by: (file.system as u16) << 8 | (file.version_made_by as u16), - version_to_extract: file.version_needed(), - flags: spec::GeneralPurposeBitFlags(flags), - compression_method, - last_mod_time: file.last_modified_time.timepart(), - last_mod_date: file.last_modified_time.datepart(), - crc32: file.crc32, - compressed_size, - uncompressed_size, - disk_number: 0, - internal_file_attributes: 0, - external_file_attributes: file.external_attributes, - offset, - file_name_raw: file.file_name.as_bytes().to_vec(), - extra_field, - file_comment_raw: Vec::new(), - }; + let mut extra_field = zip64_extra_field[..zip64_extra_field_length as usize].to_vec(); + extra_field.extend_from_slice(&file.extra_field[..]); - header.write(writer) + let header = spec::CentralDirectoryHeader { + version_made_by: (file.system as u16) << 8 | (file.version_made_by as u16), + version_to_extract: file.version_needed(), + flags: spec::GeneralPurposeBitFlags(flags), + compression_method, + last_mod_time: file.last_modified_time.timepart(), + last_mod_date: file.last_modified_time.datepart(), + crc32: file.crc32, + compressed_size, + uncompressed_size, + disk_number: 0, + internal_file_attributes: 0, + external_file_attributes: file.external_attributes, + offset, + file_name_raw: file.file_name.as_bytes().to_vec(), + extra_field, + file_comment_raw: Vec::new(), + }; + + header.write(writer) } fn validate_extra_data(file: &ZipFileData) -> ZipResult<()> {