From f803fa01971bd442fa007b7d5fe00c5e442f6c0b Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:23:32 -0700 Subject: [PATCH] test: (#33) Verify that data_start is correct when reading an alignment-padded file (#228) * test: Add test that `data_start` is correctly detected while reading * chore: Fix imports --- src/write.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/write.rs b/src/write.rs index 913219c3..48276cb9 100644 --- a/src/write.rs +++ b/src/write.rs @@ -2434,6 +2434,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(Stored) + .with_alignment(page_size); + let mut zip = ZipWriter::new(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(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()));