Expand description
§compression-rs
Safe Rust bindings for Apple’s libcompression APIs on macOS.
compression-rs covers the core pieces you typically need first:
- one-shot
compression_encode_buffer/compression_decode_buffer - streaming
Encoder/Decoderwrappers built oncompression_stream_* - algorithms:
LZ4,LZFSE,LZMA,zlib, andBrotli - ergonomic
compress/decompresshelpers that grow output buffers for you
§Status
Initial 0.1.0 coverage focuses on the public compression.h surface that is
useful for in-memory tools and streaming pipelines.
§Installation
[dependencies]
compression-rs = "0.1"§Quick start
use compression::{compress, decompress, Algorithm};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let input = b"doom fish doom fish doom fish";
let compressed = compress(input, Algorithm::Lzfse)?;
let round_trip = decompress(&compressed, Algorithm::Lzfse)?;
assert_eq!(round_trip, input);
Ok(())
}§Highlights
- Direct wrappers for
compression_encode_bufferandcompression_decode_buffer - Safe
Encoder/Decoderstreaming types for chunked workloads - No Swift bridge required — this crate is pure Rust + C FFI
examples/01_roundtrip.rssmoke test for a 64 KiB LZFSE round-trip
§API notes
compression_encode_bufferandcompression_decode_bufferexpect the caller to provide the destination buffer and return the number of bytes written.compressanddecompressbuild on the streaming APIs so they can resize output buffers automatically.Algorithm::Brotlirequires a macOS version that ships Brotli support inlibcompression.
§Smoke example
cargo run --example 01_roundtripExpected tail output:
✅ compression round-trip OK§License
Licensed under either of:
- MIT license (LICENSE-MIT)
- Apache License, Version 2.0 (LICENSE-APACHE)
Structs§
Enums§
Functions§
- compress
- compression_
decode_ buffer - compression_
decode_ scratch_ buffer_ size - compression_
encode_ buffer - compression_
encode_ scratch_ buffer_ size - decompress