oxiarc-snappy [Stable]
Pure Rust Snappy compression library, part of the OxiArc ecosystem.
Version: 0.2.8 (2026-05-08) | 57 tests passing
Features
- Pure Rust — No C dependencies or unsafe FFI
- Snappy block format — Fast in-memory compress/decompress
- Snappy framing format — Streaming API with CRC32C checksums per chunk
- Streaming API —
FrameEncoder<W: Write>andFrameDecoder<R: Read>for incremental processing - SSE 4.2 CRC32C hardware acceleration — x86_64 builds use
_mm_crc32_u64intrinsics via runtime dispatch (OnceLock), falling back to pure-Rust software CRC32C automatically
All features are implemented and tested. API is stable.
Quick Start
Add to your Cargo.toml:
[]
= "0.2.8"
Block Format
use ;
let data = b"Hello, World! Hello, World!";
let compressed = compress;
let decompressed = decompress?;
assert_eq!;
Framing Format (Streaming)
use ;
use ;
// Compress with streaming encoder
let mut compressed = Vecnew;
// Decompress with streaming decoder
let mut decoder = new;
let mut output = Vecnew;
decoder.read_to_end?;
assert_eq!;
API Overview
| Item | Kind | Description |
|---|---|---|
compress(data: &[u8]) -> Vec<u8> |
function | Snappy block compression |
decompress(data: &[u8]) -> Result<Vec<u8>, SnappyError> |
function | Snappy block decompression |
max_compress_len(input_len: usize) -> usize |
function | Upper bound on compressed size |
decompress_len(compressed: &[u8]) -> Result<usize, SnappyError> |
function | Decode uncompressed length from header |
crc32c(data: &[u8]) -> u32 |
function | Castagnoli CRC32C checksum |
mask_checksum(crc: u32) -> u32 |
function | Apply Snappy masking to CRC32C |
unmask_checksum(masked: u32) -> u32 |
function | Remove Snappy masking from CRC32C |
masked_crc32c(data: &[u8]) -> u32 |
function | Compute masked CRC32C in one step |
FrameEncoder<W> |
struct | Streaming framing encoder (implements Write) |
FrameDecoder<R> |
struct | Streaming framing decoder (implements Read) |
SnappyError |
enum | Error type for decompression and framing failures |
Feature Flags
This crate has no optional feature flags. All functionality — block format, framing format, CRC32C (with SSE 4.2 hardware acceleration on x86_64) — is enabled by default.
CRC32C
The Snappy framing format requires a masked CRC32C checksum for each chunk. oxiarc-snappy includes a pure-Rust CRC32C implementation (Castagnoli polynomial, slicing-by-4 optimised).
Hardware Acceleration (SSE 4.2 on x86_64)
On x86_64 hosts, the CRC32C path is accelerated at runtime when SSE 4.2 is available:
- Checks
is_x86_feature_detected!("sse4.2")once at startup viaOnceLock. - Fast path uses
_mm_crc32_u64(8 bytes/cycle), with_mm_crc32_u8for trailing 1–7 bytes. - The output is bitwise-identical to the scalar path — no difference in correctness.
- On non-x86_64 platforms (e.g. aarch64/macOS) and on x86_64 without SSE 4.2, the scalar fallback is used transparently.
Part of OxiArc
This crate is part of the OxiArc project — a Pure Rust archive and compression library ecosystem.
Documentation
Full API documentation: https://docs.rs/oxiarc-snappy
License
Apache-2.0