2 releases

0.1.1 May 8, 2021
0.1.0 Oct 30, 2020

#363 in Compression

Download history 15/week @ 2024-02-19 26/week @ 2024-02-26 4/week @ 2024-03-04 7/week @ 2024-03-11 11/week @ 2024-03-25 47/week @ 2024-04-01

66 downloads per month
Used in 2 crates

MIT license

532 lines


High-level Rust bindings for lzham codec built upon the lower-level lzham-sys crate.

You must have cmake and a C++ compiler to build this crate, as the lzham-sys crate builds lzham library and does not search for a prebuilt library.


Add the following to your Cargo.toml:

lzham = "0.1.1"


use lzham::{compress, decompress};
let data = String::from("This is a test.");

let mut comp = Vec::new();
let status = compress(&mut data.as_bytes(), &mut comp);


let mut decomp = Vec::new();
let status = decompress(&mut comp.as_slice(), &mut decomp, data.len());



lzham supports both static and dynamic linking. To link statically, you can either set LIBLZHAM_STATIC or LZHAM_STATIC environment variables to true, or use the static feature.

To link dynamically, use the dynamic feature.

If you don't set any environment variables or use any features, the build will be the expected default library linking method based on OS or target. For Windows, macOS and Linux with musl, it will be static. For Linux without musl, it will be dynamic.

Note that environment variables take precedence over features. In case of any ambiguity, it uses the default linking method.


The crate has the following two features:

  • static: Links to the library statically
  • dynamic: Links to the library dynamically

These set the appropriate lzham-sys features, which is responsible for building and linking the library.


lzham is available under the MIT license. See LICENSE for more details.


~31K SLoC