fn outputBytes(h: *Huffman, bytes: []const u8, eos: bool) Writer.Error!void h: *Huffmanbytes: []const u8eos: bool2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392 fn outputBytes(h: *Huffman, bytes: []const u8, eos: bool) Writer.Error!void {
comptime assert(max_tokens != 65535);
assert(bytes.len <= max_tokens);
var freqs: [257]u16 = @splat(0);
freqs[256] = 1;
for (bytes) |b| freqs[b] += 1;
h.hasher.update(bytes);
var codes_buf: CodesBuf = .init;
if (try h.outputHeader(&freqs, &codes_buf, @intCast(bytes.len), eos)) |table| {
for (bytes) |b| {
try h.bit_writer.write(table.codes[b], table.bits[b]);
}
try h.bit_writer.write(table.codes[256], table.bits[256]);
} else {
try h.bit_writer.output.writeAll(bytes);
}
}