Skip to content

Commit

Permalink
Merge pull request #26 from ibaryshnikov/master
Browse files Browse the repository at this point in the history
don't check for EOF when unpacked size is specified
  • Loading branch information
gendx committed Mar 5, 2020
2 parents 94553d6 + 41bb720 commit 2a1767a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/decode/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ where
rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
) -> error::Result<()> {
loop {
if self.unpacked_size.is_some() && rangecoder.is_finished_ok()? {
if let Some(unpacked_size) = self.unpacked_size {
if self.output.len() as u64 >= unpacked_size {
break;
}
} else if rangecoder.is_finished_ok()? {
break;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ fn round_trip_file(filename: &str) {
.read_to_end(&mut x)
.unwrap();
round_trip(x.as_slice());

// Do another round trip, but this time also write it to the header
let encode_options = lzma_rs::compress::Options {
unpacked_size: lzma_rs::compress::UnpackedSize::WriteToHeader(Some(x.len() as u64)),
};
let decode_options = lzma_rs::decompress::Options {
unpacked_size: lzma_rs::decompress::UnpackedSize::ReadFromHeader,
};
round_trip_with_options(x.as_slice(), &encode_options, &decode_options);
}

fn decomp_big_file(compfile: &str, plainfile: &str) {
Expand Down

0 comments on commit 2a1767a

Please sign in to comment.