Safe Rust bindings for Apple’s Compression and AppleArchive APIs on macOS.
compression-rs 0.2.2 uses a Swift bridge in front of the C-only Apple SDK
surfaces. The default API is safe Rust over opaque Swift-owned handles, while
the original compression.h FFI remains available behind the raw-ffi feature.
- macOS
- Xcode / Swift toolchain available on
PATH(build.rsrunsswift build)
[dependencies]
compression-rs = "0.2"Enable raw compression.h bindings when needed:
[dependencies]
compression-rs = { version = "0.2", features = ["raw-ffi"] }CompressionStreamviaCompressionStream,Encoder, andDecoder- one-shot
CompressionEncode/CompressionDecodehelpers AAByteStreamfile, fd, temp-file, shared-buffer, compression, and random-access APIsAAArchiveStreamencode, decode, extract, convert, header, blob, and message-callback APIsAAEntryACLBlobandAAEntryXATBlobhelper APIs- custom
AACustomByteStreamandAACustomArchiveStreamcallback flows AEAContext,AEAAuthData, andAEAStreamssymmetric archive helpersAAFieldKey/AAFieldKeySetAAHeader- requested
AAEntryStreamcoverage, mapped toPathList,EntryMessage, andEntryAttributes
See COVERAGE.md for the requested-area mapping and COVERAGE_AUDIT.md for the full audited SDK surface.
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(())
}Algorithm::ALLcontains the stream-capable algorithms.Algorithm::BUFFER_ALLadditionally includes buffer-only algorithms such asLz4RawandLzbitmap.compress/decompressuse stream APIs when available and automatically fall back to repeated one-shot buffer calls for buffer-only algorithms.raw-fficurrently preserves the directcompression.hsurface. AppleArchive stays behind the Swift bridge.- AppleArchive does not define a concrete
AAEntryStreamtype; this crate uses the entry-levelAAPathList,AAEntryMessage, andAAEntryAttributesAPIs to cover that requested area. - Deprecated AppleArchive
*Abort*compatibility shims remain available as deprecated Rust aliases for audited SDK parity; prefer thecancelAPIs in new code.
cargo run --example 01_roundtrip
cargo run --example 04_aa_archive_stream_roundtrip
cargo run --example 05_aa_byte_stream_pipeline
cargo run --example 09_aa_entry_blobs
cargo run --example 10_aea_roundtrip
cargo run --example 11_aa_custom_stream_callbacksThis release also includes examples and tests for all requested logical areas:
01_roundtrip02_compression_encode_one_shot03_compression_decode_one_shot04_aa_archive_stream_roundtrip05_aa_byte_stream_pipeline06_aa_entry_stream_path_list07_aa_field_key_set08_aa_header_roundtrip09_aa_entry_blobs10_aea_roundtrip11_aa_custom_stream_callbacks
Licensed under either of:
- MIT license (LICENSE-MIT)
- Apache License, Version 2.0 (LICENSE-APACHE)