This crate features an optimized inflate algorithm supporting whole buffer decompression.
Supported formats are
The implementation is heavily based on Eric Biggers [libdeflate] and hence has similar characteristics.
Specifically, we do not support streaming decompression but prefer whole buffer decompression.
To use in your crate, simply add the following in your Cargo.toml
```toml [dependencies]
zune-inflate = "0.2.0" ```
One can enable or disable a specific format using cargo features.
Specifically, the following can be enabled
gzip
: Enable decompressing of gzip encoded datazlib
: Enable decompressing of zlib encoded dataTo enable one feature, modify Cargo.toml
entry to be
toml
[dependencies]
zune-inflate = { version = "0.2", default-features = false, features = ["#ADD_SPECIFIC_FEATURE"] }
The library exposes a simple API for decompressing
data, and depending on what type of data you have, you typically choose
one of the decode[_suffix]
function to decode your data
The decompressor expects the whole buffer handed upfront
To decode raw deflate data, the following code should get you started.
rust
use zune_inflate::DeflateDecoder;
let totally_valid_data = [0; 23];
let mut decoder = DeflateDecoder::new( & totally_valid_data);
// panic on errors, because that's the cool way to go
let decompressed_data = decoder.decode_deflate().unwrap();
To decode deflate data wrapped in zlib, the following code should get you started.
rust
use zune_inflate::DeflateDecoder;
let totally_valid_data = [0; 23];
let mut decoder = DeflateDecoder::new( & totally_valid_data);
// panic on errors, because that's the cool way to go
let decompressed_data = decoder.decode_zlib().unwrap();
There are advanced options specified by DeflateOptions
which can change
decompression settings.
I'll compare this with flate2
with miniz-oxide
backend.
| feature | zune-inflate
| flate2
|
|-------------------------|----------------|----------|
| zlib decompression | yes | yes |
| delfate decompression | yes | yes |
| gzip | yes | yes |
| compression | soon | yes |
| streaming decompression | no | yes |
| unsafe | no | yes |
As you can see, there are a lot of features we currently lack when compared to flate2/miniz-oxide.
There's actually nothing riding in for us, except...it's wickedly fast...
Again, I'm gonna compare zune-inflate and miniz-oxide.
The test bench is a 42mb enwiki file compressed to 13.3 mb of zlib infused madness, we test decompression on the machine
| File | Metric | zune-inflate | flate2/miniz-oxide | flate/zlib-ng | libdeflate | |-------------|------------|--------------|--------------------|---------------|-------------| | enwiki_part | Speed | 86.295 ms | 158.11 ms | 112.18 ms | 63.745ms | | | Throughput | 153.83 Mb/s | 84.230 Mb/s | 118.72 Mb/s | 208.92 Mb/s |
libdeflate: Provided by [libdeflater] which offers bindings to [libdeflate]
Damn impressive libdeflate, damn impressive
The decoder is currently fuzzed for correctness by both miniz-oxide
and zlib-ng
, see the fuzz/src directory