It is asserted buffer is least flate.max_window_len bytes.
It is asserted output has a capacity of at least 8 bytes.
pub fn init(
output: *Writer,
buffer: []u8,
container: flate.Container,
opts: Options,
) Writer.Error!Compress
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),
};
}