Skip to main content

Crate noflate

Crate noflate 

Source
Expand description

A zero-dependency DEFLATE (RFC 1951), gzip (RFC 1952), and zlib (RFC 1950) encoder and decoder.

§Examples

One-shot compression and decompression:

let input = b"Hello, DEFLATE!";
let compressed = noflate::deflate::compress(input)?;
let decompressed = noflate::deflate::decompress(&compressed)?;
assert_eq!(decompressed, input);

Streaming encoder:

let mut encoder = noflate::deflate::Encoder::new();
encoder.feed(b"Hello, ")?;
encoder.feed(b"world!")?;
encoder.finish()?;
let compressed = encoder.output().to_vec();
encoder.advance(compressed.len());
assert_eq!(
    noflate::deflate::decompress(&compressed)?,
    b"Hello, world!",
);

Streaming decoder:

let mut decoder = noflate::deflate::Decoder::new();
decoder.feed(&compressed)?;
let out = decoder.output().to_vec();
decoder.advance(out.len());
assert!(decoder.is_finished());
assert_eq!(out, b"hello");

The gzip and zlib modules provide the same API shape for their respective container formats.

The crate performs no I/O itself, but the sans-io API plugs into std::io::Write and std::io::Read with a small adapter: drain deflate::Encoder::output into any Write sink, and top up deflate::Decoder::feed from any Read source. See examples/io_bridge.rs in the repository for a runnable DeflateWriter / DeflateReader pair; the same pattern works verbatim for the gzip and zlib streaming types.

Format::detect identifies the format of a compressed stream:

let data = noflate::gzip::compress(b"hello")?;
assert_eq!(noflate::Format::detect(&data), Some(noflate::Format::Gzip));

Modules§

deflate
Raw DEFLATE (RFC 1951) encoder and decoder.
gzip
GZIP (RFC 1952) encoder and decoder.
zlib
ZLIB (RFC 1950) encoder and decoder.

Enums§

Error
Errors returned by the encoder and decoder.
Format
The detected compression format of a byte stream.

Type Aliases§

Result
Convenience alias for Result<T, Error>.