Skip to content

Commit

Permalink
Fixed entry's compressed_size
Browse files Browse the repository at this point in the history
  • Loading branch information
dyz1990 committed Dec 14, 2023
1 parent e5e06f7 commit 8535b39
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,16 @@ impl Archive {
if !archive.files[i].has_stream {
continue;
}

//set `compressed_size` of first file in block
if stream_map.folder_first_file_index[next_folder_index] == i {
let first_pack_stream_index =
stream_map.folder_first_pack_stream_index[next_folder_index];
let pack_size = archive.pack_sizes[first_pack_stream_index];

archive.files[i].compressed_size = pack_size;
}

next_folder_unpack_stream_index += 1;
if next_folder_unpack_stream_index
>= archive.folders[next_folder_index].num_unpack_sub_streams
Expand Down
27 changes: 27 additions & 0 deletions tests/decompression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,30 @@ fn test_bcj2() {
.unwrap();
}
}

#[test]
fn test_entry_compressed_size() {
let dir = std::fs::read_dir("tests/resources").unwrap();
for entry in dir {
let path = entry.unwrap().path();
if path.to_string_lossy().ends_with("7z") {
println!("{:?}", path);
let mut file = File::open(path).unwrap();
let file_len = file.metadata().unwrap().len();
let archive = Archive::read(&mut file, file_len, &[]).unwrap();
for i in 0..archive.folders.len() {
let fi = archive.stream_map.folder_first_file_index[i];
let file = &archive.files[fi];
println!(
"\t:{}\tsize={}, \tcompressed={}",
file.name(),
file.size,
file.compressed_size
);
if file.has_stream && file.size > 0 {
assert!(file.compressed_size > 0);
}
}
}
}
}

0 comments on commit 8535b39

Please sign in to comment.