A small wrapper around LibLZF, a very small data compression library

11 releases

Uses old Rust 2015

0.3.1 Sep 27, 2015
0.3.0 Sep 16, 2015
0.2.3 Apr 3, 2015
0.2.1 Feb 26, 2015
0.1.0 Nov 22, 2014

#108 in Compression

Download history 169/week @ 2021-06-30 182/week @ 2021-07-07 242/week @ 2021-07-14 126/week @ 2021-07-21 193/week @ 2021-07-28 152/week @ 2021-08-04 124/week @ 2021-08-11 180/week @ 2021-08-18 140/week @ 2021-08-25 115/week @ 2021-09-01 157/week @ 2021-09-08 63/week @ 2021-09-15 129/week @ 2021-09-22 212/week @ 2021-09-29 247/week @ 2021-10-06 394/week @ 2021-10-13

795 downloads per month
Used in 7 crates (6 directly)


846 lines

LZF - a very small data compression library

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


extern crate lzf;

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.


liblzf is BSD as well. See lzf.h.

No runtime deps