Crate lzokay_native
source ·Expand description
LZ👌in Rust
A pure rust port of lzokay, which is a C++ implementation of the LZO compression format.
Examples
Compressing raw data
use std::fs::File;
fn main () -> Result<(), lzokay_native::Error> {
let data = include_bytes!("../test-data/uncompressed/alice29.txt");
let compressed = lzokay_native::compress(data);
Ok(())
}
Multiple compressions without repeated (de-)allocations
By using a Dict
and compress_with_dict
you can avoid repeat allocation/deallocation
of the work memory used by the compressor:
use std::fs::File;
fn main () -> Result<(), lzokay_native::Error> {
let mut dict = lzokay_native::Dict::new();
let data1 = include_bytes!("../test-data/uncompressed/alice29.txt");
let compressed1 = lzokay_native::compress_with_dict(data1, &mut dict)?;
let data2 = include_bytes!("../test-data/uncompressed/asyoulik.txt");
let compressed2 = lzokay_native::compress_with_dict(data2, &mut dict)?;
Ok(())
}
Decompressing a file
use std::fs::File;
fn main () -> Result<(), lzokay_native::Error> {
let file_path = "./test-data/compressed/fields.c.lzo";
let mut file = File::open(file_path)?; // file implements std::io::Read
let decompressed = lzokay_native::decompress(&mut file, None);
Ok(())
}
Decompressing raw data
use std::fs::File;
fn main () -> Result<(), lzokay_native::Error> {
let data = include_bytes!("../test-data/compressed/fields.c.lzo");
let decompressed = lzokay_native::decompress_all(data, None);
Ok(())
}
Structs
- Dict
compress
ADict
can be used to across multiple compression runs; avoiding repeat allocation/deallocation of the work memory used by the compressor.
Enums
- The various errors that can be reported by this crate.
Functions
- compress
compress
Compresses a byte slice and returns the result as a newVec<u8>
. - compress_with_dict
compress
Compresses a byte slice and returns the result as a newVec<u8>
. - compress_worst_size
compress
Returns the worst (maximum) size of the compressed data when compressing data of a given size. - decompress
decompress
Decompresses a lzo-compressed reader and returns the result as a newVec<u8>
. - decompress_all
decompress
Decompresses a byte slice and returns the result as a newVec<u8>
.