Lossless compression for blockchain data -- up to 60:1 ratios with Zstandard and custom dictionaries, built in Rust.
Blockchain data is full of repeated structures -- program IDs, public keys, signatures, common amounts -- that general-purpose compressors don't exploit. This library uses Zstandard with custom dictionaries trained on blockchain-specific byte patterns to achieve dramatically better compression ratios while guaranteeing perfect data integrity.
Add to your Cargo.toml:
[dependencies]
blockchain-compression = { version = "0.1", features = ["zstd"] }Compress and decompress:
use blockchain_compression::presets::solana::{SolanaCompressor, SolanaPreset};
use blockchain_compression::core::traits::CompressionStrategy;
let mut compressor = SolanaCompressor::new(SolanaPreset::Transactions);
let compressed = compressor.compress(data)?;
let decompressed = compressor.decompress(&compressed)?;
assert_eq!(data, decompressed.as_slice());- Blockchain-optimized dictionaries -- custom Zstandard dictionaries for Solana program IDs, signatures, and common patterns
- 6 compression presets -- from real-time (
FastCompression) to archival (MaxCompression) - Multiple backends -- Zstandard, DEFLATE, and LZ4 support via feature flags
- 100% lossless -- rigorous roundtrip validation on every operation
- Thread-safe -- safe for concurrent usage across threads
- Trait-based architecture -- composable
CompressionStrategytrait for custom implementations
| Preset | Zstd Level | Compression Ratio | Best For |
|---|---|---|---|
FastCompression |
3 | 5--15:1 | Real-time processing |
Transactions |
3 | 10--30:1 | Transaction data |
Instructions |
6 | 10--25:1 | Program instructions |
Accounts |
6 | 15--40:1 | Account state snapshots |
Mixed |
6 | 12--35:1 | General-purpose |
MaxCompression |
19 | 20--60:1 | Archival storage |
Enable the compression backend you need:
# Zstandard (recommended)
blockchain-compression = { version = "0.1", features = ["zstd"] }
# DEFLATE
blockchain-compression = { version = "0.1", features = ["deflate"] }
# LZ4
blockchain-compression = { version = "0.1", features = ["lz4"] }# Build
cargo build --features zstd
# Run tests
cargo test --features zstd
# Run examples
cargo run --example basic_usage --features zstd
cargo run --example performance_benchmark --features zstd
# Benchmarks
cargo bench --features zstd- API Reference -- full Rustdoc on docs.rs
- User Guide -- mkdocs-based guides and tutorials
- API Details -- in-repo API documentation
- Examples -- runnable code examples
MIT