style: cargo fmt --all
This commit is contained in:
parent
db4a967eba
commit
9568e713bd
2 changed files with 92 additions and 13 deletions
|
@ -1124,11 +1124,14 @@ pub(crate) fn central_header_to_zip_file<R: Read + Seek>(
|
|||
|
||||
// Parse central header
|
||||
let block = ZipCentralEntryBlock::parse(reader)?;
|
||||
let file = central_header_to_zip_file_inner(reader, archive_offset, central_header_start, block)?;
|
||||
let file =
|
||||
central_header_to_zip_file_inner(reader, archive_offset, central_header_start, block)?;
|
||||
let central_header_end = reader.stream_position()?;
|
||||
let data_start = find_data_start(&file, reader)?;
|
||||
if data_start > central_header_start {
|
||||
return Err(InvalidArchive("A file can't start after its central-directory header"));
|
||||
return Err(InvalidArchive(
|
||||
"A file can't start after its central-directory header",
|
||||
));
|
||||
}
|
||||
file.data_start.get_or_init(|| data_start);
|
||||
reader.seek(SeekFrom::Start(central_header_end))?;
|
||||
|
|
98
src/write.rs
98
src/write.rs
|
@ -3113,15 +3113,55 @@ mod test {
|
|||
let sub_writer = {
|
||||
let mut writer = ZipWriter::new(Cursor::new(Vec::new()));
|
||||
writer.set_flush_on_finish_file(false);
|
||||
let options = FileOptions { compression_method: Stored, compression_level: None, last_modified_time: DateTime::from_date_and_time(1981, 1, 1, 0, 24, 21)?, permissions: Some(16908288), large_file: false, encrypt_with: None, extended_options: ExtendedFileOptions {extra_data: vec![].into(), central_extra_data: vec![].into()}, alignment: 20555, ..Default::default() };
|
||||
writer.start_file_from_path("\0\u{7}\u{1}\0\0\0\0\0\0\0\0\u{1}\0\0PK\u{1}\u{2};", options)?;
|
||||
writer.write_all(&([255, 255, 255, 255, 253, 253, 253, 203, 203, 203, 253, 253, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 249, 191, 225, 225, 241, 197]))?;
|
||||
writer.write_all(&([197, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 75, 0]))?;
|
||||
let options = FileOptions {
|
||||
compression_method: Stored,
|
||||
compression_level: None,
|
||||
last_modified_time: DateTime::from_date_and_time(1981, 1, 1, 0, 24, 21)?,
|
||||
permissions: Some(16908288),
|
||||
large_file: false,
|
||||
encrypt_with: None,
|
||||
extended_options: ExtendedFileOptions {
|
||||
extra_data: vec![].into(),
|
||||
central_extra_data: vec![].into(),
|
||||
},
|
||||
alignment: 20555,
|
||||
..Default::default()
|
||||
};
|
||||
writer.start_file_from_path(
|
||||
"\0\u{7}\u{1}\0\0\0\0\0\0\0\0\u{1}\0\0PK\u{1}\u{2};",
|
||||
options,
|
||||
)?;
|
||||
writer.write_all(
|
||||
&([
|
||||
255, 255, 255, 255, 253, 253, 253, 203, 203, 203, 253, 253, 253, 253, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 249, 191, 225, 225,
|
||||
241, 197,
|
||||
]),
|
||||
)?;
|
||||
writer.write_all(
|
||||
&([
|
||||
197, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 75, 0,
|
||||
]),
|
||||
)?;
|
||||
writer
|
||||
};
|
||||
writer.merge_archive(sub_writer.finish_into_readable()?)?;
|
||||
writer = ZipWriter::new_append(writer.finish_into_readable()?.into_inner())?;
|
||||
let options = FileOptions { compression_method: Stored, compression_level: None, last_modified_time: DateTime::from_date_and_time(1980, 11, 14, 10, 46, 47)?, permissions: None, large_file: false, encrypt_with: None, extended_options: ExtendedFileOptions {extra_data: vec![].into(), central_extra_data: vec![].into()}, alignment: 0, ..Default::default() };
|
||||
let options = FileOptions {
|
||||
compression_method: Stored,
|
||||
compression_level: None,
|
||||
last_modified_time: DateTime::from_date_and_time(1980, 11, 14, 10, 46, 47)?,
|
||||
permissions: None,
|
||||
large_file: false,
|
||||
encrypt_with: None,
|
||||
extended_options: ExtendedFileOptions {
|
||||
extra_data: vec![].into(),
|
||||
central_extra_data: vec![].into(),
|
||||
},
|
||||
alignment: 0,
|
||||
..Default::default()
|
||||
};
|
||||
writer.start_file_from_path(PATH_1, options)?;
|
||||
writer.deep_copy_file_from_path(PATH_1, "eee\u{6}\0\0\0\0\0\0\0\0\0\0\0$\0\0\0\0\0\0\u{7f}\u{7f}PK\u{6}\u{6}K\u{6}\u{6}\u{6}\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u{1}\0\0\0\0\0\0\0\0\u{1}\0\0PK\u{1}\u{1e},\0\0\0\0\0\0\0\0\0\0\0\u{8}\0*\0\0\u{1}PK\u{6}\u{7}PK\u{6}\u{6}\0\0\0\0\0\0\0\0}K\u{2}\u{6}")?;
|
||||
writer
|
||||
|
@ -3166,26 +3206,62 @@ mod test {
|
|||
let sub_writer = {
|
||||
let mut writer = ZipWriter::new(Cursor::new(Vec::new()));
|
||||
writer.set_flush_on_finish_file(false);
|
||||
let options = FileOptions { compression_method: Stored, compression_level: None, last_modified_time: DateTime::from_date_and_time(1981, 1, 1, 0, 0, 21)?, permissions: Some(16908288), large_file: false, encrypt_with: None, extended_options: ExtendedFileOptions {extra_data: vec![].into(), central_extra_data: vec![].into()}, alignment: 20555, ..Default::default() };
|
||||
let options = FileOptions {
|
||||
compression_method: Stored,
|
||||
compression_level: None,
|
||||
last_modified_time: DateTime::from_date_and_time(
|
||||
1981, 1, 1, 0, 0, 21,
|
||||
)?,
|
||||
permissions: Some(16908288),
|
||||
large_file: false,
|
||||
encrypt_with: None,
|
||||
extended_options: ExtendedFileOptions {
|
||||
extra_data: vec![].into(),
|
||||
central_extra_data: vec![].into(),
|
||||
},
|
||||
alignment: 20555,
|
||||
..Default::default()
|
||||
};
|
||||
writer.start_file_from_path("\0\u{7}\u{1}\0\0\0\0\0\0\0\0\u{1}\0\0PK\u{1}\u{2};\u{1a}\u{18}\u{1a}UT\t.........................\0u", options)?;
|
||||
writer
|
||||
};
|
||||
writer.merge_archive(sub_writer.finish_into_readable()?)?;
|
||||
let options = FileOptions { compression_method: CompressionMethod::Bzip2, compression_level: Some(5), last_modified_time: DateTime::from_date_and_time(2055, 7, 7, 3, 6, 6)?, permissions: None, large_file: false, encrypt_with: None, extended_options: ExtendedFileOptions {extra_data: vec![].into(), central_extra_data: vec![].into()}, alignment: 0, ..Default::default() };
|
||||
let options = FileOptions {
|
||||
compression_method: CompressionMethod::Bzip2,
|
||||
compression_level: Some(5),
|
||||
last_modified_time: DateTime::from_date_and_time(
|
||||
2055, 7, 7, 3, 6, 6,
|
||||
)?,
|
||||
permissions: None,
|
||||
large_file: false,
|
||||
encrypt_with: None,
|
||||
extended_options: ExtendedFileOptions {
|
||||
extra_data: vec![].into(),
|
||||
central_extra_data: vec![].into(),
|
||||
},
|
||||
alignment: 0,
|
||||
..Default::default()
|
||||
};
|
||||
writer.start_file_from_path("\0\0\0\0..\0\0\0\0\0\u{7f}\u{7f}PK\u{6}\u{6}K\u{6}\u{6}\u{6}\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u{1}\0\0\0\0\0\0\0\0\u{1}\0\0PK\u{1}\u{1e},\0\0\0\0\0\0\0\0\0\0\0\u{8}\0*\0\0\u{1}PK\u{6}\u{7}PK\u{6}\u{6}\0\0\0\0\0\0\0\0}K\u{2}\u{6}", options)?;
|
||||
writer = ZipWriter::new_append(writer.finish_into_readable()?.into_inner())?;
|
||||
writer = ZipWriter::new_append(
|
||||
writer.finish_into_readable()?.into_inner(),
|
||||
)?;
|
||||
writer
|
||||
};
|
||||
writer.merge_archive(sub_writer.finish_into_readable()?)?;
|
||||
writer = ZipWriter::new_append(writer.finish_into_readable()?.into_inner())?;
|
||||
writer = ZipWriter::new_append(
|
||||
writer.finish_into_readable()?.into_inner(),
|
||||
)?;
|
||||
writer
|
||||
};
|
||||
writer.merge_archive(sub_writer.finish_into_readable()?)?;
|
||||
writer = ZipWriter::new_append(writer.finish_into_readable()?.into_inner())?;
|
||||
writer =
|
||||
ZipWriter::new_append(writer.finish_into_readable()?.into_inner())?;
|
||||
writer
|
||||
};
|
||||
writer.merge_archive(sub_writer.finish_into_readable()?)?;
|
||||
writer = ZipWriter::new_append(writer.finish_into_readable()?.into_inner())?;
|
||||
writer =
|
||||
ZipWriter::new_append(writer.finish_into_readable()?.into_inner())?;
|
||||
writer
|
||||
};
|
||||
writer.merge_archive(sub_writer.finish_into_readable()?)?;
|
||||
|
|
Loading…
Add table
Reference in a new issue