| Crates.io | oxiarc-deflate |
| lib.rs | oxiarc-deflate |
| version | 0.1.0 |
| created_at | 2026-01-12 08:02:17.270232+00 |
| updated_at | 2026-01-12 08:02:17.270232+00 |
| description | Pure Rust DEFLATE compression algorithm (RFC 1951) for OxiArc |
| homepage | |
| repository | https://github.com/cool-japan/oxiarc |
| max_upload_size | |
| id | 2037212 |
| size | 108,480 |
Pure Rust implementation of the DEFLATE compression algorithm (RFC 1951).
DEFLATE is the compression algorithm used in:
This crate provides both compression and decompression with no external dependencies.
use oxiarc_deflate::{deflate, inflate};
// Compress data
let original = b"Hello, World! Hello, World! Hello, World!";
let compressed = deflate(original, 6)?; // Level 6 (default)
// Decompress data
let decompressed = inflate(&compressed)?;
assert_eq!(&decompressed, original);
| Level | Description | Use Case |
|---|---|---|
| 0 | Stored (no compression) | Already compressed data |
| 1-3 | Fast compression | Real-time streaming |
| 4-6 | Balanced (default: 6) | General purpose |
| 7-9 | Best compression | Archival, storage |
// Compress with specified level
let compressed = deflate(data, level)?;
// Decompress
let decompressed = inflate(&compressed)?;
use oxiarc_deflate::{Deflater, Inflater};
// Streaming compression
let mut deflater = Deflater::new(6);
let compressed = deflater.compress_all(data)?;
// Streaming decompression
let mut inflater = Inflater::new();
loop {
let (consumed, produced, status) = inflater.decompress(input, output)?;
// Handle status...
}
use oxiarc_deflate::{Lz77Encoder, Lz77Token};
let mut encoder = Lz77Encoder::new(6);
for token in encoder.encode(data) {
match token {
Lz77Token::Literal(byte) => { /* literal byte */ }
Lz77Token::Match { length, distance } => { /* back-reference */ }
}
}
use oxiarc_deflate::{HuffmanTree, HuffmanBuilder};
// Build tree from code lengths
let lengths = [3, 3, 3, 3, 3, 2, 4, 4];
let tree = HuffmanTree::from_lengths(&lengths)?;
// Decode symbols
let symbol = tree.decode(&mut bit_reader)?;
+------------------+
| Block Header | (3 bits: BFINAL + BTYPE)
+------------------+
| Block Data | (varies by type)
+------------------+
| ... more blocks |
+------------------+
| BTYPE | Name | Description |
|---|---|---|
| 00 | Stored | Uncompressed data (up to 65535 bytes) |
| 01 | Fixed | Fixed Huffman codes (RFC 1951 Table) |
| 10 | Dynamic | Custom Huffman codes in header |
| 11 | Reserved | Invalid |
Literal/Length (286 symbols):
Distance (30 symbols):
| Range | Code Length |
|---|---|
| 0-143 | 8 bits |
| 144-255 | 9 bits |
| 256-279 | 7 bits |
| 280-287 | 8 bits |
| Module | Description |
|---|---|
deflate |
Compression (encoder) |
inflate |
Decompression (decoder) |
huffman |
Huffman tree operations |
lz77 |
LZ77 dictionary encoder |
tables |
Fixed Huffman tables, length/distance extra bits |
Compression ratios on typical data (Calgary Corpus):
| File | Original | Compressed | Ratio |
|---|---|---|---|
| book1 | 768771 | ~300000 | ~61% |
| paper1 | 53161 | ~18000 | ~66% |
| progc | 39611 | ~13000 | ~67% |
MIT OR Apache-2.0