Skip to content

Commit

Permalink
test: Add test that data_start is correctly detected while reading
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0methean committed Jul 24, 2024
1 parent 546e49d commit 369e2f5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,28 @@ mod test {
assert_eq!(file.data_start(), page_size.into());
}

#[test]
fn test_alignment_2() {
let page_size = 4096;
let mut data = Vec::new();
{
let options = SimpleFileOptions::default()
.compression_method(CompressionMethod::Stored)
.with_alignment(page_size);
let mut zip = ZipWriter::new(io::Cursor::new(&mut data));
let contents = b"sleeping";
let () = zip.start_file("sleep", options).unwrap();
let _count = zip.write(&contents[..]).unwrap();
}
assert_eq!(data[4096..4104], b"sleeping"[..]);
{
let mut zip = ZipArchive::new(io::Cursor::new(&mut data)).unwrap();
let file = zip.by_index(0).unwrap();
assert_eq!(file.name(), "sleep");
assert_eq!(file.data_start(), page_size.into());
}
}

#[test]
fn test_crash_short_read() {
let mut writer = ZipWriter::new(Cursor::new(Vec::new()));
Expand Down

0 comments on commit 369e2f5

Please sign in to comment.