Skip to main content

Crate lzallright

Crate lzallright 

Source
Expand description

The crate is started as a port of the C++ lzokay library.

LZO compresses a block of data into matches (a sliding dictionary) and runs of non-matching literals to produce good results on highly redundant data

— Wikipedia

There is no publicly available documentation of the LZO format. A good introduction is available in the Linux Kernel documentation

The crate is no_std. Decompression works without any allocation. For compression, a Dict instance is needed.

§Examples

use lzallright::{compress, decompress, worst_case_len, Dict};

let input = b"hello world";

// You should reuse the dictionary across calls.
let mut dict = Dict::new();
let mut compressed = vec![0u8; worst_case_len(input.len())];
let n = compress(input, &mut compressed, &mut dict).unwrap();
compressed.truncate(n);

let mut output = vec![0u8; input.len()];
let m = decompress(&compressed, &mut output).unwrap();
assert_eq!(&output[..m], input);

Structs§

Dict
Compressor state. Contains a sliding window and two extremely simple hash-tables.
Error
The error type of compression and decompression operations.

Enums§

ErrorKind
List specifying categories of compression and decompression related errors.

Functions§

compress
Compresses the content of the slice src into out, using dict to store compressor state. In case of success, returns the number of bytes produced.
decompress
Decompresses the LZO stream src into dst and returns the number of bytes written.
worst_case_len
Returns the maximum length needed to hold the compressed data of size.