compress/zstd
lib/compress/zstd.vklib/compress/zstd.vk
Pure-Veko RFC 8878 Zstandard (.zst) frame encoder and decoder.
Emits wire-compliant RFC 8878 Zstandard frames (0xFD2FB528 magic, Single-Segment FCS header,
adaptive RLE_Block run compression + Raw_Block framing) and decodes RFC 8878 frames
including skippable frames, window/dictionary descriptors, and Raw/RLE/literal-compressed blocks.
Zero capabilities required; works identically on VM, Wasm 3.0, and Native.
zstd-frame? = fn [data bytes] bool
Returns true if data starts with the 4-byte RFC 8878 Zstandard frame magic 28 B5 2F FD.
compress = fn [data bytes] bytes
Compresses data into a wire-compliant RFC 8878 Zstandard frame.
Executable Example
use [zstd = compress/zstd]
mut msg = bytes/with-cap 256
_ = bytes/push-all mut msg (bytes/from-str 'Veko Zstd Frame Header: ')
mut i = 0
while i < 64 [
_ = bytes/push mut msg 65
i = i + 1
]
_ = bytes/push-all mut msg (bytes/from-str ' -- tail payload!')
z = zstd/compress msg
if (not (zstd/zstd-frame? z)) or (zstd/decompress z) != msg [ err 'zstd roundtrip' ] else [ .ok ]
decompress = fn [zbytes bytes] bytes
Decompresses one or more concatenated RFC 8878 Zstandard frames (ignoring skippable frames).