Skip to content
blockchain-compression cargo add →

// quickstart

cargo add to round-trip, in five steps.

No configuration files, no dictionary artifacts to download, no running node. Add the crate, pick a preset, and compress.

  1. 1

    Add the crate

    Add blockchain-compression to Cargo.toml with the zstd feature enabled — the Solana presets require it.

    [dependencies]
    blockchain-compression = { version = "0.1", features = ["zstd"] }
  2. 2

    Import the compressor and trait

    Bring the SolanaCompressor preset type and the CompressionStrategy trait into scope.

    use blockchain_compression::presets::solana::{
        SolanaCompressor, SolanaPreset,
    };
    use blockchain_compression::core::traits::CompressionStrategy;
  3. 3

    Pick a preset

    Choose the preset that matches your workload. Accounts for state snapshots, Transactions for tx batches, MaxCompression for cold archival.

    let mut compressor = SolanaCompressor::new(
        SolanaPreset::Accounts,
    );
  4. 4

    Compress

    Hand the compressor your raw bytes. It returns a smaller Vec of bytes.

    let compressed = compressor.compress(data)?;
  5. 5

    Decompress and verify the round-trip

    Decompress and assert byte-for-byte equality. This is the lossless contract — it holds on every operation.

    let decompressed = compressor.decompress(&compressed)?;
    assert_eq!(data, decompressed.as_slice());

// next

Not sure which preset? The presets page walks through choosing by workload. Want the internals? Read how it works. Full API on docs.rs.