Skip to content

CompressionOptions

Options for brotli.compressWithOptions, Encoder and StreamingCompressor. Defined in src/compress/encode.zig and re-exported as brotli.CompressionOptions.

Definition

zig
pub const Options = struct {
    quality: u32 = 11,
    lgwin: u32 = 22,
    mode: Mode = .generic,
    lgblock: u32 = 0,
    disable_literal_context_modeling: bool = false,
    size_hint: usize = 0,
    large_window: bool = false,
    npostfix: u32 = 0,
    ndirect: u32 = 0,
    progress: ?ProgressCallback = null,
    progress_ctx: ?*anyopaque = null,
};

Fields

FieldTypeDefaultDescription
qualityu3211Quality level 0..11; higher = better ratio, slower
lgwinu3222Window bits 10..24 (clamped); bounds match distance
modeMode.generic.generic, .text, or .font analysis hint
lgblocku320Block-size hint (accepted for API parity)
disable_literal_context_modelingboolfalseAccepted for API parity; encoder uses a fixed context layout
size_hintusize0Expected total input size; improves progress reporting
large_windowboolfalseAccept LGWIN values up to 30 for interoperability
npostfix / ndirectu320Distance parameterization (accepted for API parity)
progress?ProgressCallbacknullCalled with (ctx, bytes_done, bytes_total) during streaming
progress_ctx?*anyopaquenullUser pointer passed to the callback

Usage

zig
const compressed = try brotli.compressWithOptions(allocator, data, .{
    .quality = 9,
    .lgwin = 22,
    .mode = .text,
    .size_hint = data.len,
});

Progress Callbacks

zig
const Ctx = struct { total: usize = 0 };
fn onProgress(ctx: ?*anyopaque, done: usize, total: usize) void {
    const c: *Ctx = @ptrCast(@alignCast(ctx.?));
    c.total = done;
}

var opts = brotli.CompressionOptions{ .quality = 9, .size_hint = file_size };
opts.progress = onProgress;
opts.progress_ctx = &ctx;

Parameter Identifiers

For Encoder.setParameter(id, value) — mirrors the C enumeration:

ConstantValueControls
PARAM_MODE0mode
PARAM_QUALITY1quality
PARAM_LGWIN2lgwin
PARAM_LGBLOCK3lgblock
PARAM_DISABLE_LITERAL_CONTEXT_MODELING4context modeling flag
PARAM_SIZE_HINT5size_hint
PARAM_LARGE_WINDOW6large_window
PARAM_NPOSTFIX7npostfix
PARAM_NDIRECT8ndirect

Released under the MIT License.