inflate
A DEFLATE decoder written in rust.
This library provides functionality to decompress data compressed with the DEFLATE algorithm, both with and without a zlib header/trailer.
Examples
The easiest way to get std::Vec<u8>
containing the decompressed bytes is to use either
inflate::inflate_bytes
or inflate::inflate_bytes_zlib
(depending on whether
the encoded data has zlib headers and trailers or not). The following example
decodes the DEFLATE encoded string "Hello, world" and prints it:
use inflate_bytes;
use from_utf8;
let encoded = ;
let decoded = inflate_bytes.unwrap;
println!; // prints "Hello, world"
If you need more flexibility, then the library also provides an implementation
of std::io::Writer
in inflate::writer
. Below is an example using an
inflate::writer::InflateWriter
to decode the DEFLATE encoded string "Hello, world":
use InflateWriter;
use Write;
use from_utf8;
let encoded = ;
let mut decoder = new;
decoder.write.unwrap;
let decoded = decoder.finish.unwrap;
println!; // prints "Hello, world"
Finally, if you need even more flexibility, or if you only want to depend on
core
, you can use the inflate::InflateStream
API. The below example
decodes an array of DEFLATE encoded bytes:
use InflateStream;
let data = ;
let mut inflater = new;
let mut out = Vec:: new;
let mut n = 0;
while n < data.len