Calls zlib through libflare_zlib.so, a thin C wrapper built automatically
on pixi install / environment activation via flare/http/ffi/build.sh.
Why a C wrapper instead of calling zlib directly?
The C wrapper exposes a single-call (const void*, int, void*, int, int) -> int
API so Mojo never needs to re-read z_stream fields after a foreign call — Mojo's
JIT can serve stale stack-slot values for memory modified by external calls,
returning incorrect byte counts.
Why helper functions with borrowed lib?
Mojo's ASAP (As Soon As Possible) destruction policy destroys an OwnedDLHandle
immediately after its last Mojo-visible use, which is the get_function call
that retrieves the function pointer. ASAP then calls dlclose and unmaps the
library before the pointer is actually invoked, crashing the JIT on both macOS
ARM64 and Linux.
The fix: each public entry point opens lib, then delegates to a private helper
that accepts lib as a read (borrowed) parameter. A borrow cannot be
ASAP-destroyed — it stays alive for the helper's entire execution, including every
C call inside it.
Public API surface:
decompress_gzip(data) → List[UInt8]
decompress_deflate(data) → List[UInt8]
compress_gzip(data, level=6) → List[UInt8]
decode_content(data, encoding) → List[UInt8]