Expand description
§compression-rs
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.
§Requirements
- macOS
- Xcode / Swift toolchain available on
PATH(build.rsrunsswift build)
§Installation
[dependencies]
compression-rs = "0.2"Enable raw compression.h bindings when needed:
[dependencies]
compression-rs = { version = "0.2", features = ["raw-ffi"] }§Covered areas
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.
§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(())
}§API notes
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.
§Examples
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
§License
Licensed under either of:
- MIT license (LICENSE-MIT)
- Apache License, Version 2.0 (LICENSE-APACHE)
Modules§
- raw_ffi
raw-ffi
Structs§
- Access
Control Entry - AeaAuth
Data - AeaContext
- AeaPadding
- Archive
Flags - Archive
Stream - Blob
Description - Byte
Stream - Compression
Stream - Decoder
- Encoder
- Entry
AclBlob - Entry
Attributes - Entry
Message Event - Entry
XatBlob - Field
Key - Field
KeySet - Hash
Value - Header
- Named
Blob Entry - Path
List - Timespec
Enums§
- AceQualifier
Type - AeaChecksum
Mode - AeaCiphersuite
- AeaContext
Field - AeaContext
Field Representation - AeaEncryption
Mode - AeaProfile
- AeaSignature
Mode - Algorithm
- Archive
Compression Algorithm - Compression
Error - Entry
Message - Entry
Message Data - Entry
Type - Field
Type - Hash
Function - Header
Field Value - Stream
Operation
Constants§
Traits§
Functions§
- compress
- compression_
decode_ buffer - compression_
decode_ scratch_ buffer_ size - compression_
encode_ buffer - compression_
encode_ scratch_ buffer_ size - decompress