stdx extends Zig's standard library with compression, checksums, JSON, base 64, regular
expressions and Unicode. It groups its modules as std groups its own, and each is written from
its RFC or from the specification that it names. Nothing in stdx allocates, opens a file, starts a
thread or reads a clock, so it fits the hot path of a server.
Each module's folder holds a README with its examples, its options, its limits and its speed.
| Module | What it holds |
|---|---|
stdx.compress.deflate |
DEFLATE (RFC 1951): an encoder and a decoder |
stdx.compress.zlib |
The zlib container (RFC 1950): HTTP's deflate coding |
stdx.compress.gzip |
The gzip container (RFC 1952): HTTP's gzip coding |
stdx.compress.zstd |
Zstandard (RFC 8878, with RFC 9659's limits for HTTP): HTTP's zstd coding |
stdx.compress.brotli |
brotli (RFC 7932): HTTP's br coding |
stdx.hash |
CRC-32, Adler-32 and XXH64, with SIMD paths that the CPU selects at run time |
stdx.encoding.json |
JSON (RFC 8259) with JSON text sequences (RFC 7464): an encoder and a pull decoder |
stdx.encoding.base64 |
Base 64 (RFC 4648): an encoder and a decoder |
stdx.regex |
Regular expressions in RFC 9485's grammar with RE2's syntax, matched in time linear in the text |
stdx.unicode |
Unicode 17.0.0's categories, scripts and case folding |
stdx.unicode.utf8 |
UTF-8 (RFC 3629), with a validator proved in Lean |
stdx.platform |
What the CPU offers, which a program detects once when it starts |
stdx.crypto |
chapulin's TLS 1.3, JSON Web Signatures, DNSSEC, SCRAM's calls, and its hashes, HMAC and HKDF, for a dependent that passes .crypto = true |
stdx.codec |
The streaming contract that every codec shares |
| Area | What stdx does |
|---|---|
| Memory | No allocator anywhere in src/, tests included. Your program owns each state and buffer, and each codec's state has a comptime size. |
| I/O | None. stdx.platform reads the CPU with instructions and the auxiliary vector, and makes no system call. |
| Streaming | A call takes any amount of input, writes what fits, and says whether it needs more input, more room, or is done. Each decoder is also a std.Io.Reader, and each encoder a std.Io.Writer. |
| Output | An encoder writes the same bytes on every host, in every build mode, and for every split of its input. |
| Threads | No global state: run codecs on as many threads as you like. |
| Safety | Assertions stay on in production. Hostile input returns an error value, and the code cites the RFC section behind each refusal. |
| Testing | Differential checks against zlib, Wuffs, libzstd, Google's brotli, Go's regexp and RE2's own test logs. A fuzzer every night. Lean proofs of the UTF-8 validator, of the state machine that reads JSON numbers, and of a model of the regex matcher. |
Run zig fetch to add stdx to your build.zig.zon:
zig fetch --save git+https://github.com/c4milo/stdx#v0.4.0Then import it in build.zig:
const stdx = b.dependency("stdx", .{ .target = target, .release = true });
exe.root_module.addImport("stdx", stdx.module("stdx"));- Zig compiles only the parts that a program uses.
- stdx builds in Debug or ReleaseSafe only, because its assertions stay on
(decision 17).
.release = trueselects ReleaseSafe, and stdx takes no.optimizeoption. - The package exports
stdxalone. A module's own name, such asstdx.module("gzip"), stops the build: usestdx.compress.gzip.
Call stdx.platform.CpuFeatures.detect() once when the program starts, and pass the result to
each codec and searcher.
/// Decodes the gzip file `body` into `output`, and returns the decoded octets.
fn gunzip(features: stdx.platform.CpuFeatures, body: []const u8, output: []u8) ![]u8 {
var decoder: stdx.compress.gzip.Decoder = undefined; // about 43 KiB
decoder.init(features);
const whole = try decoder.decode_all(body, output);
return output[0..whole.written];
}Each module's README holds its own examples. Every example comes from
tools/consumer/, a program that zig build test builds against this tree and
runs.
The benchmarks compare stdx with other libraries on GitHub's hosted runners. Every library of a
row runs in the same job (decision 20). Each release runs every benchmark
again and draws each chart into the branch charts
(decision 85). A green ▲ or a red ▼ in a chart marks a row 5% or more faster or
slower than at the previous release, where both ran on one CPU model.
Each module's README shows its chart: brotli,
gzip, Zstandard,
json, base64,
hash and regex.
The page of the branch charts lists
the counts of each chart, the losses included, and each release's notes list the rows that
changed. docs/benchmarks.md says how to read the charts and run each
benchmark again.
stdx is before 1.0, and its releases follow SemVer 2.0.0 (decision 65). The latest release is 0.4.0. Open work is in the issues.
zig build test- The differential checks are separate steps, such as
zig build differential-deflate -Doracles. The first build with-Doraclesfetches about 265 MB of other implementations and corpora. docs/design.mdholds the design and the build plan,docs/decisions.mdthe numbered decisions, anddocs/invariants.mdthe invariants.docs/performance.mdanddocs/costs.mdhold the performance method and the measured costs.CONTRIBUTING.mdsummarizes the rules a change keeps, andCLAUDE.mdholds all of them, with every build step.SECURITY.mdsays how to report a vulnerability in private.
stdx is licensed under the Apache License, Version 2.0 (decision 83).