8 releases
Uses new Rust 2024
| 0.2.6 | Mar 21, 2026 |
|---|---|
| 0.2.5 | Mar 18, 2026 |
| 0.2.1 | Feb 8, 2026 |
| 0.1.0 | Jan 12, 2026 |
#767 in Compression
2,090 downloads per month
Used in 155 crates
(28 directly)
385KB
7.5K
SLoC
oxiarc-lz4
Pure Rust implementation of LZ4 compression algorithm with LZ4-HC (High Compression).
Version: 0.2.6 (2026-03-18) | Tests: 110 passing
Overview
LZ4 is a lossless compression algorithm focused on compression and decompression speed, making it ideal for real-time applications. It provides an excellent balance between speed and compression ratio. Version 0.2.6 adds an acceleration parameter for tuning compression speed vs ratio, along with continued improvements to the dictionary (dict) and high-compression (hc) modules.
Features
- Pure Rust - No C dependencies or unsafe FFI
- Extremely fast - Optimized for speed-critical applications
- LZ4-HC - High Compression mode for better ratios at the cost of speed
- Frame format support - Compatible with LZ4 frame format
- Block format support - Low-level block API available
- Content size tracking - Original size metadata in frames
- Parallel compression - Optional multi-threaded compression via Rayon (
parallelfeature) - Acceleration parameter - Tunable speed/ratio tradeoff for compression
- Dictionary support - Improved dictionary compression
Quick Start
use oxiarc_lz4::{compress, decompress};
// Compress data
let original = b"Hello, LZ4! ".repeat(100);
let compressed = compress(&original)?;
// Decompress data
let decompressed = decompress(&compressed)?;
assert_eq!(decompressed, original);
API
Frame Format (High-Level)
use oxiarc_lz4::{Lz4Writer, Lz4Reader};
use std::io::Cursor;
// Compression
let mut output = Vec::new();
let mut writer = Lz4Writer::new(&mut output);
writer.write_compressed(&data)?;
// Decompression
let mut reader = Lz4Reader::new(Cursor::new(compressed))?;
let decompressed = reader.decompress()?;
Block Format (Low-Level)
use oxiarc_lz4::block::{compress_block, decompress_block};
let compressed = compress_block(&data);
let decompressed = decompress_block(&compressed, original_size)?;
Parallel Compression
use oxiarc_lz4::compress_parallel;
// Use all available CPU cores (requires `parallel` feature)
let compressed = compress_parallel(&data)?;
Features (Cargo)
| Feature | Default | Description |
|---|---|---|
parallel |
no | Multi-threaded block compression via Rayon |
[dependencies]
# Default (no parallel)
oxiarc-lz4 = "0.2.6"
# With parallel compression
oxiarc-lz4 = { version = "0.2.6", features = ["parallel"] }
Use Cases
- Real-time data streaming - Network protocols, game assets
- Log compression - Fast compression for high-volume logs
- Cache compression - Reduce memory usage with minimal overhead
- Backup systems - Quick compression for frequent backups
Algorithm
LZ4 uses simple but effective techniques:
- LZ77-style matching - Find repeated sequences
- Token encoding - Compact representation of literals and matches
- Fast hash table - Quick pattern matching
- No entropy coding - Raw tokens for maximum speed
Part of OxiArc
This crate is part of the OxiArc project - a Pure Rust archive/compression library ecosystem.
License
Apache-2.0
Dependencies
~130–760KB
~17K SLoC