#lzma #decompression

no-std patina_lzma_rs

A codec for LZMA, LZMA2 and XZ written in pure Rust

1 unstable release

0.3.2 Oct 12, 2025

#545 in Compression

Download history 443/week @ 2025-10-20 413/week @ 2025-10-27 795/week @ 2025-11-03 830/week @ 2025-11-10 1142/week @ 2025-11-17 451/week @ 2025-11-24 1111/week @ 2025-12-01 657/week @ 2025-12-08 507/week @ 2025-12-15 222/week @ 2025-12-22 105/week @ 2025-12-29 772/week @ 2026-01-05 427/week @ 2026-01-12 444/week @ 2026-01-19 451/week @ 2026-01-26 558/week @ 2026-02-02

1,887 downloads per month
Used in patina_ffs_extractors

MIT license

155KB
4K SLoC

patina_lzma_rs

Minimum Rust 1.78 Safety Dance Build Status

Origin

This repo is forked off of Guillaume Endignoux's lzma-rs with the intent of providing no_std compatibility while maintaining all existing functionality. This crate should be considered temporary in that, should no_std compatibility be added to the upstream, this crate will no longer have a reason to exist.

Description

This project is a decoder for LZMA and its variants written in pure Rust, with focus on clarity. It already supports LZMA, LZMA2 and a subset of the .xz file format.

Usage

Decompress a .xz file.

let filename = "foo.xz";
let mut f = std::io::BufReader::new(std::fs::File::open(filename).unwrap());
// "decomp" can be anything that implements "std::io::Write"
let mut decomp: Vec<u8> = Vec::new();
patina_lzma_rs::xz_decompress(&mut f, &mut decomp).unwrap();
// Decompressed content is now in "decomp"

Compress a slice into a vector in a no_std environment.

#![no_std]
extern crate alloc;
use alloc::vec::Vec;

let data: &[u8] = gather_my_data();
let compressed_data: Vec<u8> = Vec::new();

patina_lzma_rs::lzma_compress(&mut lzma_compress::io::Cursor::new(data), compressed_data).unwrap();
// Compressed content is now in decomp

Encoder

For now, there is also a dumb encoder that only uses byte literals, with many hard-coded constants for code simplicity. Better encoders are welcome!

Contributing

Pull-requests are welcome, to improve the decoder, add better encoders, or more tests. Ultimately, this project should also implement .xz and .7z files.

License

MIT

Dependencies

~175–265KB