Skip to content

Introduction

compressionz is a fast, ergonomic compression library for Zig with codec-specific APIs. Each codec module exposes only the features it supports, providing type-safe, discoverable interfaces for LZ4, Snappy, Zstd, Gzip, Brotli, and more.

MetricValue
LZ4 Compression36 GB/s
Zstd Throughput12 GB/s
Supported Codecs7
System Dependencies0
const cz = @import("compressionz");
// Compress with Zstd
const compressed = try cz.zstd.compress(data, allocator, .{});
defer allocator.free(compressed);
// Decompress
const original = try cz.zstd.decompress(compressed, allocator, .{});
defer allocator.free(original);

Each codec has its own module with tailored APIs. Use cz.zstd, cz.lz4.frame, cz.lz4.block, cz.gzip, cz.snappy, or cz.brotli.

Codec-Specific APIs

Each codec exposes only its supported features. Type-safe, discoverable interfaces with no runtime codec selection overhead.

Blazing Fast

Pure Zig LZ4 and Snappy with SIMD optimizations achieve 36+ GB/s compression throughput.

Zero Dependencies

All C libraries are vendored. No brew install, no apt-get. Works on any platform Zig supports.

Production Ready

Streaming, dictionaries, checksums, decompression bomb protection. Everything you need.

CodecSpeedRatioStreamingImplementation
Zstd12 GB/s99.9%YesVendored C
LZ4 Block36 GB/s99.5%NoPure Zig
LZ4 Frame4.8 GB/s99.3%YesPure Zig
Snappy31 GB/s95.3%NoPure Zig
Gzip2.4 GB/s99.2%YesVendored C
Brotli1.3 GB/s99.9%YesVendored C

Streaming API

Process large files without loading everything into memory. Integrates with Zig’s standard Reader/Writer interfaces.

Dictionary Compression

Dramatically improve ratios for small data with known patterns. Supported by Zstd and Zlib.

Zero-Copy Options

Compress into pre-allocated buffers for zero-allocation hot paths. Perfect for embedded or real-time systems.

Auto-Detection

Automatically detect compression format from magic bytes. Decompress unknown data without guessing.

Archive Support

Read and write ZIP and TAR archives with simple, ergonomic APIs. Extract or create with one function call.

Decompression Bomb Protection

Set maximum output size limits to protect against malicious compressed data.

  • Zig 0.15.0 or later
  • Any platform Zig supports (Linux, macOS, Windows, etc.)
  • No external dependencies