Skip to content

Commit

Permalink
test: verify that we can read a file with a data descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0methean committed Apr 23, 2024
1 parent ffa7772 commit 46ff80d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ pub fn read_zipfile_from_stream<'a, R: Read>(reader: &'a mut R) -> ZipResult<Opt
#[cfg(test)]
mod test {
use crate::ZipArchive;
use std::io::Cursor;
use std::io::{Cursor, Read};

#[test]
fn invalid_offset() {
Expand Down Expand Up @@ -1447,4 +1447,14 @@ mod test {
v.extend_from_slice(include_bytes!("../tests/data/deflate64_issue_25.zip"));
ZipArchive::new(Cursor::new(v)).expect_err("Invalid file");
}

#[test]
fn test_read_with_data_descriptor() {
let mut v = Vec::new();
v.extend_from_slice(include_bytes!("../tests/data/data_descriptor.zip"));
let mut reader = ZipArchive::new(Cursor::new(v)).unwrap();
let mut decompressed = [0u8; 16];
let mut file = reader.by_index(0).unwrap();
assert_eq!(file.read(&mut decompressed).unwrap(), 12);
}
}
Binary file added tests/data/data_descriptor.zip
Binary file not shown.

0 comments on commit 46ff80d

Please sign in to comment.