Referencia Zigconduit-zig (SDK consumido)

zig/zstd.zig

Declaraciones públicas de zig/zstd.zig (conduit-zig (SDK consumido)).

ImplementadoSin versión del tren todavía· generada desde apps/docs/generated/zig/conduit.json

Página generada desde conduit@conduit-0.1.0-f7J_7zg5DwCsHBHItwdOz9ZVq8cvH7ceFsk7-m3-T61t (zig/root.zig). No se edita a mano: bun run docs:gen la regenera y bun run docs:check falla si difiere.

Content-Encoding: zstd for wire v2 (spec/wire-v2.md §7), without C and without dependencies, so the same code runs in the CLI, the C-ABI library and WASM:

  • Compressor: an LZ77 encoder (greedy, one hash probe) that writes standard zstd frames (RFC 8878): raw literals, sequences with the predefined FSE tables, RLE and raw blocks. It trades ratio for simplicity and speed; any zstd decoder reads its frames (checked against std.compress.zstd, the zstd CLI and Bun in the tests).
  • decodeFrame: the server's bounded decoder. It checks the frame header against the wire rules before allocating anything (one frame, no skippable frame, no dictionary, window ≤ 8 MiB, content size equal to the range when present), then decodes with std.compress.zstd.Decompress into a buffer of exactly window + 128 KiB and hands the bytes to a sink, which bounds the output. The encoded input is bounded too (max_input, the range length), whether or not the body had a Content-Length. Trailing bytes after the frame are refused.
  • Policy: the client rule (§7): never encode video, audio or data that is already compressed (sniffed from the first bytes), and only encode when a 64 KiB sample shrinks to ≤ 90 %.

zstd.max_window

const · línea 30

pub const max_window: u64 = 8 << 20

Largest window the wire accepts (Window_Size ≤ 8 MiB).

zstd.block_max

const · línea 31

pub const block_max: usize = zstd.block_size_max

Sin ///.

zstd.magic

const · línea 32

pub const magic: u32 = 0xFD2FB528

Sin ///.

zstd.max_header_len

const · línea 35

pub const max_header_len = 18

Longest frame header: magic, descriptor, window, 4-byte dictionary id, 8-byte content size.

zstd.min_input_buffer

const · línea 38

pub const min_input_buffer = 2048

The decoder peeks up to 2048 bytes for an FSE table description, so the reader it reads from (decodeFrame's own, over the body) holds at least this.

zstd.Header

type · línea 42

pub const Header = struct

Sin ///.

zstd.HeaderError

const · línea 48

pub const HeaderError = error{ /// Not a zstd frame, or one the wire forbids (skippable, dictionary, /// window over 8 MiB, reserved bit). BadFrame, /// The header says the frame holds more bytes than …

Sin ///.

zstd.parseHeader

fn · línea 60

pub fn parseHeader(bytes: []const u8, expected: u64) HeaderError!Header

Check a frame header against spec/wire-v2.md §7. expected is the decoded length the request must produce (the range length).

zstd.DecodeError

const · línea 113

pub const DecodeError = error{ BadFrame, /// More decoded bytes than `expected` (or the header said so). TooLarge, /// More encoded bytes than `max_input`: whatever the transport framing /// (a `Trans …

Sin ///.

zstd.Sink

type · línea 129

pub const Sink = struct

Where decoded bytes go. writeFn may refuse (it bounds the output).

zstd.decoderMemory

fn · línea 136

pub fn decoderMemory(w: u64) u64

Bytes a decoder holds for a frame with window w.

zstd.decodeFrame

fn · línea 145

pub fn decodeFrame(gpa: Allocator, in: *Reader, sink: *Sink, expected: u64, max_input: u64) DecodeError!u64

Decode exactly one zstd frame from in into sink. in must hold the encoded body and nothing else (it ends where the body ends); its buffer may be any size. At most max_input encoded bytes are read: one more is InputTooLarge, never decoded past. Returns the decoded length; anything after the frame is BadFrame.

zstd.Compressor

type · línea 409

pub const Compressor = struct

Reusable encoder state (~800 KiB): one per worker.

zstd.Compressor.init

fn · línea 419

pub fn init(gpa: Allocator) Allocator.Error!Compressor

Sin ///.

zstd.Compressor.deinit

fn · línea 432

pub fn deinit(c: *Compressor) void

Sin ///.

zstd.Compressor.compress

fn · línea 445

pub fn compress(c: *Compressor, src: []const u8, dst: []u8) ?usize

Compress src into one zstd frame in dst. Null when the frame does not fit dst (pass dst.len < src.len to get "only if it shrinks"). The frame carries the content size and a window of at most 8 MiB, the limits decodeFrame enforces.

zstd.sample_len

const · línea 652

pub const sample_len = 64 * 1024

Sin ///.

zstd.Sniff

type · línea 655

pub const Sniff = enum

What the first bytes of a file say about its payload.

zstd.sniff

fn · línea 658

pub fn sniff(head: []const u8) Sniff

Video, audio and already-compressed containers by their magic bytes.

zstd.worthEncoding

fn · línea 679

pub fn worthEncoding(c: *Compressor, head: []const u8) bool

Spec §7 client policy on the file's first bytes: encode only payload that is neither media nor compressed and whose first 64 KiB shrink to ≤ 90 %. c is any compressor (it is reset by compress).