Skip to content

Introduction

compressionz is a fast, ergonomic compression library for Zig with a unified API across multiple codecs. One interface 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 any codec
const compressed = try cz.compress(.zstd, data, allocator);
defer allocator.free(compressed);
// Decompress
const original = try cz.decompress(.zstd, compressed, allocator);
defer allocator.free(original);

Same API for all codecs. Just change .zstd to .lz4, .gzip, .snappy, or .brotli.

Unified API

One interface for all compression algorithms. Learn once, use any codec. Switch codecs with a single line change.

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 Raw36 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, Zlib, and Deflate.

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