This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.
Compress
import std/compressstd/compress - owned gzip encoding: pure Zig, no libc, freestanding-safe.
compress.kz · 2 tors
std/compress - owned gzip encoding: pure Zig, no libc, freestanding-safe.
One-shot gzip for bodies of any size: input chunks at FF_BLOCK_CAP
(65535 bytes — the ff_tok capacity bound) into a multi-block DEFLATE
stream, absolute positions keeping the 32KB match window live across
block boundaries. Dynamic Huffman with a per-worker cached tree reused
while a used-symbol mask stays inside the tree's coverage; fixed
Huffman below 64 bytes where the tree header costs more than it saves.
The trailer folds through PMULL on aarch64-crypto targets, PCLMULQDQ
on x86_64 where CPUID reports it, and a slicing-by-8 table elsewhere.
const n = std_compress.gzipInto(body, out_buf);
if (n == 0) // out buffer too small
Phantom lifecycles
Derived from the phantom labels in the declarations below — state! issues an
obligation the compiler will chase, !state discharges it, a bare state holds it without moving it. Nothing here is hand-drawn.
string carries the label <*> with no obligation attached — a dimension, not a lifecycle.
// Koru-level entry: `~std/compress:gzip(data)` — allocates into the
// program's allocator and returns a shrunk slice. Any input size compresses:
// the stream chunks into as many DEFLATE blocks as it needs.
~pub tor gzip { data: string<*> }
| compressed { data: string, original_size: usize }
| error string// CRC32 of arbitrary bytes — the trailer's checksum exposed as its own
// surface: wire receivers verify gzip streams, tests pin compressed output
// without an inflater, and callers on the buffer API can stamp their own
// trailers. `string<*>` admits borrowed views and obligated buffers alike.
~pub tor crc32 { data: string<*> } -> usize