Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

init

It is asserted buffer is least flate.max_window_len bytes. It is asserted output has a capacity of at least 8 bytes.

Compress.init
pub fn init(
    output: *Writer,
    buffer: []u8,
    container: flate.Container,
    opts: Options,
) Writer.Error!Compress

File

lib/std/compress/flate/Compress.zig:303

Code

pub fn init(
    output: *Writer,
    buffer: []u8,
    container: flate.Container,
    opts: Options,
) Writer.Error!Compress {
    assert(output.buffer.len > 8);
    assert(buffer.len >= flate.max_window_len);

    // note that disallowing some of these simplifies matching logic
    assert(opts.chain != 0); // use `Huffman`; disallowing this simplies matching
    assert(opts.good >= 3 and opts.nice >= 3); // a match will (usually) not be found
    assert(opts.good <= 258 and opts.nice <= 258); // a longer match will not be found
    assert(opts.lazy <= opts.nice); // a longer match will (usually) not be found
    if (opts.good <= opts.lazy) assert(opts.chain >= 1 << 2); // chain can be reduced to zero

    try output.writeAll(container.header());
    return .{
        .writer = .{
            .buffer = buffer,
            .vtable = &.{
                .drain = drain,
                .flush = flush,
                .rebase = rebase,
            },
        },
        .history_len = 0,
        .history_end_unhashed = false,
        .bit_writer = .init(output),
        .buffered_tokens = .empty,
        .lookup = .{
            // init `value` is max so there is 0xff pattern
            .head = @splat(.{ .value = math.maxInt(u15), .is_null = true }),
            .chain = undefined,
            .chain_pos = math.maxInt(u15),
        },
        .container = container,
        .opts = opts,
        .hasher = .init(container),
    };
}