blockchain-compression
Lossless compression for blockchain data -- up to 60:1 ratios with Zstandard and custom dictionaries, built in Rust.
Why blockchain-compression?
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.
Quick Start
Add to your Cargo.toml:
[]
= { = "0.1", = ["zstd"] }
Compress and decompress:
use ;
use CompressionStrategy;
let mut compressor = new;
let compressed = compressor.compress?;
let decompressed = compressor.decompress?;
assert_eq!;
Features
- 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
Presets
| 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 |
Installation
Enable the compression backend you need:
# Zstandard (recommended)
= { = "0.1", = ["zstd"] }
# DEFLATE
= { = "0.1", = ["deflate"] }
# LZ4
= { = "0.1", = ["lz4"] }
Building and Testing
# Build
# Run tests
# Run examples
# Benchmarks
Documentation
- API Reference -- full Rustdoc on docs.rs
- User Guide -- mkdocs-based guides and tutorials
- API Details -- in-repo API documentation
- Examples -- runnable code examples
License
MIT