Skip to main content

Crate omnizip_ffi

Crate omnizip_ffi 

Source
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§

ArchHandle
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 with ozip_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_len bytes) with codec at level. Returns a Rust-allocated buffer and writes its length through out_len, or NULL on error (see ozip_last_error).
ozip_decompress⚠
Decompress input (input_len bytes). expected_len is the exact plaintext size (the codecs verify it); use the value recorded at compress time. Returns a buffer + length via out_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.