Expand description
omnizip-ffi — the C ABI over the omnizip codecs: the Rust side of the Ruby gem’s Rust-accelerated path.
The surface is deliberately tiny and stable: three codecs
(zstd, bzip2, lzma/xz), explicit lengths, one call each way, a
thread-local last-error, and one deallocator. Ruby binds it with
stdlib Fiddle — no compiled extension, no rake-compiler:
require 'fiddle'
lib = Fiddle.dlopen('libomnizip_ffi.dylib')
compress = Fiddle::Function.new(lib['ozip_compress'],
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_SIZE_T,
Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOIDP)§Safety model
Every entry point is pub extern "C" with a documented SAFETY
contract; panics never cross the boundary (catch_unwind at
every entry); errors surface as NULL returns plus
ozip_last_error. Buffer ownership is explicit: returned
buffers are Rust-allocated and MUST be freed by ozip_free —
nothing else may touch them.
§Determinism
The codecs’ contracts carry through: same input + level ⇒ same bytes, on every machine — the tier swap in the gem cannot disturb downstream content addressing.
Structs§
- Arch
Handle - An opened archive: one
ArchiveReader(any supported format, auto-detected) plus its materialized entry list. Opaque handle for the archive-level FFI surface — the gem’s whole-archive operations (list entries, read entry) ride this instead of decoding entry-by-entry through codec names.
Functions§
- ozip_
arch_ ⚠close - Close an archive handle (freeing it). NULL is a no-op.
- ozip_
arch_ ⚠count - Number of entries in the opened archive. 0 on NULL handle.
- ozip_
arch_ ⚠entry_ name - Entry name (NUL-terminated, valid until the next call on this handle). NULL on out-of-range index.
- ozip_
arch_ ⚠entry_ size - Entry uncompressed size (u64). 0 on out-of-range.
- ozip_
arch_ ⚠open - Open an archive from raw bytes (format auto-detected; optional
NUL-terminated password). Returns NULL on error
(
ozip_last_error). Free withozip_arch_close. - ozip_
arch_ ⚠read_ entry - Read one entry’s uncompressed bytes; free the buffer with
ozip_free. NULL on error. - ozip_
compress ⚠ - Compress
input(input_lenbytes) withcodecatlevel. Returns a Rust-allocated buffer and writes its length throughout_len, or NULL on error (seeozip_last_error). - ozip_
decompress ⚠ - Decompress
input(input_lenbytes).expected_lenis the exact plaintext size (the codecs verify it); use the value recorded at compress time. Returns a buffer + length viaout_len, or NULL on error. - ozip_
free ⚠ - Free a buffer returned by
ozip_compress/ozip_decompress. - ozip_
last_ error - The error from the most recent FFI call on this thread, as a NUL-terminated C string valid until the next call. Never NULL.
- ozip_
version - The library’s semver (
env!("CARGO_PKG_VERSION")) as a NUL-terminated C string. Static for the process lifetime — the gem’s platform-gem smoke gate asserts the vendored dylib matches the gem’s expected Rust release.