Skip to content

Options Reference

This page documents all configuration options available in compressionz. Each codec has its own options struct tailored to its supported features.

All codecs that support compression levels use the same enum:

pub const Level = enum {
fastest, // Maximum speed, lower ratio
fast, // Good speed, good ratio
default, // Balanced (recommended)
better, // Better ratio, slower
best, // Maximum ratio, slowest
};
const fast = try cz.zstd.compress(data, allocator, .{
.level = .fast,
});
const best = try cz.zstd.compress(data, allocator, .{
.level = .best,
});
LevelCompressDecompressRatio
fastest12+ GB/s11+ GB/s99.8%
fast12 GB/s11+ GB/s99.9%
default12 GB/s11+ GB/s99.9%
better5 GB/s11+ GB/s99.9%
best1.3 GB/s12 GB/s99.9%

pub const CompressOptions = struct {
level: Level = .default,
};
pub const DecompressOptions = struct {
max_output_size: ?usize = null,
};
// Compress with dictionary
const compressed = try cz.zstd.compressWithDict(data, dictionary, allocator, .{
.level = .default,
});
// Decompress with dictionary
const decompressed = try cz.zstd.decompressWithDict(compressed, dictionary, allocator, .{
.max_output_size = 100 * 1024 * 1024,
});

pub const CompressOptions = struct {
/// Compression level
level: Level = .default,
/// Include XXH32 checksum of content
content_checksum: bool = true,
/// Include XXH32 checksum per block
block_checksum: bool = false,
/// Include original size in header
content_size: ?usize = null,
/// Maximum block size
block_size: BlockSize = .max64KB,
/// Blocks don't reference previous blocks
independent_blocks: bool = false,
};
pub const BlockSize = enum {
max64KB,
max256KB,
max1MB,
max4MB,
};

content_checksum: When enabled (default), a XXH32 checksum of the original content is appended. This detects corruption but adds slight overhead.

content_size: When provided, the original size is stored in the frame header. This allows the decompressor to allocate the exact buffer size needed.

pub const DecompressOptions = struct {
max_output_size: ?usize = null,
};

LZ4 block format has no compression options:

const compressed = try cz.lz4.block.compress(data, allocator);

For decompression, you must provide the original size:

const decompressed = try cz.lz4.block.decompressWithSize(compressed, original_len, allocator);

Snappy has no options for compression or decompression:

const compressed = try cz.snappy.compress(data, allocator);
const decompressed = try cz.snappy.decompress(compressed, allocator);

For size-limited decompression:

const decompressed = try cz.snappy.decompressWithLimit(compressed, allocator, max_size);

pub const CompressOptions = struct {
level: Level = .default,
};
pub const DecompressOptions = struct {
max_output_size: ?usize = null,
};

pub const CompressOptions = struct {
level: Level = .default,
};
pub const DecompressOptions = struct {
max_output_size: ?usize = null,
};
// Compress with dictionary
const compressed = try cz.zlib.compressWithDict(data, dictionary, allocator, .{});
// Decompress with dictionary
const decompressed = try cz.zlib.decompressWithDict(compressed, dictionary, allocator, .{});

For raw deflate without zlib wrapper:

const compressed = try cz.zlib.compressDeflate(data, allocator, .{});
const decompressed = try cz.zlib.decompressDeflate(compressed, allocator, .{});

pub const CompressOptions = struct {
level: Level = .default,
};

Note: Brotli’s best level is significantly slower than other levels (86 MB/s vs 1.3 GB/s). Only use for static content.

pub const DecompressOptions = struct {
max_output_size: ?usize = null,
};

CodecDefault LevelDefault Checksum
Zstd.defaultYes (built-in)
LZ4 Frame.defaultYes (content)
LZ4 BlockN/ANo
SnappyN/ANo
Gzip.defaultYes (CRC32)
Zlib.defaultYes (Adler-32)
Brotli.defaultNo

Streaming compressors use the same options as one-shot compression:

// Gzip streaming with options
var comp = try cz.gzip.Compressor(@TypeOf(writer)).init(allocator, writer, .{
.level = .best,
});
// LZ4 frame streaming with options
var comp = try cz.lz4.frame.Compressor(@TypeOf(writer)).init(allocator, writer, .{
.level = .fast,
.content_checksum = true,
});
// Zstd streaming with options
var comp = try cz.zstd.Compressor(@TypeOf(writer)).init(allocator, writer, .{
.level = .default,
});

FeatureZstdLZ4 FrameLZ4 BlockSnappyGzipZlibBrotli
LevelsYesYesNoNoYesYesYes
ChecksumBuilt-inOptionalNoNoCRC32Adler-32No
DictionaryYesNoNoNoNoYesNo
Size in headerAutoOptionalNoYesMod 2^32NoNo
Max output sizeYesYesNoYesYesYesYes