Crates.io | lzf |
lib.rs | lzf |
version | 1.0.0 |
source | src |
created_at | 2014-11-22 13:27:55.538815 |
updated_at | 2022-11-06 13:07:21.064579 |
description | DEPRECATED! An implementation of LZF, a very small data compression algorithm |
homepage | https://github.com/badboy/lzf-rs |
repository | https://github.com/badboy/lzf-rs |
max_upload_size | |
id | 339 |
size | 45,426 |
DEPRECATED
LibLZF is a super small and fast compression library, originally written by Marc Lehmann. It's written in C and consists of only 4 files. And this is the rewrite in Rust.
Instead of rewriting the whole thing in Rust, I used Rust's Foreign Function Interface and wrote a wrapper.
The whole Rust code is under 50 lines (yes, there is more test code than actual implementation code).
And it is super easy to use, though I'm not happy with the current interface.
I sat down and tried to understand the original C code and then rewrote it in (mostly) safe Rust code.
And the best thing: it's still super fast (on some basic benchmarks it's nearly as fast as the original code).
It now consists of roughly 200 lines of code, which is probably around the same as the original implementation.
cargo build --release
fn main() {
let data = "foobar";
let compressed = lzf::compress(data.as_bytes()).unwrap();
let decompressed = lzf::decompress(&compressed, data.len()).unwrap();
}
Run tests with:
cargo test
Run benchmarks with:
cargo bench
If you find bugs or want to help otherwise, please open an issue.
This is my first released library in Rust and I'm still learning. So if there are better ways to do things in Rust, I'm happy to hear about it.