Cargo fmt and cargo clippy fixes.

This commit is contained in:
Avi Weinstock 2022-03-25 12:32:41 -04:00
parent 993cbcdc5c
commit 45a98c01b9
2 changed files with 50 additions and 47 deletions

View file

@ -640,7 +640,7 @@ pub(crate) fn central_header_to_zip_file<R: Read + io::Seek>(
archive_offset: u64, archive_offset: u64,
) -> ZipResult<ZipFileData> { ) -> ZipResult<ZipFileData> {
let central_header_start = reader.seek(io::SeekFrom::Current(0))?; 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() { let file_name = match central_header.flags.is_utf8() {
true => String::from_utf8_lossy(&*central_header.file_name_raw).into_owned(), true => String::from_utf8_lossy(&*central_header.file_name_raw).into_owned(),
@ -662,14 +662,17 @@ pub(crate) fn central_header_to_zip_file<R: Read + io::Seek>(
CompressionMethod::from_u16(central_header.compression_method) CompressionMethod::from_u16(central_header.compression_method)
}, },
compression_level: None, 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, crc32: central_header.crc32,
compressed_size: central_header.compressed_size as u64, compressed_size: central_header.compressed_size as u64,
uncompressed_size: central_header.uncompressed_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, file_name_raw: central_header.file_name_raw,
extra_field: central_header.extra_field, extra_field: central_header.extra_field,
file_comment: file_comment, file_comment,
header_start: central_header.offset as u64, header_start: central_header.offset as u64,
central_header_start, central_header_start,
data_start: AtomicU64::new(0), data_start: AtomicU64::new(0),

View file

@ -1008,28 +1008,28 @@ fn write_local_file_header<T: Write>(writer: &mut T, file: &ZipFileData) -> ZipR
let compressed_size = file.compressed_size.min(spec::ZIP64_BYTES_THR) as u32; 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 uncompressed_size = file.uncompressed_size.min(spec::ZIP64_BYTES_THR) as u32;
let mut extra_field = if file.large_file { let mut extra_field = if file.large_file {
let mut zip64_extra_field = vec![0; 20]; let mut zip64_extra_field = vec![0; 20];
write_local_zip64_extra_field(&mut zip64_extra_field, file)?; write_local_zip64_extra_field(&mut zip64_extra_field, file)?;
zip64_extra_field zip64_extra_field
} else { } else {
Vec::new() Vec::new()
}; };
extra_field.extend_from_slice(&file.extra_field[..]); extra_field.extend_from_slice(&file.extra_field[..]);
let local_file_header = spec::LocalFileHeader { let local_file_header = spec::LocalFileHeader {
version_to_extract: file.version_needed(), version_to_extract: file.version_needed(),
flags: spec::GeneralPurposeBitFlags(flags), flags: spec::GeneralPurposeBitFlags(flags),
compression_method, compression_method,
last_mod_time: file.last_modified_time.timepart(), last_mod_time: file.last_modified_time.timepart(),
last_mod_date: file.last_modified_time.datepart(), last_mod_date: file.last_modified_time.datepart(),
crc32: file.crc32, crc32: file.crc32,
compressed_size, compressed_size,
uncompressed_size, uncompressed_size,
file_name_raw: file.file_name.as_bytes().to_vec(), file_name_raw: file.file_name.as_bytes().to_vec(),
extra_field, extra_field,
}; };
local_file_header.write(writer)?; local_file_header.write(writer)?;
Ok(()) Ok(())
} }
@ -1075,29 +1075,29 @@ fn write_central_directory_header<T: Write>(writer: &mut T, file: &ZipFileData)
let uncompressed_size = file.uncompressed_size.min(spec::ZIP64_BYTES_THR) as u32; 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 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(); let mut extra_field = zip64_extra_field[..zip64_extra_field_length as usize].to_vec();
extra_field.extend_from_slice(&file.extra_field[..]); extra_field.extend_from_slice(&file.extra_field[..]);
let header = spec::CentralDirectoryHeader { let header = spec::CentralDirectoryHeader {
version_made_by: (file.system as u16) << 8 | (file.version_made_by as u16), version_made_by: (file.system as u16) << 8 | (file.version_made_by as u16),
version_to_extract: file.version_needed(), version_to_extract: file.version_needed(),
flags: spec::GeneralPurposeBitFlags(flags), flags: spec::GeneralPurposeBitFlags(flags),
compression_method, compression_method,
last_mod_time: file.last_modified_time.timepart(), last_mod_time: file.last_modified_time.timepart(),
last_mod_date: file.last_modified_time.datepart(), last_mod_date: file.last_modified_time.datepart(),
crc32: file.crc32, crc32: file.crc32,
compressed_size, compressed_size,
uncompressed_size, uncompressed_size,
disk_number: 0, disk_number: 0,
internal_file_attributes: 0, internal_file_attributes: 0,
external_file_attributes: file.external_attributes, external_file_attributes: file.external_attributes,
offset, offset,
file_name_raw: file.file_name.as_bytes().to_vec(), file_name_raw: file.file_name.as_bytes().to_vec(),
extra_field, extra_field,
file_comment_raw: Vec::new(), file_comment_raw: Vec::new(),
}; };
header.write(writer) header.write(writer)
} }
fn validate_extra_data(file: &ZipFileData) -> ZipResult<()> { fn validate_extra_data(file: &ZipFileData) -> ZipResult<()> {