Module compress::rle [] [src]

Run time length encoding and decoding based on byte streams, see https://en.wikipedia.org/wiki/Run-length_encoding.

A run is defined as a sequence of identical bytes of length two or greater. A run of byte a and length n is encoded by a two repitions of a, followed by a length specification which describes how much often these bytes are repeated. Such a specification is a string of bytes with dynamic length. The most significat bit of each byte in this string indicates if the byte is the last byte in the string. The rest of the bits are concatenated using the Little Endian convention.

Example

use compress::rle;
use std::io::{Write, Read};

let input = b"Helloooo world!!";

let mut encoder = rle::Encoder::new(Vec::new());
encoder.write_all(&input[..]).unwrap();
let (buf, _): (Vec<u8>, _) = encoder.finish();

let mut decoder = rle::Decoder::new(&buf[..]);
let mut decoder_buf = Vec::new();
decoder.read_to_end(&mut decoder_buf).unwrap();

assert_eq!(&input[..], &decoder_buf[..]);

Structs

Decoder

This structure is used to decode a run length encoded stream. This wraps an internal reader which is read from when this decoder's read method is called.

Encoder

This structure is used to compress a stream of bytes using a RLE compression algorithm. This is a wrapper around an internal writer which bytes will be written to.