Expand description
Fast parallel bzip2 compression and decompression.
In memory:
let data = b"hello hello hello hello";
let packed = pbz2::compress(data, pbz2::Level::BEST);
assert_eq!(pbz2::decompress(&packed)?, data);Streaming, with any std::io::Write and std::io::Read, such as files or
sockets:
use std::io::{self, Cursor};
let original = b"one block of text, two blocks of text".repeat(1000);
let mut encoder = pbz2::ParallelEncoder::new(Vec::new(), pbz2::Level::BEST);
io::copy(&mut original.as_slice(), &mut encoder)?;
let packed = encoder.finish()?;
let mut decoder = pbz2::ParallelDecoder::new(Cursor::new(packed));
let mut unpacked = Vec::new();
io::copy(&mut decoder, &mut unpacked)?;
assert_eq!(unpacked, original);ParallelDecoder and ParallelEncoder use every core, and decode data while it
is still arriving. DecoderReader and EncoderWriter use the calling thread only.
With the simd feature, which is on by default, all of them use the SIMD instructions
the build targets; see pbz2_core::Native. On x86-64 builds that do not target
SSE4.2, each one checks the CPU once when it is created and uses SSE4.2 if it is there.
Output is a standard bzip2 stream that any bzip2 tool reads, and any bzip2 stream, including several in a row, decodes.
Everything here is built on pbz2_core, which does not allocate, does no I/O, and
runs without std, for embedded targets or your own threads.
Re-exports§
pub use pbz2_core;
Structs§
- Decoder
Reader - Decompresses bzip2 data from a reader on the calling thread.
- Encoder
Writer - Compresses data written to it on the calling thread into another writer. Dropping it ends the stream but ignores errors.
- Level
- A bzip2 block size, 1 to 9 hundred thousand bytes, which is also the compression
level: larger blocks compress better. A
Levelis always 1 to 9. - Parallel
Decoder - Decompresses bzip2 data from a reader on every core, decoding blocks as they arrive.
- Parallel
Encoder - Compresses data written to it on every core into another writer. Dropping it ends the stream but ignores errors.
Enums§
- Error
- Why data could not be compressed or decompressed.
Functions§
- compress
- Compresses all of
dataatlevelon every core. - decompress
- Decompresses all of
dataon every core.