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 - Wraps the raw
compression.hand AppleArchive FFI surface.
Structs§
- Access
Control Entry - Wraps an ACL entry used by
AAEntryACLBlob. - AeaAuth
Data - Wraps an
AEAAuthDatahandle. - AeaContext
- Wraps an
AEAContexthandle. - AeaPadding
- Wraps AEA padding constants.
- Archive
Flags - Wraps AppleArchive archive-processing flags.
- Archive
Stream - Wraps an
AAArchiveStreamhandle. - Blob
Description - Wraps blob descriptors returned by
AAHeaderGetFieldBlob. - Byte
Stream - Wraps an
AAByteStreamhandle. - Compression
Stream - Wraps a
compression_streamhandle. - Decoder
- Wraps
compression_stream_processfor decoding. - Encoder
- Wraps
compression_stream_processfor encoding. - Entry
AclBlob - Wraps an
AAEntryACLBlobhandle. - Entry
Attributes - Wraps AppleArchive entry attribute values.
- Entry
Message Event - Wraps
AAEntryMessageProcevent data. - Entry
XatBlob - Wraps an
AAEntryXATBlobhandle. - Field
Key - Wraps an
AAFieldKeyvalue. - Field
KeySet - Wraps an
AAFieldKeySethandle. - Hash
Value - Wraps hash values returned by
AAHeaderGetFieldHash. - Header
- Wraps an
AAHeaderhandle. - Named
Blob Entry - Wraps a named blob entry used by
AAEntryXATBlobandAEAAuthData. - Path
List - Wraps an
AAPathListhandle. - Timespec
- Wraps
timespecvalues stored inAAHeaderfields.
Enums§
- AceQualifier
Type - Wraps AppleArchive ACL qualifier type identifiers.
- AeaChecksum
Mode - Wraps AEA checksum mode identifiers.
- AeaCiphersuite
- Wraps AEA ciphersuite identifiers.
- AeaContext
Field - Wraps AEA context field identifiers.
- AeaContext
Field Representation - Wraps AEA context field representation identifiers.
- AeaEncryption
Mode - Wraps AEA encryption mode identifiers.
- AeaProfile
- Wraps AEA profile identifiers.
- AeaSignature
Mode - Wraps AEA signature mode identifiers.
- Algorithm
- Wraps
compression_algorithmvalues fromcompression.h. - Archive
Compression Algorithm - Wraps AppleArchive compression algorithm identifiers.
- Compression
Error - Wraps failures returned by Compression and AppleArchive helpers.
- Entry
Message - Wraps AppleArchive entry message identifiers.
- Entry
Message Data - Wraps payloads delivered through
AAEntryMessageProc. - Entry
Type - Wraps AppleArchive entry type identifiers.
- Field
Type - Wraps AppleArchive header field type identifiers.
- Hash
Function - Wraps AppleArchive hash function identifiers.
- Header
Field Value - Wraps typed
AAHeaderfield values. - Stream
Operation - Wraps
compression_stream_operationvalues.
Constants§
- DEFAULT_
FILE_ MODE - Wraps
DEFAULT_FILE_MODE. - OPEN_
CREATE - Wraps
OPEN_CREATE. - OPEN_
READ_ ONLY - Wraps
OPEN_READ_ONLY. - OPEN_
READ_ WRITE - Wraps
OPEN_READ_WRITE. - OPEN_
TRUNCATE - Wraps
OPEN_TRUNCATE. - OPEN_
WRITE_ ONLY - Wraps
OPEN_WRITE_ONLY.
Traits§
- Custom
Archive Stream Callbacks - Wraps callbacks installed by
AACustomArchiveStreamSet*Proc. - Custom
Byte Stream Callbacks - Wraps callbacks installed by
AACustomByteStreamSet*Proc. - Entry
Message Handler - Wraps handlers installed through
AAEntryMessageProc.
Functions§
- compress
- Wraps
compression_encode_buffer. - compression_
decode_ buffer - Wraps
compression_decode_buffer. - compression_
decode_ scratch_ buffer_ size - Wraps
compression_decode_buffer. - compression_
encode_ buffer - Wraps
compression_encode_buffer. - compression_
encode_ scratch_ buffer_ size - Wraps
compression_encode_buffer. - decompress
- Wraps
compression_decode_buffer.
Type Aliases§
- AceFlag
Set - Wraps the AppleArchive ACL flag bitset type.
- AcePerm
Set - Wraps the AppleArchive ACL permission bitset type.
- AceTag
- Wraps the AppleArchive ACL tag field type.
- Result
- Wraps crate results returned by Compression and AppleArchive helpers.