Skip to content

CompressionOptions

Options for zstd.compressWithOptions and StreamingCompressor.initWithOptions. Defined in src/compress/compress.zig:8 and re-exported as zstd.CompressionOptions (src/zstd.zig:21).

Definition

zig
pub const CompressionOptions = struct {
    level: i32 = 3,
    window_log: u8 = 0,
    hash_log: u8 = 0,
    chain_log: u8 = 0,
    search_log: u8 = 0,
    min_match: u8 = 0,
    target_length: u32 = 0,
    strategy: Strategy = .fast,
    checksum: bool = false,
    dict_id: u32 = 0,
    content_size: ?u64 = null,
    enable_ldm: bool = false,
};

pub const Strategy = enum(u8) {
    fast = 1, dfast = 2, greedy = 3, lazy = 4, lazy2 = 5, btlazy2 = 6, btopt = 7, btultra = 8, btultra2 = 9,
};

Fields

FieldTypeDefaultDescription
leveli323Compression level (-131072..22; defaultCLevel()=3). Used by getCompressionParameters to derive other params
window_logu80Window log override (0 = auto, otherwise 10..31)
hash_logu80Hash table log size override
chain_logu80Chain log size override
search_logu80Search log size override
min_matchu80Minimum match length (3..7)
target_lengthu320Target length (0..131072)
strategyStrategy.fastCompression strategy
checksumboolfalseEnable XXH64 frame checksum (checksum_flag in header)
dict_idu320Dictionary ID written to frame header
content_size?u64nullPledged source size (null = auto from src.len)
enable_ldmboolfalseEnable long distance matching (reserved)

Usage

zig
const zstd = @import("zstd");

// Default options via compress()
const c1 = try zstd.compress(allocator, data);

// With explicit level
const c2 = try zstd.compressWithLevel(allocator, data, 9);

// With CompressionOptions
const c3 = try zstd.compressWithOptions(allocator, data, .{
    .level = 9,
    .checksum = true,
});

// All options + strategy
const c4 = try zstd.compressWithOptions(allocator, data, .{
    .level = 12,
    .window_log = 22,
    .hash_log = 18,
    .chain_log = 18,
    .search_log = 6,
    .min_match = 4,
    .target_length = 32,
    .strategy = .btopt,
    .checksum = true,
    .dict_id = 42,
    .content_size = @as(?u64, data.len),
    .enable_ldm = false,
});

// Derive tuned options then tweak
var tuned = zstd.getCompressionParameters(12, data.len, 20);
tuned.checksum = true;
const c5 = try zstd.compressWithOptions(allocator, data, tuned);

Removed names: old CompressOptions { level: CLevel = .default, checksum, dict_id, use_dict_id, strategy: ?Strategy, window_log: ?u32 } no longer exists. Use the struct above with i32 level and u8 logs.

Released under the MIT License.