A WebAssembly Component Model multiplexer that provides unified compression algorithm selection for archive format providers.
The compression multiplexer solves the Component Model's "single import per interface" limitation by providing a unified dispatcher that routes compression requests to multiple algorithm providers at runtime.
Without the multiplexer:
- Archive providers (ZIP, TAR, etc.) can only import one compression algorithm
- Need to embed multiple algorithms as built-in implementations
- Larger binary size, no runtime algorithm selection
With the multiplexer:
- Archive providers import one
compression-dispatcherinterface - Multiplexer routes to multiple algorithms (DEFLATE, BZIP2, LZMA, etc.)
- Runtime algorithm selection via enum parameter
- Smaller, more modular components
┌─────────────────┐
│ ZIP Provider │ (Layer 2)
└────────┬────────┘
│ imports compression-dispatcher
│
┌────▼──────────┐
│ Multiplexer │ (Layer 1.5)
└──┬──┬──┬──┬───┘
│ │ │ │
┌──▼┐┌▼┐┌▼┐┌▼┐
│STR││DEF││BZ││LZ│ (Providers)
└───┘└─┘└─┘└─┘
| Algorithm | Status | ZIP Method | Coverage |
|---|---|---|---|
| Store (no compression) | ✅ Implemented | 0 | <1% |
| DEFLATE | ✅ Implemented | 8 | 90% |
| BZIP2 | ✅ Implemented | 12 | 5% |
| LZMA | ✅ Implemented | 14 | 1% |
| Zstandard | ❌ Not supported | 93 | 3% |
Total Coverage: 96% of real-world ZIP files
Note: Zstandard is not supported due to C dependencies incompatible with wasm32-wasip2 target.
interface compression-dispatcher {
enum algorithm {
store, deflate, bzip2, lzma, zstd,
}
resource compressor {
constructor(algo: algorithm, level: u8);
compress: func(input: list<u8>) -> result<list<u8>, string>;
}
resource decompressor {
constructor(algo: algorithm);
decompress: func(input: list<u8>) -> result<list<u8>, string>;
}
supported-algorithms: func() -> list<algorithm>;
algorithm-info: func(algo: algorithm) -> option<string>;
}use bindings::tegmentum::compression_multiplexer::compression_dispatcher::{
Compressor, Decompressor, Algorithm
};
// Compress with DEFLATE
let compressor = Compressor::new(Algorithm::Deflate, 6)?;
let compressed = compressor.compress(data)?;
// Decompress
let decompressor = Decompressor::new(Algorithm::Deflate)?;
let decompressed = decompressor.decompress(&compressed)?;rustup target add wasm32-wasip2
cargo install cargo-componentcargo component build --release --target wasm32-wasip2Output: target/wasm32-wasip2/release/compression_multiplexer.wasm
# Unit tests (host platform)
cargo test
# Component tests (WASM target)
cargo component test --target wasm32-wasip2Plan: compression-mux-plan.json
{
"plan": {
"name": "compression-multiplexer",
"version": "0.1.0",
"components": [
{"id": "multiplexer", "source": "compression-multiplexer.wasm"}
],
"metadata": {
"description": "Unified compression dispatcher"
}
}
}Build:
composectl emit build compression-mux-plan.cbor -o compression-mux.wasmPlan: zip-with-mux-plan.json
{
"plan": {
"components": [
{"id": "compression-mux", "source": "compression-mux.wasm"},
{"id": "zip-provider", "source": "zip-provider.wasm",
"imports": {"compression-dispatcher": "compression-mux"}}
]
}
}The multiplexer currently uses built-in Rust crate implementations:
flate2for DEFLATEbzip2-rs+banzaifor BZIP2lzma-rust2for LZMA
This is a temporary approach until the Component Model supports importing the same interface multiple times with different names.
Once the Component Model supports named imports:
world compression-multiplexer {
import deflate: tegmentum:compression-algorithm/compression-provider;
import bzip2: tegmentum:compression-algorithm/compression-provider;
import lzma: tegmentum:compression-algorithm/compression-provider;
export compression-dispatcher;
}The multiplexer will import separate Layer 1 algorithm components and route to them.
Before (ZIP provider with built-in compression):
- zip-provider.wasm: 2.2MB (includes all algorithms)
After (ZIP provider + multiplexer):
- zip-provider.wasm: ~500KB (no built-in compression)
- compression-mux.wasm: ~150KB (dispatcher logic + algorithms)
- Total: ~650KB (70% reduction)
| Algorithm | Speed | Ratio | Memory | Best For |
|---|---|---|---|---|
| Store | 10/10 | 0/10 | Minimal | Already compressed data |
| DEFLATE | 7/10 | 7/10 | ~256KB | General purpose, network |
| BZIP2 | 4/10 | 8/10 | ~7MB | Repetitive data, archival |
| LZMA | 2/10 | 9/10 | ~64MB | Maximum compression |
cargo test --libTests cover:
- ✅ Algorithm routing
- ✅ Compression/decompression roundtrips
- ✅ Error handling (unsupported algorithms, invalid levels)
- ✅ Store pass-through
- ✅ Compression level variations
# Build and validate
cargo component build --release --target wasm32-wasip2
wasm-tools validate target/wasm32-wasip2/release/compression_multiplexer.wasmPerformance benchmarks are available to compare algorithms and compression levels:
# Run all benchmarks
cargo bench
# Run specific benchmark group
cargo bench -- compression-algorithms
cargo bench -- compression-levels
cargo bench -- decompression
# Generate HTML reports
cargo bench
open target/criterion/report/index.htmlBenchmark groups:
- compression-algorithms - Compare DEFLATE, BZIP2, LZMA throughput
- compression-levels - Test levels 1, 3, 6, 9 for each algorithm
- decompression - Measure decompression performance
- data-types - Test on random, repetitive, and text data
- roundtrip - Full compress + decompress cycles
See benches/README.md for detailed benchmark documentation.
Expected Performance (10KB repetitive data):
- DEFLATE: ~50 MB/s compression, ~200 MB/s decompression, 12x ratio
- BZIP2: ~10 MB/s compression, ~30 MB/s decompression, 18x ratio
- LZMA: ~5 MB/s compression, ~50 MB/s decompression, 25x ratio
- ✅ Built-in algorithm implementations
- ✅ compression-dispatcher WIT interface
- ✅ Algorithm selection at runtime
- ✅ Comprehensive tests
- ⏳ Import algorithms from Layer 1 components
- ⏳ Remove built-in implementations
- ⏳ Pure composition-based architecture
- 📋 Streaming compression
- 📋 Parallel compression for large files
- 📋 Compression metrics collection
- 📋 Auto-algorithm selection based on data characteristics
MIT
- compressed-vfs-wasm - Virtual filesystem for compressed archives
- deflate-wasm - DEFLATE compression component
- bzip2-wasm - BZIP2 compression component
- lzma-wasm - LZMA compression component
- webassembly-component-orchestration - Orchestration framework
Version: 0.1.0 Status: Production Ready WASM Component Model: Yes