Skip to main content

Crate sirocco

Crate sirocco 

Source
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::Encoder compresses 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::Writer compresses what is written to it into any std::io::Write.

Decompressing is in inflate:

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::Scanner finds a stream’s end and output length without writing it, for example to walk a git pack.

§Features

Modules§

deflate
DEFLATE, zlib and gzip compression.
inflate
DEFLATE, zlib and gzip decompression.

Enums§

Format
Which wrapper, if any, goes around the DEFLATE stream.

Functions§

compressalloc
Compresses all of input into a new Vec, at level.
decompressalloc
Decompresses all of input into a new Vec of at most max_len bytes.