Skip to content

Examples ​

Ten runnable programs live in the examples directory of the repository. Each is a complete Zig program with a main function, and each is compiled by zig build check.

bash
zig build run-basic_compression

Run every one:

bash
zig build run-all-examples

The programs ​

Each example covers one thing. None repeats another's demonstration.

ExampleWhat it covers
basic_compressionOne-shot round trip with verification and header introspection
compression_levelsAll nine levels side by side with ratios and timings
reusable_contextsOne Compressor and one Decoder, many streams
caller_buffersCaller-provided output buffers, sizing and retry on overflow
chunked_inputIrregular write sizes producing a byte-identical stream
streaming_pipelinescompressStream and decompressStream as bounded pipelines
file_compressionFile to file with staging, plus the damaged-stream failure path
large_fileA 16 MiB round trip in constant memory, hash-verified
decoder_semanticsStatistics, CRC verification, corruption taxonomy, concatenation
custom_allocatorA counting custom allocator proving the byte balance

Run one by prefixing its name with run-:

bash
zig build run-compression_levels
zig build run-large_file

The examples that write files put them in a directory under the system temporary area they create themselves and remove again at the end, so a run leaves the working directory as it found it.

Output ​

The examples write to standard error through std.debug.print, which keeps them usable in a pipeline where standard output might be redirected.

Source layout ​

Tests live at the bottom of the module they cover, so a behaviour described in the documentation can be read next to the code that implements it and the tests that pin it down. The examples are the executable half of the same idea: each one is short enough to read in full and produces output you can check against the claim in its name.

Released under the MIT License.