| Crates.io | lznt1 |
| lib.rs | lznt1 |
| version | 0.1.3 |
| created_at | 2025-12-01 22:23:55.846242+00 |
| updated_at | 2025-12-01 22:46:04.338457+00 |
| description | A pure Rust implementation of the LZNT1 compression algorithm used by Windows. |
| homepage | |
| repository | https://github.com/xangelix/lznt1 |
| max_upload_size | |
| id | 1960752 |
| size | 61,981 |
A safe, pure-Rust, no_std implementation of the LZNT1 compression algorithm.
LZNT1 is the standard compression algorithm used by the Windows NT kernel, notably in NTFS filesystem compression, Active Directory replication, and various Windows API functions (RtlCompressBuffer). This crate allows you to read and write LZNT1 streams on any platform without linking to system libraries.
#![forbid(unsafe_code)].no_std Compatible: only requires the alloc crate.compress and decompress functions operating on byte slices and vectors.Add this to your Cargo.toml:
[dependencies]
lznt1 = "0.1.0" # Use the latest version
use lznt1::decompress;
fn main() -> Result<(), lznt1::DecompressionError> {
// Example: "Hello world" compressed
let compressed_data = [
0x0c, 0xb0, 0x00,
b'H', b'e', b'l', b'l', b'o', b' ', b'w', b'o',
0x00,
b'r', b'l', b'd',
];
let mut buffer = Vec::new();
decompress(&compressed_data, &mut buffer)?;
assert_eq!(buffer, b"Hello world");
Ok(())
}
use lznt1::compress;
fn main() {
let input = b"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.";
let mut compressed_output = Vec::new();
compress(input, &mut compressed_output);
println!("Original size: {}", input.len());
println!("Compressed size: {}", compressed_output.len());
}
LZNT1 works by splitting data into 4KB chunks. Each chunk is stored either:
0xB000 + size) followed by LZ77 sequences (literals and offset/length tuples).0x3000 + size) followed by raw data (used when compression doesn't save space).This implementation handles the adaptive window splitting logic and the "Tag Group" format (1 tag byte per 8 items) defined by the algorithm.
This crate prioritizes correctness and safety.
cargo-fuzz to verify that the decompressor never panics or crashes, even on malicious/random input.criterion.To run the tests:
cargo test
To run benchmarks:
cargo bench
This project is licensed under the MIT License.