Skip to content

Commit

Permalink
bzip2 multistream support (#62)
Browse files Browse the repository at this point in the history
* Add failing test for multistreams bz2

* Use bzip2 MultiBzDecoder to deal with concatenated bzip2 files

* Add changelog entry
  • Loading branch information
luizirber authored Jan 26, 2023
1 parent a29c1ef commit ff7dae4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added


### Changed

- Support for multistream bzip2 files by default (#62)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion src/basic/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ cfg_if! {
inp: Box<dyn io::Read + 'a>,
) -> Result<(Box<dyn io::Read + 'a>, Format), Error> {
Ok((
Box::new(bzip2::read::BzDecoder::new(inp)),
Box::new(bzip2::read::MultiBzDecoder::new(inp)),
Format::Bzip,
))
}
Expand Down
40 changes: 40 additions & 0 deletions src/basic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,46 @@ mod test {
assert_eq!(LOREM_IPSUM, buffer.as_slice());
}

#[cfg(feature = "bz2")]
#[test]
fn bzip_multidecoder() {
let mut buf: Vec<u8> = vec![];

{
let mut writer =
get_writer(Box::new(&mut buf), compression::Format::Bzip, Level::Six).unwrap();
writer
.write_all(LOREM_IPSUM)
.expect("Error during write of data");
}

let ofile = NamedTempFile::new().expect("Can't create tmpfile");
{
use std::io::Write;
let mut wfile = ofile.reopen().expect("Can't create tmpfile");
wfile
.write_all(buf.as_slice())
.expect("Error during write of data");
wfile
.write_all(buf.as_slice())
.expect("Error during write of data");
}

let rfile = ofile.reopen().expect("Can't create tmpfile");
let (mut reader, compression) =
get_reader(Box::new(rfile)).expect("Error reading from tmpfile");

assert_eq!(compression, compression::Format::Bzip);

let mut buffer = Vec::new();
reader
.read_to_end(&mut buffer)
.expect("Error during reading");
let mut result: Vec<u8> = LOREM_IPSUM.into();
result.extend(LOREM_IPSUM);
assert_eq!(result, buffer.as_slice());
}

#[test]
#[cfg(not(feature = "lzma"))]
fn no_lzma_feature() {
Expand Down

0 comments on commit ff7dae4

Please sign in to comment.