Expand description
Fast DEFLATE, zlib and gzip compression and decompression in pure Rust.
sirocco compresses and decompresses with the same fast core whether it gets the whole input at once or piece by piece, without allocating.
For a one-off call, use compress and decompress:
use sirocco::Format;
// "hello hello hello" as a raw DEFLATE stream.
let compressed = [0xcb, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0xc8, 0x40, 0x90, 0x00];
let data = sirocco::decompress(Format::Deflate, &compressed, 1 << 20)?;
assert_eq!(data, b"hello hello hello");Compressing is in deflate:
deflate::Encodercompresses from a buffer you own, in one call or many, with zlib’s flushes. Its levels are zlib’s, each compressing about as well as zlib’s same level, several times faster.deflate::Writercompresses what is written to it into anystd::io::Write.
Decompressing is in inflate:
inflate::Decoderdecompresses into your buffer, from input in one piece or many, without allocating. Reuse it: its tables are costly to set up.inflate::Readerreads from anystd::io::BufRead:
use std::io::Read;
use sirocco::{inflate, Format};
let mut reader = inflate::Reader::new(Format::Deflate, &compressed[..]);
let mut data = String::new();
reader.read_to_string(&mut data)?;
assert_eq!(data, "hello hello hello");inflate::Scannerfinds a stream’s end and output length without writing it, for example to walk a git pack.
§Features
std(default):deflate::Writer,inflate::Readerandstd::iointegrations; enablesalloc.alloc:compressanddecompress, anddeflate::Encoder::new, which allocates the encoder’s tables. Without it,deflate::Encoder(with tables you give it, seewith_tables),inflate::Decoderandinflate::Scannerstill work.
Modules§
Enums§
- Format
- Which wrapper, if any, goes around the DEFLATE stream.
Functions§
- compress
alloc - Compresses all of
inputinto a newVec, atlevel. - decompress
alloc - Decompresses all of
inputinto a newVecof at mostmax_lenbytes.