| Crates.io | pklib |
| lib.rs | pklib |
| version | 0.2.0 |
| created_at | 2025-06-05 05:52:19.773649+00 |
| updated_at | 2025-07-05 04:21:09.154547+00 |
| description | Pure Rust implementation of PKWare Data Compression Library (DCL) with full PKLib compatibility |
| homepage | https://github.com/danielsreichenbach/pklib-rs |
| repository | https://github.com/danielsreichenbach/pklib-rs |
| max_upload_size | |
| id | 1701111 |
| size | 351,480 |
A pure Rust implementation of the PKWare Data Compression Library (DCL) format (1980s DOS era), providing high-performance compression and decompression compatible with the original PKLib by Ladislav Zezula.
PKLib implements the PKWare DCL format used in game archives like MPQ and other legacy applications. It provides both compression ("implode") and decompression ("explode") functionality with full compatibility to the original PKLib specification. This format uses Huffman coding and sliding dictionary compression, and is covered by Patent No. 5,051,745.
Read/Write traitsAdd to your Cargo.toml:
[dependencies]
pklib = "0.2"
use pklib::{CompressionMode, DictionarySize, explode_bytes, implode_bytes};
// Decompress PKLib-compressed data
let compressed_data = std::fs::read("data.imploded")?;
let decompressed = explode_bytes(&compressed_data)?;
// Compress data using PKLib format
let data = b"Hello, World! This is a test of the PKLib compression.";
let compressed = implode_bytes(data, CompressionMode::ASCII, DictionarySize::Size2K)?;
use std::io::{Read, Write};
use pklib::{ExplodeReader, ImplodeWriter, CompressionMode, DictionarySize};
// Decompress using streaming API
let compressed_data = std::fs::read("large_file.imploded")?;
let mut decompressor = ExplodeReader::new(std::io::Cursor::new(compressed_data))?;
let mut decompressed = Vec::new();
decompressor.read_to_end(&mut decompressed)?;
// Compress using streaming API
let mut output = Vec::new();
let mut compressor = ImplodeWriter::new(&mut output, CompressionMode::Binary, DictionarySize::Size4K)?;
compressor.write_all(b"Data to compress")?;
let compressed_output = compressor.finish()?;
pklib includes a powerful CLI tool called blast-cli for compressing and decompressing files:
# Install from source
cargo install --path .
# Or run directly
cargo run --bin blast-cli -- --help
# Basic compression with ASCII mode (good for text)
blast-cli compress input.txt output.pklib --mode ascii
# Binary mode with 4KB dictionary (good for binary data)
blast-cli compress data.bin compressed.pklib --mode binary --dict-size size4-k
# Force overwrite existing files
blast-cli compress input.txt output.pklib --force
# Basic decompression
blast-cli decompress compressed.pklib restored.txt
# With verbose output
blast-cli --verbose decompress compressed.pklib restored.txt
# Get information about a compressed file
blast-cli info compressed.pklib
# Verbose output shows additional details
blast-cli --verbose info compressed.pklib
--mode: Choose binary (default) or ascii compression mode--dict-size: Dictionary size - size1-k, size2-k (default), or size4-k--force: Overwrite existing output files--verbose: Show detailed progress and statistics--quiet: Suppress non-error outputPKLib supports two compression modes optimized for different data types:
Choose the dictionary size based on your data characteristics:
| Feature | Status | Notes |
|---|---|---|
| Core Infrastructure | ✅ Complete | Types, errors, constants |
| Static Lookup Tables | ✅ Complete | All PKLib tables ported |
| CRC32 Implementation | ✅ Complete | PKLib-compatible checksums |
| Decompression (Explode) | ✅ Complete | Full PKLib compatibility verified |
| Compression (Implode) | ✅ Complete | Full PKLib compatibility verified |
| Testing & Validation | ✅ Complete | Comprehensive test suite with property testing |
| CLI Tool | ✅ Complete | Command-line interface with compress/decompress/info commands |
PKLib is designed for high performance with several optimizations:
Performance characteristics:
PKLib includes a comprehensive benchmark suite to measure performance across various scenarios:
# Run all benchmarks
cargo bench
# Run specific benchmark suite
cargo bench compression
cargo bench decompression
cargo bench round_trip
cargo bench memory
cargo bench concurrent
# Save baseline for comparison
cargo bench -- --save-baseline initial
# Compare against baseline
cargo bench -- --baseline initial
The benchmark suite covers:
This implementation achieves 100% compatibility with:
Contributions are welcome!
# Clone the repository
git clone https://github.com/danielsreichenbach/pklib-rs.git
cd pklib-rs
# Run tests
cargo test
# Format code
cargo fmt
# Run linter
cargo clippy --all-targets --all-features
# Run benchmarks
cargo bench
This project is licensed under the MIT License - see the LICENSE file for details.
Status: All 4 implementation phases are complete! PKLib provides a fully functional, production-ready implementation of the PKWare DCL format with comprehensive testing and validation.