SyncValsverifier → artifact → classifier → verdict
SyncVals · Trajectory

klauspost-compress-1115

codex gpt-5.5 ✓ resolved GOOD_SUCCESS ↑ View task
Solved from the instruction alone, tests/ and solution/ were withheld from the agent's workspace and restored only for grading.
Reward = tests/test.sh exit code (0 → resolved); the classification below is post-hoc and cannot change it.
Classification , post-hoc; cannot change the reward
GOOD_SUCCESSLegitimate solve, implements the asked-for behavior; tests verify real functionality.
SubtypeLegitimate Solution
EvidenceAll 5 verification tests passed: test_package_builds, test_flate_streams_roundtrip (core requirement), test_held_back_actually_ran, test_existing_flate_package_tests_pass (backward compatibility), and test_no_hardcoded_hidden_literals (anti-cheat check). Result: reward=1.0. The roundtrip test specifically verifies the bug is fixed, corrupted streams cannot be decompressed successfully.
Root causeThe agent successfully debugged the DEFLATE compressor's block construction and Huffman model selection in the Go flate package, identified the root cause of the corrupt output generation for large highly compressible inputs, and implemented a focused fix that makes the generated byte stream valid while preserving backward compatibility and the public API.
RecommendationN/A - task is fine
Trajectory
Tool-by-tool agent trajectory
59 tool calls · 3 tool types · 79 steps
<permissions instructions> Filesystem sandboxing defines which files can be read or written. `sandbox_mode` is `danger-full-access`: No filesystem sandboxing - all commands are permitted. Network access is enabled. Approval policy is currently never. Do not provide the `sandbox_permissions` for any reason, commands will be rejected. </permissions instructions><apps_instructions> ## Apps (Connectors) Apps (Connectors) can be explicitly triggered in user messages in the format `[$app-name](app://{connector_id})`. Apps can also be implicitly triggered as long as the context suggests usage of available apps. An app is equivalent to a set of MCP tools within the `codex_apps` MCP. An installed app's MCP tools are either provided to you already, or can be lazy-loaded through the `tool_search` tool. If `tool_search` is available, the apps that are searchable by `tools_search` will be listed by it. Do not additionally call list_mcp_resources or list_mcp_resource_templates for apps. </apps_instructions><skills_instructions> ## Skills A skill is a set of instructions provided through a `SKILL.md` source. Below is the list of skills that can be used. Each entry includes a name, description, and source locator. `file` locators are on the host filesystem, `environment resource` locators are owned by an execution environment, `orchestrator resource` locators are opaque non-filesystem resources, and `custom resource` locators use their provider's access mechanism. ### Available skills - imagegen: Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extending an established icon or logo system, or building the visual directly in HTML/CSS/canvas. (file: /tmp/codex-home/skills/.system/imagegen/SKILL.md) - openai-docs: Use when the user asks how to build with OpenAI products or APIs, asks about Codex itself or choosing Codex surfaces, needs up-to-date official documentation with citations, help choosing the latest model for a use case, or model upgrade and prompt-upgrade guidance; use OpenAI docs MCP tools for non-Codex docs questions, use the Codex manual helper first for broad Codex self-knowledge, and restrict fallback browsing to official OpenAI domains. (file: /tmp/codex-home/skills/.system/openai-docs/SKILL.md) - plugin-creator: Create and scaffold plugin directories for Codex with a required `.codex-plugin/plugin.json`, optional plugin folders/files, valid manifest defaults, and personal-marketplace entries by default. Use when Codex needs to create a new personal plugin, add optional plugin structure, generate or update marketplace entries for plugin ordering and availability metadata, or update an existing local plugin during development with the CLI-driven cachebuster and reinstall flow. (file: /tmp/codex-home/skills/.system/plugin-creator/SKILL.md) - skill-creator: Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Codex's capabilities with specialized knowledge, workflows, or tool integrations. (file: /tmp/codex-home/skills/.system/skill-creator/SKILL.md) - skill-installer: Install Codex skills into $CODEX_HOME/skills from a curated list or a [code-host] repo path. Use when a user asks to list installable skills, install a curated skill, or install a skill from another repo (including private repos). (file: /tmp/codex-home/skills/.system/skill-installer/SKILL.md) ### How to use skills - Discovery: The list above is the skills available in this session (name + description + source locator). `file` entries live on the host filesystem, `environment resource` entries are owned by their execution environment, `orchestrator resource` entries must be accessed through `skills.list` and `skills.read`, and `custom resource` entries use their provider's access mechanism. - Trigger rules: If the user names a skill (with `$SkillName` or plain text) OR the task clearly matches a skill's description shown above, you must use that skill for that turn. Multiple mentions mean use them all. Do not carry skills across turns unless re-mentioned. - Missing/blocked: If a named skill isn't in the list or its source can't be read, say so briefly and continue with the best fallback. - How to use a skill (progressive disclosure): 1) After deciding to use a skill, the main agent must read its `SKILL.md` completely before taking task actions. For a `file` entry, open the listed path. For an `environment resource`, use the filesystem of the owning environment. For an `orchestrator resource`, call `skills.list` with `{"authority":{"kind":"orchestrator"}}`, select the matching package, and pass its `main_resource` to `skills.read`. If a read is truncated or paginated, continue until EOF. 2) When `SKILL.md` references another resource, use the same access mechanism. Resolve relative paths against a filesystem-backed skill directory. For orchestrator skills, pass the exact referenced resource identifier with the same authority and package to `skills.read`; do not treat `skill://` identifiers as filesystem paths. 3) If `SKILL.md` points to extra folders such as `references/`, use its routing instructions to identify the resources required for the task. The main agent must read each required instruction or reference file itself before acting on it. Do not delegate reading, summarizing, or interpreting skill instructions to a subagent. Subagents may still perform task work when the selected skill allows it. 4) For filesystem-backed skills, prefer running or patching provided scripts instead of retyping large code blocks. For orchestrator skills, use `skills.read` and the available tools; do not invent a local path. 5) Reuse provided assets or templates through the same source access mechanism instead of recreating them. - Coordination and sequencing: - If multiple skills apply, choose the minimal set that covers the request and state the order you'll use them. - Announce which skill(s) you're using and why (one short line). If you skip an obvious skill, say why. - Context hygiene: - Progressive disclosure applies to selecting relevant files, not partially reading a selected instruction file. Do not load unrelated references, scripts, or assets. - Avoid deep reference-chasing: prefer opening only files directly linked from `SKILL.md` unless you're blocked. - When variants exist (frameworks, providers, domains), pick only the relevant reference file(s) and note that choice. - Safety and fallback: If a skill can't be applied cleanly (missing files, unclear instructions), state the issue, pick the next-best approach, and continue. </skills_instructions>
<environment_context> <cwd>/app</cwd> <shell>bash</shell> <current_date>2026-06-21</current_date> <timezone>Etc/UTC</timezone> <filesystem><workspace_roots><root>/app</root></workspace_roots><permission_profile type="disabled"><file_system type="unrestricted" /></permission_profile></filesystem> </environment_context>
The Go module in /app implements DEFLATE compression and decompression. Streams written with flate.NewWriter must be readable by the Go standard library DEFLATE reader, this module's reader, and ordinary tools that enforce the block format. Large highly compressible inputs can produce corrupt output after a writer accepts data and closes successfully. The issue is visible across one-shot and chunked writes and across compression levels, including the strongest levels, default compression, Huffman-only mode, and fast or uncompressed modes that should keep existing behavior. The most reliable failures come from large low-entropy data on the high compression path, especially when the writer finishes blocks around internal block boundaries. Treat the decompressor error as a symptom of an invalid stream emitted by the compressor, not as a reader problem. The issue can be reproduced with generated low-entropy inputs in one-shot and chunked writes; do not spend time creating, downloading, or repairing external corpus files. Debug the compressor's block construction and Huffman model selection. Start in /app/flate/deflate.go, where the high compression path assembles blocks inside deflateLazy. The representation chosen for a block must be derived from the bytes that the block actually encodes. Decisions computed from a broader or later region of the window can make a long repetitive stream internally inconsistent even though the writer accepts the input and only fails when another reader checks the emitted format. The underlying change needed is small. After the failure reproduces, prefer applying and verifying a focused fix early over extended reading of the package. Fix the compressor so every completed stream round-trips exactly for low, medium, and high entropy inputs across supported compression levels and chunked or single-write callers. A valid fix must make the generated byte stream valid, not relax readers, ignore decompression errors, special-case fixed inputs, or hide bit-writing failures after an invalid block has already been emitted. Keep the public API unchanged and preserve valid output for inputs that already worked. Existing deterministic compression and golden regression cases must remain byte-for-byte stable; do not replace a high-compression result with a different stream that merely decompresses successfully. Build the module with go build ./... after your change. This task image includes the flate-local regression data but not the upstream parent ../testdata text corpora used by some broad package tests; do not recreate those files or treat their absence as the compressor bug. Use focused round-trip repro cases and the available flate-local regression tests to verify the change.
I’ll reproduce this with generated inputs first, then patch the high-compression block selection path in `deflateLazy` and run focused regression checks plus `go build ./...`.
shell
pwd && rg -n "func \(d \*compressor\) deflateLazy|deflateLazy|chooseBlock|dynamic|stored|fixed|tokens" flate/deflate.go flate -S
output
Chunk ID: a4b83f
Wall time: 0.0001 seconds
Process exited with code 0
Original token count: 13184
Output:
Total output lines: 288

/app
flate/deflate.go:43:	// The maximum number of tokens we will encode at the time.
flate/deflate.go:119:	blockStart int // window index where current tokens start
flate/deflate.go:122:	// queued output tokens
flate/deflate.go:123:	tokens tokens
flate/deflate.go:172:func (d *compressor) writeBlock(tok *tokens, index int, eof bool) error {
flate/deflate.go:186:// writeBlockSkip writes the current block and uses the number of tokens
flate/deflate.go:187:// to determine if the block should be stored on no matches, or
flate/deflate.go:189:func (d *compressor) writeBlockSkip(tok *tokens, index int, eof bool) error {
flate/deflate.go:198:				// Write a dynamic huffman block.
flate/deflate.go:224:		d.fast.Encode(&d.tokens, b)
flate/deflate.go:225:		d.tokens.Reset()
flate/deflate.go:406:// deflateLazy is the same as deflate, but with d.fastSkipHashing == skipNever,
flate/deflate.go:408:func (d *compressor) deflateLazy() {
flate/deflate.go:448:					d.tokens.AddLiteral(d.window[s.index-1])
flate/deflate.go:451:				if d.tokens.n > 0 {
flate/deflate.go:452:					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:455:					d.tokens.Reset()
flate/deflate.go:508:									// Emit tokens we "owe"
flate/deflate.go:510:										d.tokens.AddLiteral(d.window[prevIndex+j])
flate/deflate.go:511:										if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:513:											if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:516:											d.tokens.Reset()
flate/deflate.go:549:											// Emit tokens we "owe"
flate/deflate.go:551:												d.tokens.AddLiteral(d.window[prevIndex+j])
flate/deflate.go:552:												if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:554:													if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:557:													d.tokens.Reset()
flate/deflate.go:581:			d.tokens.AddMatch(uint32(prevLength-3), uint32(prevOffset-minOffsetSize))
flate/deflate.go:612:			if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:614:				if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:617:				d.tokens.Reset()
flate/deflate.go:628:				d.tokens.AddLiteral(d.window[s.index-1])
flate/deflate.go:629:				if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:630:					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:633:					d.tokens.Reset()
flate/deflate.go:645:						d.tokens.AddLiteral(d.window[s.index-1])
flate/deflate.go:646:						if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:647:							if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:650:							d.tokens.Reset()
flate/deflate.go:663:					d.tokens.AddLiteral(d.window[s.index-1])
flate/deflate.go:666:					if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:667:						if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:670:						d.tokens.Reset()
flate/deflate.go:728:			d.tokens.Reset()
flate/deflate.go:735:	d.fast.Encode(&d.tokens, d.window[:d.windowEnd])
flate/deflate.go:737:	if d.tokens.n == 0 {
flate/deflate.go:740:	} else if int(d.tokens.n) > d.windowEnd-(d.windowEnd>>4) {
flate/deflate.go:744:		d.w.writeBlockDynamic(&d.tokens, false, d.window[:d.windowEnd], d.sync)
flate/deflate.go:747:	d.tokens.Reset()
flate/deflate.go:813:		d.step = (*compressor).deflateLazy
flate/deflate.go:836:		d.tokens.Reset()
flate/deflate.go:855:		d.tokens.Reset()
flate/level1.go:18:func (e *fastEncL1) Encode(dst *tokens, src []byte) {
flate/level1.go:136:						dst.tokens[dst.n] = token(v)
flate/level1.go:165:					dst.tokens[dst.n] = token(matchType | uint32(xl)<<lengthShift | xoffset)
flate/fast_encoder.go:15:	Encode(dst *tokens, src []byte)
flate/huffman_code.go:89:// Generates a HuffmanCode corresponding to the fixed literal table
flate/huffman_code.go:129:var fixedLiteralEncoding = generateFixedLiteralEncoding()
flate/huffman_code.go:130:var fixedOffsetEncoding = generateFixedOffsetEncoding()
flate/level2.go:15:func (e *fastEncL2) Encode(dst *tokens, src []byte) {
flate/level2.go:142:						dst.tokens[dst.n] = token(v)
flate/level6.go:11:func (e *fastEncL6) Encode(dst *tokens, src []byte) {
flate/level6.go:260:					dst.tokens[dst.n] = token(v)
flate/level4.go:11:func (e *fastEncL4) Encode(dst *tokens, src []byte) {
flate/level4.go:143:					dst.tokens[dst.n] = token(v)
flate/_gen/gen_inflate.go:40:// fixed distance encoding associated with fixed Huffman blocks.
flate/token_test.go:13:// loadTestTokens will load test tokens.
flate/token_test.go:15:func loadTestTokens(t testFatal) *tokens {
flate/token_test.go:16:	b, err := os.ReadFile("testdata/tokens.bin")
flate/token_test.go:20:	var tokens tokens
flate/token_test.go:21:	err = tokens.FromVarInt(b)
flate/token_test.go:25:	return &tokens
flate/token_test.go:28:func Test_tokens_EstimatedBits(t *testing.T) {
flate/token_test.go:46:func Benchmark_tokens_EstimatedBits(b *testing.B) {
flate/flate_test.go:322:		"fixed block, use reserved symbol 287",
flate/inflate.go:46:// Initialize the fixedHuffmanDecoder only once upon first use.
flate/inflate.go:47:var fixedOnce sync.Once
flate/inflate.go:48:var fixedHuffmanDecoder huffmanDecoder
flate/inflate.go:78:// zlib. There is a lookup table of a fixed bit width (huffmanChunkBits),
flate/inflate.go:362:			fmt.Println("stored block")
flate/inflate.go:365:		// compressed, fixed Huffman tables
flate/inflate.go:366:		f.hl = &fixedHuffmanDecoder
flate/inflate.go:373:		// compressed, dynamic Huffman tables
flate/inflate.go:381:			fmt.Println("dynamic huffman block")
flate/inflate.go:455:// Compression with dynamic Huffman codes
flate/inflate.go:775:func fixedHuffmanDecoderInit() {
flate/inflate.go:776:	fixedOnce.Do(func() {
flate/inflate.go:791:		fixedHuffmanDecoder.init(bits[:])
flate/inflate.go:828:	fixedHuffmanDecoderInit()
flate/deflate.go:43:	// The maximum number of tokens we will encode at the time.
flate/deflate.go:119:	blockStart int // window index where current tokens start
flate/deflate.go:122:	// queued output tokens
flate/deflate.go:123:	tokens tokens
flate/deflate.go:172:func (d *compressor) writeBlock(tok *tokens, index int, eof bool) error {
flate/deflate.go:186:// writeBlockSkip writes the current block and uses the number of tokens
flate/deflate.go:187:// to determine if the block should be stored on no matches, or
flate/deflate.go:189:func (d *compressor) writeBlockSkip(tok *tokens, index int, eof bool) error {
flate/deflate.go:198:				// Write a dynamic huffman block.
flate/deflate.go:224:		d.fast.Encode(&d.tokens, b)
flate/deflate.go:225:		d.tokens.Reset()
flate/deflate.go:406:// deflateLazy is the same as deflate, but with d.fastSkipHashing == skipNever,
flate/deflate.go:408:func (d *compressor) deflateLazy() {
flate/deflate.go:448:					d.tokens.AddLiteral(d.window[s.index-1])
flate/deflate.go:451:				if d.tokens.n > 0 {
flate/deflate.go:452:					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:455:					d.tokens.Reset()
flate/deflate.go:508:									// Emit tokens we "owe"
flate/deflate.go:510:										d.tokens.AddLiteral(d.window[prevIndex+j])
flate/deflate.go:511:										if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:513:											if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:516:											d.tokens.Reset()
flate/deflate.go:549:											// Emit tokens we "owe"
flate/deflate.go:551:												d.tokens.AddLiteral(d.window[prevIndex+j])
flate/deflate.go:552:												if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:554:													if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:557:													d.tokens.Reset()
flate/deflate.go:581:			d.tokens.AddMatch(uint32(prevLength-3), uint32(prevOffset-minOffsetSize))
flate/deflate.go:612:			if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:614:				if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:617:				d.tokens.Reset()
flate/deflate.go:628:				d.tokens.AddLiteral(d.window[s.index-1])
flate/deflate.go:629:				if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:630:					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:633:					d.tokens.Reset()
flate/deflate.go:645:						d.tokens.AddLiteral(d.window[s.index-1])
flate/deflate.go:646:						if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:647:							if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:650:							d.tokens.Reset()
flate/deflate.go:663:					d.tokens.AddLiteral(d.window[s.index-1])
flate/deflate.go:666:					if d.tokens.n == maxFlateBlockTokens {
flate/deflate.go:667:						if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:670:						d.tokens.Reset()
flate/deflate.go:728:			d.tokens.Reset()
flate/deflate.go:735:	d.fast.Encode(&d.tokens, d.window[:d.windowEnd])
flate/deflate.go:737:	if d.tokens.n == 0 {
flate/deflate.go:740:	} else if int(d.tokens.n) > d.windowEnd-(d.windowEnd>>4) {
flate/deflate.go:744:		d.w.writeBlockDynamic(&d.tokens, false, d.window[:d.windowEnd], d.sync)
flate/deflate.go:747:	d.tokens.Reset()
flate/deflate.go:813:		d.step = (*compressor).deflateLazy
flate/deflate.go:836:		d.tokens.Reset()
flate/deflate.go:855:		d.tokens.Reset()
flate/level5.go:11:func (e *fastEncL5) Encode(dst *tokens, src []byte) {
flate/level5.go:225:					dst.tokens[dst.n] = token(v)
flate/level5.go:322:func (e *fastEncL5Window) Encode(dst *tokens, src []byte) {
flate/level5.go:537:					dst.tokens[dst.n] = token(v)
flate/token.go:130:type tokens struct {
flate/token.go:136:	tokens    [maxStoreBlockSize + 1]token
flate/token.go:139:func (t *tokens) Reset() {
flate/token.go:156:func (t *tokens) Fill() {
flate/token.go:179:func indexTokens(in []token) tokens {
flate/token.go:180:	var t tokens
flate/token.go:185:func (t *tokens) indexTokens(in []token) {
flate/token.go:197:func emitLiteral(dst *tokens, lit []byte) {
flate/token.go:199:		dst.tokens[dst.n] = token(v)
flate/token.go:205:func (t *tokens) AddLiteral(lit byte) {
flate/token.go:206:	t.tokens[t.n] = token(lit)
flate/token.go:225:func (t *tokens) EstimatedBits() int {
flate/token.go:262:// AddMatch adds a match to the tokens.
flate/token.go:264:func (t *tokens) AddMatch(xlength uint32, xoffset uint32) {
flate/token.go:278:	t.tokens[t.n] = token(matchType | xlength<<lengthShift | xoffset)
flate/token.go:282:// AddMatchLong adds a match to the tokens, potentially longer than max match length.
flate/token.go:284:func (t *tokens) AddMatchLong(xlength int32, xoffset uint32) {
flate/token.go:306:		t.tokens[t.n] = token(matchType | uint32(xl)<<lengthShift | xoffset)
flate/token.go:311:func (t *tokens) AddEOB() {
flate/token.go:312:	t.tokens[t.n] = token(endBlockMarker)
flate/token.go:317:func (t *tokens) Slice() []token {
flate/token.go:318:	return t.tokens[:t.n]
flate/token.go:321:// VarInt returns the tokens as varint encoded bytes.
flate/token.go:322:func (t *tokens) VarInt() []byte {
flate/token.go:325:	for _, v := range t.tokens[:t.n] {
flate/token.go:331:// FromVarInt restores t to the varint encoded tokens provided.
flate/token.go:333:func (t *tokens) FromVarInt(b []byte) error {
flate/deflate_test.go:511:		if w.d.tokens.n != 0 {
flate/deflate_test.go:512:			t.Errorf("level %d Writer not reset after Reset. %d tokens were present", level, w.d.tokens.n)
flate/deflate_test.go:515:		w.d.tokens = wref.d.tokens
flate/huffman_bit_writer_test.go:100:	tokens      []token
flate/huffman_bit_writer_test.go:101:	input       string // File name of input data matching the tokens.
flate/huffman_bit_writer_test.go:113:		tokens:      []token{0x0, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, 0x0, 0x0},
flate/huffman_bit_writer_test.go:119:		tokens:      []token{0x33, 0x2e, 0x31, 0x34, 0x31, 0x35, 0x39, 0x32, 0x36, 0x35, 0x33, 0x35, 0x38, 0x39, 0x37, 0x39, 0x33, 0x32, 0x33, 0x38, 0x34, 0x36, 0x32, 0x36, 0x34, 0x33, 0x33, 0x38, 0x33, 0x32, 0x37, 0x39, 0x35, 0x30, 0x32, 0x38, 0x38, 0x34, 0x31, 0x39, 0x37, 0x31, 0x36, 0x39, 0x33, 0x39, 0x39, 0x33, 0x37, 0x35, 0x31, 0x30, 0x35, 0x38, 0x32, 0x30, 0x39, 0x37, 0x34, 0x39, 0x34, 0x34, 0x35, 0x39, 0x32, 0x33, 0x30, 0x37, 0x38, 0x31, 0x36, 0x34, 0x30, 0x36, 0x32, 0x38, 0x36, 0x32, 0x30, 0x38, 0x39, 0x39, 0x38, 0x36, 0x32, 0x38, 0x30, 0x33, 0x34, 0x38, 0x32, 0x35, 0x33, 0x34, 0x32, 0x31, 0x31, 0x37, 0x30, 0x36, 0x37, 0x39, 0x38, 0x32, 0x31, 0x34, 0x38, 0x30, 0x38, 0x36, 0x35, 0x31, 0x33, 0x32, 0x38, 0x32, 0x33, 0x30, 0x36, 0x36, 0x34, 0x37, 0x30, 0x39, 0x33, 0x38, 0x34, 0x34, 0x36, 0x30, 0x39, 0x35, 0x35, 0x30, 0x35, 0x38, 0x32, 0x32, 0x33, 0x31, 0x37, 0x32, 0x35, 0x33, 0x35, 0x39, 0x34, 0x30, 0x38, 0x31, 0x32, 0x38, 0x34, 0x38, 0x31, 0x31, 0x31, 0x37, 0x34, 0x4040007e, 0x34, 0x31, 0x30, 0x32, 0x37, 0x30, 0x31, 0x39, 0x33, 0x38, 0x35, 0x32, 0x31, 0x31, 0x30, 0x35, 0x35, 0x35, 0x39, 0x36, 0x34, 0x34, 0x36, 0x32, 0x32, 0x39, 0x34, 0x38, 0x39, 0x35, 0x34, 0x39, 0x33, 0x30, 0x33, 0x38, 0x31, 0x40400012, 0x32, 0x38, 0x38, 0x31, 0x30, 0x39, 0x37, 0x35, 0x36, 0x36, 0x35, 0x39, 0x33, 0x33, 0x34, 0x34, 0x36, 0x40400047, 0x37, 0x35, 0x36, 0x34, 0x38, 0x32, 0x33, 0x33, 0x37, 0x38, 0x36, 0x37, 0x38, 0x33, 0x31, 0x36, 0x35, 0x32, 0x37, 0x31, 0x32, 0x30, 0x31, 0x39, 0x30, 0x39, 0x31, 0x34, 0x4040001a, 0x35, 0x36, 0x36, 0x39, 0x32, 0x33, 0x34, 0x36, 0x404000b2, 0x36, 0x31, 0x30, 0x34, 0x35, 0x34, 0x33, 0x32, 0x36, 0x40400032, 0x31, 0x33, 0x33, 0x39, 0x33, 0x36, 0x30, 0x37, 0x32, 0x36, 0x30, 0x32, 0x34, 0x39, 0x31, 0x34, 0x31, 0x32, 0x37, 0x33, 0x37, 0x32, 0x34, 0x35, 0x38, 0x37, 0x30, 0x30, 0x36, 0x36, 0x30, 0x36, 0x33, 0x31, 0x35, 0x35, 0x38, 0x38, 0x31, 0x37, 0x34, 0x38, 0x38, 0x31, 0x35, 0x32, 0x30, 0x39, 0x32, 0x30, 0x39, 0x36, 0x32, 0x38, 0x32, 0x39, 0x32, 0x35, 0x34, 0x30, 0x39, 0x31, 0x37, 0x31, 0x35, 0x33, 0x36, 0x34, 0x33, 0x36, 0x37, 0x38, 0x39, 0x32, 0x35, 0x39, 0x30, 0x33, 0x36, 0x30, 0x30, 0x31, 0x31, 0x33, 0x33, 0x30, 0x35, 0x33, 0x30, 0x35, 0x34, 0x38, 0x38, 0x32, 0x30, 0x34, 0x36, 0x36, 0x35, 0x32, 0x31, 0x33, 0x38, 0x34, 0x31, 0x34, 0x36, 0x39, 0x35, 0x31, 0x39, 0x34, 0x31, 0x35, 0x31, 0x31, 0x36, 0x30, 0x39, 0x34, 0x33, 0x33, 0x30, 0x35, 0x37, 0x32, 0x37, 0x30, 0x33, 0x36, 0x35, 0x37, 0x35, 0x39, 0x35, 0x39, 0x31, 0x39, 0x35, 0x33, 0x30, 0x39, 0x32, 0x31, 0x38, 0x36, 0x31, 0x31, 0x37, 0x404000e9, 0x33, 0x32, 0x40400009, 0x39, 0x33, 0x31, 0x30, 0x35, 0x31, 0x31, 0x38, 0x35, 0x34, 0x38, 0x30, 0x37, 0x4040010e, 0x33, 0x37, 0x39, 0x39, 0x36, 0x32, 0x37, 0x34, 0x39, 0x35, 0x36, 0x37, 0x33, 0x35, 0x31, 0x38, 0x38, 0x35, 0x37, 0x35, 0x32, 0x37, 0x32, 0x34, 0x38, 0x39, 0x31, 0x32, 0x32, 0x37, 0x39, 0x33, 0x38, 0x31, 0x38, 0x33, 0x30, 0x31, 0x31, 0x39, 0x34, 0x39, 0x31, 0x32, 0x39, 0x38, 0x33, 0x33, 0x36, 0x37, 0x33, 0x33, 0x36, 0x32, 0x34, 0x34, 0x30, 0x36, 0x35, 0x36, 0x36, 0x34, 0x33, 0x30, 0x38, 0x36, 0x30, 0x32, 0x31, 0x33, 0x39, 0x34, 0x39, 0x34, 0x36, 0x33, 0x39, 0x35, 0x32, 0x32, 0x34, 0x37, 0x33, 0x37, 0x31, 0x39, 0x30, 0x37, 0x30, 0x32, 0x31, 0x37, 0x39, 0x38, 0x40800099, 0x37, 0x30, 0x32, 0x37, 0x37, 0x30, 0x35, 0x33, 0x39, 0x32, 0x31, 0x37, 0x31, 0x37, 0x36, 0x32, 0x39, 0x33, 0x31, 0x37, 0x36, 0x37, 0x35, 0x40800232, 0x37, 0x34, 0x38, 0x31, 0x40400006, 0x36, 0x36, 0x39, 0x34, 0x30, 0x404001e7, 0x30, 0x30, 0x30, 0x35, 0x36, 0x38, 0x31, 0x32, 0x37, 0x31, 0x34, 0x35, 0x32, 0x36, 0x33, 0x35, 0x36, 0x30, 0x38, 0x32, 0x37, 0x37, 0x38, 0x35, 0x37, 0x37, 0x31, 0x33, 0x34, 0x32, 0x37, 0x35, 0x37, 0x37, 0x38, 0x39, 0x36, 0x40400129, 0x33, 0x36, 0x33, 0x37, 0x31, 0x37, 0x38, 0x37, 0x32, 0x31, 0x34, 0x36, 0x38, 0x34, 0x34, 0x30, 0x39, 0x30, 0x31, 0x32, 0x32, 0x34, 0x39, 0x35, 0x33, 0x34, 0x33, 0x30, 0x31, 0x34, 0x36, 0x35, 0x34, 0x39, 0x35, 0x38, 0x35, 0x33, 0x37, 0x31, 0x30, 0x35, 0x30, 0x37, 0x39, 0x404000ca, 0x36, 0x40400153, 0x38, 0x39, 0x32, 0x33, 0x35, 0x34, 0x404001c9, 0x39, 0x35, 0x36, 0x31, 0x31, 0x32, 0x31, 0x32, 0x39, 0x30, 0x32, 0x31, 0x39, 0x36, 0x30, 0x38, 0x36, 0x34, 0x30, 0x33, 0x34, 0x34, 0x31, 0x38, 0x31, 0x35, 0x39, 0x38, 0x31, 0x33, 0x36, 0x32, 0x39, 0x37, 0x37, 0x34, 0x40400074, 0x30, 0x39, 0x39, 0x36, 0x30, 0x35, 0x31, 0x38, 0x37, 0x30, 0x37, 0x32, 0x31, 0x31, 0x33, 0x34, 0x39, 0x40800000, 0x38, 0x33, 0x37, 0x32, 0x39, 0x37, 0x38, 0x30, 0x34, 0x39, 0x39, 0x404002da, 0x39, 0x37, 0x33, 0x31, 0x37, 0x33, 0x32, 0x38, 0x4040018a, 0x36, 0x33, 0x31, 0x38, 0x35, 0x40400301, 0x404002e8, 0x34, 0x35, 0x35, 0x33, 0x34, 0x36, 0x39, 0x30, 0x38, 0x33, 0x30, 0x32, 0x36, 0x34, 0x32, 0x35, 0x32, 0x32, 0x33, 0x30, 0x404002e3, 0x40400267, 0x38, 0x35, 0x30, 0x33, 0x35, 0x32, 0x36, 0x31, 0x39, 0x33, 0x31, 0x31, 0x40400212, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30, 0x33, 0x31, 0x33, 0x37, 0x38, 0x33, 0x38, 0x37, 0x35, 0x32, 0x38, 0x38, 0x36, 0x35, 0x38, 0x37, 0x35, 0x33, 0x33, 0x32, 0x30, 0x38, 0x33, 0x38, 0x31, 0x34, 0x32, 0x30, 0x36, 0x40400140, 0x4040012b, 0x31, 0x34, 0x37, 0x33, 0x30, 0x33, 0x35, 0x39, 0x4080032e, 0x39, 0x30, 0x34, 0x32, 0x38, 0x37, 0x35, 0x35, 0x34, 0x36, 0x38, 0x37, 0x33, 0x31, 0x31, 0x35, 0x39, 0x35, 0x40400355, 0x33, 0x38, 0x38, 0x32, 0x33, 0x35, 0x33, 0x37, 0x38, 0x37, 0x35, 0x4080037f, 0x39, 0x4040013a, 0x31, 0x40400148, 0x38, 0x30, 0x35, 0x33, 0x4040018a, 0x32, 0x32, 0x36, 0x38, 0x30, 0x36, 0x36, 0x31, 0x33, 0x30, 0x30, 0x31, 0x39, 0x32, 0x37, 0x38, 0x37, 0x36, 0x36, 0x31, 0x31, 0x31, 0x39, 0x35, 0x39, 0x40400237, 0x36, 0x40800124, 0x38, 0x39, 0x33, 0x38, 0x30, 0x39, 0x35, 0x32, 0x35, 0x37, 0x32, 0x30, 0x31, 0x30, 0x36, 0x35, 0x34, 0x38, 0x35, 0x38, 0x36, 0x33, 0x32, 0x37, 0x4040009a, 0x39, 0x33, 0x36, 0x31, 0x35, 0x33, 0x40400220, 0x4080015c, 0x32, 0x33, 0x30, 0x33, 0x30, 0x31, 0x39, 0x35, 0x32, 0x30, 0x33, 0x35, 0x33, 0x30, 0x31, 0x38, 0x35, 0x32, 0x40400171, 0x40400075, 0x33, 0x36, 0x32, 0x32, 0x35, 0x39, 0x39, 0x34, 0x31, 0x33, 0x40400254, 0x34, 0x39, 0x37, 0x32, 0x31, 0x37, 0x404000de, 0x33, 0x34, 0x37, 0x39, 0x31, 0x33, 0x31, 0x35, 0x31, 0x35, 0x35, 0x37, 0x34, 0x38, 0x35, 0x37, 0x32, 0x34, 0x32, 0x34, 0x35, 0x34, 0x31, 0x35, 0x30, 0x36, 0x39, 0x4040013f, 0x38, 0x32, 0x39, 0x35, 0x33, 0x33, 0x31, 0x31, 0x36, 0x38, 0x36, 0x31, 0x37, 0x32, 0x37, 0x38, 0x40400337, 0x39, 0x30, 0x37, 0x35, 0x30, 0x39, 0x4040010d, 0x37, 0x35, 0x34, 0x36, 0x33, 0x37, 0x34, 0x36, 0x34, 0x39, 0x33, 0x39, 0x33, 0x31, 0x39, 0x32, 0x35, 0x35, 0x30, 0x36, 0x30, 0x34, 0x30, 0x30, 0x39, 0x4040026b, 0x31, 0x36, 0x37, 0x31, 0x31, 0x33, 0x39, 0x30, 0x30, 0x39, 0x38, 0x40400335, 0x34, 0x30, 0x31, 0x32, 0x38, 0x35, 0x38, 0x33, 0x36, 0x31, 0x36, 0x30, 0x33, 0x35, 0x36, 0x33, 0x37, 0x30, 0x37, 0x36, 0x36, 0x30, 0x31, 0x30, 0x34, 0x40400172, 0x38, 0x31, 0x39, 0x34, 0x32, 0x39, 0x4080041e, 0x404000ef, 0x4040028b, 0x37, 0x38, 0x33, 0x37, 0x34, 0x404004a8, 0x38, 0x32, 0x35, 0x35, 0x33, 0x37, 0x40800209, 0x32, 0x36, 0x38, 0x4040002e, 0x34, 0x30, 0x34, 0x37, 0x404001d1, 0x34, 0x404004b5, 0x4040038d, 0x38, 0x34, 0x404003a8, 0x36, 0x40c0031f, 0x33, 0x33, 0x31, 0x33, 0x36, 0x37, 0x37, 0x30, 0x32, 0x38, 0x39, 0x38, 0x39, 0x31, 0x35, 0x32, 0x40400062, 0x35, 0x32, 0x31, 0x36, 0x32, …3184 tokens truncated…0xa, 0xe7, 0xa9, 0x3b, 0x11, 0xda, 0x66, 0x8a, 0x29, 0xda, 0x79, 0xe1, 0x64, 0x8d, 0xe3, 0x54, 0xd4, 0xf5, 0xef, 0x64, 0x87, 0x3b, 0xf4, 0xc2, 0xf4, 0x71, 0x13, 0xa9, 0xe9, 0xe0, 0xa2, 0x6, 0x14, 0xab, 0x5d, 0xa7, 0x96, 0x0, 0xd6, 0xc3, 0xcc, 0x57, 0xed, 0x39, 0x6a, 0x25, 0xcd, 0x76, 0xea, 0xba, 0x3a, 0xf2, 0xa1, 0x95, 0x5d, 0xe5, 0x71, 0xcf, 0x9c, 0x62, 0x9e, 0x6a, 0xfa, 0xd5, 0x31, 0xd1, 0xa8, 0x66, 0x30, 0x33, 0xaa, 0x51, 0x17, 0x13, 0x82, 0x99, 0xc8, 0x14, 0x60, 0x9f, 0x4d, 0x32, 0x6d, 0xda, 0x19, 0x26, 0x21, 0xdc, 0x7e, 0x2e, 0x25, 0x67, 0x72, 0xca, 0xf, 0x92, 0xcd, 0xf6, 0xd6, 0xcb, 0x97, 0x8a, 0x33, 0x58, 0x73, 0x70, 0x91, 0x1d, 0xbf, 0x28, 0x23, 0xa3, 0xc, 0xf1, 0x83, 0xc3, 0xc8, 0x56, 0x77, 0x68, 0xe3, 0x82, 0xba, 0xb9, 0x57, 0x56, 0x57, 0x9c, 0xc3, 0xd6, 0x14, 0x5, 0x3c, 0xb1, 0xaf, 0x93, 0xc8, 0x8a, 0x57, 0x7f, 0x53, 0xfa, 0x2f, 0xaa, 0x6e, 0x66, 0x83, 0xfa, 0x33, 0xd1, 0x21, 0xab, 0x1b, 0x71, 0xb4, 0x7c, 0xda, 0xfd, 0xfb, 0x7f, 0x20, 0xab, 0x5e, 0xd5, 0xca, 0xfd, 0xdd, 0xe0, 0xee, 0xda, 0xba, 0xa8, 0x27, 0x99, 0x97, 0x69, 0xc1, 0x3c, 0x82, 0x8c, 0xa, 0x5c, 0x2d, 0x5b, 0x88, 0x3e, 0x34, 0x35, 0x86, 0x37, 0x46, 0x79, 0xe1, 0xaa, 0x19, 0xfb, 0xaa, 0xde, 0x15, 0x9, 0xd, 0x1a, 0x57, 0xff, 0xb5, 0xf, 0xf3, 0x2b, 0x5a, 0x6a, 0x4d, 0x19, 0x77, 0x71, 0x45, 0xdf, 0x4f, 0xb3, 0xec, 0xf1, 0xeb, 0x18, 0x53, 0x3e, 0x3b, 0x47, 0x8, 0x9a, 0x73, 0xa0, 0x5c, 0x8c, 0x5f, 0xeb, 0xf, 0x3a, 0xc2, 0x43, 0x67, 0xb4, 0x66, 0x67, 0x80, 0x58, 0xe, 0xc1, 0xec, 0x40, 0xd4, 0x22, 0x94, 0xca, 0xf9, 0xe8, 0x92, 0xe4, 0x69, 0x38, 0xbe, 0x67, 0x64, 0xca, 0x50, 0xc7, 0x6, 0x67, 0x42, 0x6e, 0xa3, 0xf0, 0xb7, 0x6c, 0xf2, 0xe8, 0x5f, 0xb1, 0xaf, 0xe7, 0xdb, 0xbb, 0x77, 0xb5, 0xf8, 0xcb, 0x8, 0xc4, 0x75, 0x7e, 0xc0, 0xf9, 0x1c, 0x7f, 0x3c, 0x89, 0x2f, 0xd2, 0x58, 0x3a, 0xe2, 0xf8, 0x91, 0xb6, 0x7b, 0x24, 0x27, 0xe9, 0xae, 0x84, 0x8b, 0xde, 0x74, 0xac, 0xfd, 0xd9, 0xb7, 0x69, 0x2a, 0xec, 0x32, 0x6f, 0xf0, 0x92, 0x84, 0xf1, 0x40, 0xc, 0x8a, 0xbc, 0x39, 0x6e, 0x2e, 0x73, 0xd4, 0x6e, 0x8a, 0x74, 0x2a, 0xdc, 0x60, 0x1f, 0xa3, 0x7, 0xde, 0x75, 0x8b, 0x74, 0xc8, 0xfe, 0x63, 0x75, 0xf6, 0x3d, 0x63, 0xac, 0x33, 0x89, 0xc3, 0xf0, 0xf8, 0x2d, 0x6b, 0xb4, 0x9e, 0x74, 0x8b, 0x5c, 0x33, 0xb4, 0xca, 0xa8, 0xe4, 0x99, 0xb6, 0x90, 0xa1, 0xef, 0xf, 0xd3, 0x61, 0xb2, 0xc6, 0x1a, 0x94, 0x7c, 0x44, 0x55, 0xf4, 0x45, 0xff, 0x9e, 0xa5, 0x5a, 0xc6, 0xa0, 0xe8, 0x2a, 0xc1, 0x8d, 0x6f, 0x34, 0x11, 0xb9, 0xbe, 0x4e, 0xd9, 0x87, 0x97, 0x73, 0xcf, 0x3d, 0x23, 0xae, 0xd5, 0x1a, 0x5e, 0xae, 0x5d, 0x6a, 0x3, 0xf9, 0x22, 0xd, 0x10, 0xd9, 0x47, 0x69, 0x15, 0x3f, 0xee, 0x52, 0xa3, 0x8, 0xd2, 0x3c, 0x51, 0xf4, 0xf8, 0x9d, 0xe4, 0x98, 0x89, 0xc8, 0x67, 0x39, 0xd5, 0x5e, 0x35, 0x78, 0x27, 0xe8, 0x3c, 0x80, 0xae, 0x79, 0x71, 0xd2, 0x93, 0xf4, 0xaa, 0x51, 0x12, 0x1c, 0x4b, 0x1b, 0xe5, 0x6e, 0x15, 0x6f, 0xe4, 0xbb, 0x51, 0x9b, 0x45, 0x9f, 0xf9, 0xc4, 0x8c, 0x2a, 0xfb, 0x1a, 0xdf, 0x55, 0xd3, 0x48, 0x93, 0x27, 0x1, 0x26, 0xc2, 0x6b, 0x55, 0x6d, 0xa2, 0xfb, 0x84, 0x8b, 0xc9, 0x9e, 0x28, 0xc2, 0xef, 0x1a, 0x24, 0xec, 0x9b, 0xae, 0xbd, 0x60, 0xe9, 0x15, 0x35, 0xee, 0x42, 0xa4, 0x33, 0x5b, 0xfa, 0xf, 0xb6, 0xf7, 0x1, 0xa6, 0x2, 0x4c, 0xca, 0x90, 0x58, 0x3a, 0x96, 0x41, 0xe7, 0xcb, 0x9, 0x8c, 0xdb, 0x85, 0x4d, 0xa8, 0x89, 0xf3, 0xb5, 0x8e, 0xfd, 0x75, 0x5b, 0x4f, 0xed, 0xde, 0x3f, 0xeb, 0x38, 0xa3, 0xbe, 0xb0, 0x73, 0xfc, 0xb8, 0x54, 0xf7, 0x4c, 0x30, 0x67, 0x2e, 0x38, 0xa2, 0x54, 0x18, 0xba, 0x8, 0xbf, 0xf2, 0x39, 0xd5, 0xfe, 0xa5, 0x41, 0xc6, 0x66, 0x66, 0xba, 0x81, 0xef, 0x67, 0xe4, 0xe6, 0x3c, 0xc, 0xca, 0xa4, 0xa, 0x79, 0xb3, 0x57, 0x8b, 0x8a, 0x75, 0x98, 0x18, 0x42, 0x2f, 0x29, 0xa3, 0x82, 0xef, 0x9f, 0x86, 0x6, 0x23, 0xe1, 0x75, 0xfa, 0x8, 0xb1, 0xde, 0x17, 0x4a},
flate/huffman_bit_writer_test.go:131:		tokens:      []token{0x61, 0x51c00000, 0xa, 0xf8, 0x8b, 0x96, 0x76, 0x48, 0xa, 0x85, 0x94, 0x25, 0x80, 0xaf, 0xc2, 0xfe, 0x8d, 0xe8, 0x20, 0xeb, 0x17, 0x86, 0xc9, 0xb7, 0xc5, 0xde, 0x6, 0xea, 0x7d, 0x18, 0x8b, 0xe7, 0x3e, 0x7, 0xda, 0xdf, 0xff, 0x6c, 0x73, 0xde, 0xcc, 0xe7, 0x6d, 0x8d, 0x4, 0x19, 0x49, 0x7f, 0x47, 0x1f, 0x48, 0x15, 0xb0, 0xe8, 0x9e, 0xf2, 0x31, 0x59, 0xde, 0x34, 0xb4, 0x5b, 0xe5, 0xe0, 0x9, 0x11, 0x30, 0xc2, 0x88, 0x5b, 0x7c, 0x5d, 0x14, 0x13, 0x6f, 0x23, 0xa9, 0xa, 0xbc, 0x2d, 0x23, 0xbe, 0xd9, 0xed, 0x75, 0x4, 0x6c, 0x99, 0xdf, 0xfd, 0x70, 0x66, 0xe6, 0xee, 0xd9, 0xb1, 0x9e, 0x6e, 0x83, 0x59, 0xd5, 0xd4, 0x80, 0x59, 0x98, 0x77, 0x89, 0x43, 0x38, 0xc9, 0xaf, 0x30, 0x32, 0x9a, 0x20, 0x1b, 0x46, 0x3d, 0x67, 0x6e, 0xd7, 0x72, 0x9e, 0x4e, 0x21, 0x4f, 0xc6, 0xe0, 0xd4, 0x7b, 0x4, 0x8d, 0xa5, 0x3, 0xf6, 0x5, 0x9b, 0x6b, 0xdc, 0x2a, 0x93, 0x77, 0x28, 0xfd, 0xb4, 0x62, 0xda, 0x20, 0xe7, 0x1f, 0xab, 0x6b, 0x51, 0x43, 0x39, 0x2f, 0xa0, 0x92, 0x1, 0x6c, 0x75, 0x3e, 0xf4, 0x35, 0xfd, 0x43, 0x2e, 0xf7, 0xa4, 0x75, 0xda, 0xea, 0x9b, 0xa},
flate/huffman_bit_writer_test.go:137:		tokens:      []token{0x31, 0x30, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x52400001, 0xd, 0xa, 0x32, 0x33, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7f400001},
flate/huffman_bit_writer_test.go:143:		tokens:      []token{0x2f, 0x2f, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x32, 0x30, 0x30, 0x39, 0x54, 0x68, 0x47, 0x6f, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x2e, 0x41, 0x6c, 0x6c, 0x40800016, 0x72, 0x72, 0x76, 0x64, 0x2e, 0xd, 0xa, 0x2f, 0x2f, 0x55, 0x6f, 0x66, 0x74, 0x68, 0x69, 0x6f, 0x75, 0x72, 0x63, 0x63, 0x6f, 0x64, 0x69, 0x67, 0x6f, 0x76, 0x72, 0x6e, 0x64, 0x62, 0x79, 0x42, 0x53, 0x44, 0x2d, 0x74, 0x79, 0x6c, 0x40400020, 0x6c, 0x69, 0x63, 0x6e, 0x74, 0x68, 0x74, 0x63, 0x6e, 0x62, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74, 0x68, 0x4c, 0x49, 0x43, 0x45, 0x4e, 0x53, 0x45, 0x66, 0x69, 0x6c, 0x2e, 0xd, 0xa, 0xd, 0xa, 0x70, 0x63, 0x6b, 0x67, 0x6d, 0x69, 0x6e, 0x4040000a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x6f, 0x22, 0x4040000c, 0x66, 0x75, 0x6e, 0x63, 0x6d, 0x69, 0x6e, 0x28, 0x29, 0x7b, 0xd, 0xa, 0x9, 0x76, 0x72, 0x62, 0x3d, 0x6d, 0x6b, 0x28, 0x5b, 0x5d, 0x62, 0x79, 0x74, 0x2c, 0x36, 0x35, 0x35, 0x33, 0x35, 0x29, 0xd, 0xa, 0x9, 0x66, 0x2c, 0x5f, 0x3a, 0x3d, 0x6f, 0x2e, 0x43, 0x72, 0x74, 0x28, 0x22, 0x68, 0x75, 0x66, 0x66, 0x6d, 0x6e, 0x2d, 0x6e, 0x75, 0x6c, 0x6c, 0x2d, 0x6d, 0x78, 0x2e, 0x69, 0x6e, 0x22, 0x40800021, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x28, 0x62, 0x29, 0xd, 0xa, 0x7d, 0xd, 0xa, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58, 0x78, 0x79, 0x7a, 0x21, 0x22, 0x23, 0xc2, 0xa4, 0x25, 0x26, 0x2f, 0x3f, 0x22},
flate/huffman_bit_writer_test.go:149:		tokens:      []token{0x2f, 0x2f, 0x20, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x32, 0x30, 0x30, 0x39, 0x20, 0x54, 0x68, 0x65, 0x20, 0x47, 0x6f, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x2e, 0x20, 0x41, 0x6c, 0x6c, 0x20, 0x4080001e, 0x73, 0x20, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x2e, 0xd, 0xa, 0x2f, 0x2f, 0x20, 0x55, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x69, 0x73, 0x20, 0x67, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x61, 0x20, 0x42, 0x53, 0x44, 0x2d, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x40800036, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x62, 0x65, 0x20, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x49, 0x43, 0x45, 0x4e, 0x53, 0x45, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0xd, 0xa, 0xd, 0xa, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x4040000f, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x22, 0x6f, 0x73, 0x22, 0x4040000e, 0x66, 0x75, 0x6e, 0x63, 0x4080001b, 0x28, 0x29, 0x20, 0x7b, 0xd, 0xa, 0x9, 0x76, 0x61, 0x72, 0x20, 0x62, 0x20, 0x3d, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x28, 0x5b, 0x5d, 0x62, 0x79, 0x74, 0x65, 0x2c, 0x20, 0x36, 0x35, 0x35, 0x33, 0x35, 0x29, 0xd, 0xa, 0x9, 0x66, 0x2c, 0x20, 0x5f, 0x20, 0x3a, 0x3d, 0x20, 0x6f, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x28, 0x22, 0x68, 0x75, 0x66, 0x66, 0x6d, 0x61, 0x6e, 0x2d, 0x6e, 0x75, 0x6c, 0x6c, 0x2d, 0x6d, 0x61, 0x78, 0x2e, 0x69, 0x6e, 0x22, 0x4080002a, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x28, 0x62, 0x29, 0xd, 0xa, 0x7d, 0xd, 0xa},
flate/huffman_bit_writer_test.go:155:		tokens:      []token{0x30, ml, 0x4b800000},
flate/huffman_bit_writer_test.go:161:		tokens:      []token{0x0, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, 0x41400000},
flate/huffman_bit_writer_test.go:197:	tokens := indexTokens(test.tokens)
flate/huffman_bit_writer_test.go:214:			writeToType(t, ttype, bw, tokens, input)
flate/huffman_bit_writer_test.go:225:		writeToType(t, ttype, bw, tokens, nil)
flate/huffman_bit_writer_test.go:243:		writeToType(t, ttype, bw, tokens, input)
flate/huffman_bit_writer_test.go:257:		writeToType(t, ttype, bw, tokens, input)
flate/huffman_bit_writer_test.go:278:	writeToType(t, ttype, bw, tokens, nil)
flate/huffman_bit_writer_test.go:296:	writeToType(t, ttype, bw, tokens, nil)
flate/huffman_bit_writer_test.go:310:func writeToType(t *testing.T, ttype string, bw *huffmanBitWriter, tok tokens, input []byte) {
flate/huffman_bit_writer_test.go:350:	tokens := indexTokens(test.tokens)
flate/huffman_bit_writer_test.go:353:		bw.writeBlock(&tokens, true, input)
flate/huffman_bit_writer_test.go:355:		bw.writeBlockDynamic(&tokens, true, input, true)
flate/stateless.go:64:// tokensPool contains tokens struct objects that can be reused
flate/stateless.go:65:var tokensPool = sync.Pool{
flate/stateless.go:67:		return &tokens{}
flate/stateless.go:100:	dst := tokensPool.Get().(*tokens)
flate/stateless.go:103:		tokensPool.Put(dst)
flate/stateless.go:157:		// Align, only a stored block can do that.
flate/stateless.go:176:func statelessEnc(dst *tokens, src []byte, startAt int16) {
flate/stateless.go:276:						dst.tokens[dst.n] = token(v)
flate/inflate_gen.go:16:// fixed distance encoding associated with fixed Huffman blocks.
flate/inflate_gen.go:267:// fixed distance encoding associated with fixed Huffman blocks.
flate/inflate_gen.go:518:// fixed distance encoding associated with fixed Huffman blocks.
flate/inflate_gen.go:769:// fixed distance encoding associated with fixed Huffman blocks.
flate/inflate_gen.go:1020:// fixed distance encoding associated with fixed Huffman blocks.
flate/level3.go:12:func (e *fastEncL3) Encode(dst *tokens, src []byte) {
flate/level3.go:151:						dst.tokens[dst.n] = token(v)
flate/inflate_test.go:110:	{"0 0 0 0 0", "invalid stored block lengths", 1},
flate/inflate_test.go:111:	{"3 0", "fixed", 0},
flate/inflate_test.go:113:	{"1 1 0 fe ff 0", "stored", 0},
flate/inflate_test.go:229:	{"3 0", "use fixed blocks", 0, -15, 1, false},
flate/huffman_bit_writer.go:29:	// maxPredefinedTokens is the maximum number of tokens
flate/huffman_bit_writer.go:30:	// where we check if fixed size is smaller.
flate/huffman_bit_writer.go:163:func (w *huffmanBitWriter) canReuse(t *tokens) (ok bool) {
flate/huffman_bit_writer.go:370:// dynamicSize returns the size of dynamically encoded data in bits.
flate/huffman_bit_writer.go:371:func (w *huffmanBitWriter) dynamicReuseSize(litEnc, offEnc *huffmanEncoder) (size int) {
flate/huffman_bit_writer.go:377:// dynamicSize returns the size of dynamically encoded data in bits.
flate/huffman_bit_writer.go:378:func (w *huffmanBitWriter) dynamicSize(litEnc, offEnc *huffmanEncoder, extraBits int) (size, numCodegens int) {
flate/huffman_bit_writer.go:400:// fixedSize returns the size of dynamically encoded data in bits.
flate/huffman_bit_writer.go:401:func (w *huffmanBitWriter) fixedSize(extraBits int) int {
flate/huffman_bit_writer.go:403:		fixedLiteralEncoding.bitLength(w.literalFreq[:]) +
flate/huffman_bit_writer.go:404:		fixedOffsetEncoding.bitLength(w.offsetFreq[:]) +
flate/huffman_bit_writer.go:408:// storedSize calculates the stored size, including header.
flate/huffman_bit_writer.go:411:func (w *huffmanBitWriter) storedSize(in []byte) (int, bool) {
flate/huffman_bit_writer.go:453:// Write the header of a dynamic Huffman block to the output stream.
flate/huffman_bit_writer.go:499:// writeStoredHeader will write a stored header.
flate/huffman_bit_writer.go:500:// If the stored block is only used for EOF,
flate/huffman_bit_writer.go:501:// it is replaced with a fixed huffman block.
flate/huffman_bit_writer.go:512:	// To write EOF, use a fixed encoding block. 10 bits instead of 5 bytes.
flate/huffman_bit_writer.go:541:	// Indicate that we are a fixed Huffman block
flate/huffman_bit_writer.go:549:// writeBlock will write a block of tokens with the smallest encoding.
flate/huffman_bit_writer.go:552:// stored block.
flate/huffman_bit_writer.go:553:// If the input is nil, the tokens will always be Huffman encoded.
flate/huffman_bit_writer.go:554:func (w *huffmanBitWriter) writeBlock(tokens *tokens, eof bool, input []byte) {
flate/huffman_bit_writer.go:559:	tokens.AddEOB()
flate/huffman_bit_writer.go:565:	numLiterals, numOffsets := w.indexTokens(tokens, false)
flate/huffman_bit_writer.go:568:	storedSize, storable := w.storedSize(input)
flate/huffman_bit_writer.go:575:	var literalEncoding = fixedLiteralEncoding
flate/huffman_bit_writer.go:576:	var offsetEncoding = fixedOffsetEncoding
flate/huffman_bit_writer.go:578:	if tokens.n < maxPredefinedTokens {
flate/huffman_bit_writer.go:579:		size = w.fixedSize(extraBits)
flate/huffman_bit_writer.go:589:	dynamicSize, numCodegens := w.dynamicSize(w.literalEncoding, w.offsetEncoding, extraBits)
flate/huffman_bit_writer.go:591:	if dynamicSize < size {
flate/huffman_bit_writer.go:592:		size = dynamicSize
flate/huffman_bit_writer.go:598:	if storable && storedSize <= size {
flate/huffman_bit_writer.go:605:	if literalEncoding == fixedLiteralEncoding {
flate/huffman_bit_writer.go:611:	// Write the tokens.
flate/huffman_bit_writer.go:612:	w.writeTokens(tokens.Slice(), literalEncoding.codes, offsetEncoding.codes)
flate/huffman_bit_writer.go:615:// writeBlockDynamic encodes a block using a dynamic Huffman table.
flate/huffman_bit_writer.go:619:// input size the block is stored.
flate/huffman_bit_writer.go:620:func (w *huffmanBitWriter) writeBlockDynamic(tokens *tokens, eof bool, input []byte, sync bool) {
flate/huffman_bit_writer.go:627:		tokens.AddEOB()
flate/huffman_bit_writer.go:644:	if !fillReuse && w.lastHeader > 0 && !w.canReuse(tokens) {
flate/huffman_bit_writer.go:649:	numLiterals, numOffsets := w.indexTokens(tokens, fillReuse && !sync)
flate/huffman_bit_writer.go:651:	ssize, storable := w.storedSize(input)
flate/huffman_bit_writer.go:664:		newSize := w.lastHeader + tokens.EstimatedBits()
flate/huffman_bit_writer.go:669:		reuseSize := w.dynamicReuseSize(w.literalEncoding, w.offsetEncoding) + extraBits
flate/huffman_bit_writer.go:681:		if tokens.n < maxPredefinedTokens {
flate/huffman_bit_writer.go:682:			if preSize := w.fixedSize(extraBits) + 7; usePrefs && preSize < size {
flate/huffman_bit_writer.go:691:					tokens.AddEOB()
flate/huffman_bit_writer.go:693:				w.writeTokens(tokens.Slice(), fixedLiteralEncoding.codes, fixedOffsetEncoding.codes)
flate/huffman_bit_writer.go:723:			w.indexTokens(tokens, true)
flate/huffman_bit_writer.go:725:		size, numCodegens = w.dynamicSize(w.literalEncoding, w.offsetEncoding, extraBits)
flate/huffman_bit_writer.go:728:		if tokens.n < maxPredefinedTokens {
flate/huffman_bit_writer.go:729:			if preSize := w.fixedSize(extraBits); usePrefs && preSize <= size {
flate/huffman_bit_writer.go:738:					tokens.AddEOB()
flate/huffman_bit_writer.go:740:				w.writeTokens(tokens.Slice(), fixedLiteralEncoding.codes, fixedOffsetEncoding.codes)
flate/huffman_bit_writer.go:763:	// Write the tokens.
flate/huffman_bit_writer.go:764:	w.writeTokens(tokens.Slice(), w.literalEncoding.codes, w.offsetEncoding.codes)
flate/huffman_bit_writer.go:780:// indexTokens indexes a slice of tokens, and updates
flate/huffman_bit_writer.go:783:// The number of literal and offset tokens is returned.
flate/huffman_bit_writer.go:784:func (w *huffmanBitWriter) indexTokens(t *tokens, filled bool) (numLiterals, numOffsets int) {
flate/huffman_bit_writer.go:808:		// We haven't found a single match. If we want to go with the dynamic encoding,
flate/huffman_bit_writer.go:821:// writeTokens writes a slice of tokens to the output.
flate/huffman_bit_writer.go:823:func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode) {
flate/huffman_bit_writer.go:827:	if len(tokens) == 0 {
flate/huffman_bit_writer.go:833:	if tokens[len(tokens)-1] == endBlockMarker {
flate/huffman_bit_writer.go:834:		tokens = tokens[:len(tokens)-1]
flate/huffman_bit_writer.go:847:	for _, t := range tokens {
flate/huffman_bit_writer.go:1010:	ssize, storable := w.storedSize(input)
flate/huffman_bit_writer.go:1025:				fmt.Println("stored", abs, "<", max)
flate/huffman_bit_writer.go:1047:			fmt.Println("stored,", ssize, "<=", estBits)
shell
go test ./flate -run 'Test.*' -count=1
output
Chunk ID: 3b744d
Wall time: 1.0022 seconds
Process running with session ID 28995
Original token count: 0
Output:
shell
rg --files flate | sort
output
Chunk ID: 7b6984
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 957
Output:
flate/_gen/gen_inflate.go
flate/deflate.go
flate/deflate_test.go
flate/dict_decoder.go
flate/dict_decoder_test.go
flate/example_test.go
flate/fast_encoder.go
flate/flate_test.go
flate/fuzz_test.go
flate/huffman_bit_writer.go
flate/huffman_bit_writer_test.go
flate/huffman_code.go
flate/huffman_sortByFreq.go
flate/huffman_sortByLiteral.go
flate/inflate.go
flate/inflate_gen.go
flate/inflate_test.go
flate/large_low_entropy_test.go
flate/level1.go
flate/level2.go
flate/level3.go
flate/level4.go
flate/level5.go
flate/level6.go
flate/matchlen_generic.go
flate/reader_test.go
flate/regmask_amd64.go
flate/regmask_other.go
flate/stateless.go
flate/testdata/fuzz/FuzzEncoding.zip
flate/testdata/fuzz/encode-raw-corpus.zip
flate/testdata/huffman-null-max.dyn.expect
flate/testdata/huffman-null-max.dyn.expect-noinput
flate/testdata/huffman-null-max.golden
flate/testdata/huffman-null-max.in
flate/testdata/huffman-null-max.sync.expect
flate/testdata/huffman-null-max.sync.expect-noinput
flate/testdata/huffman-null-max.wb.expect
flate/testdata/huffman-null-max.wb.expect-noinput
flate/testdata/huffman-pi.dyn.expect
flate/testdata/huffman-pi.dyn.expect-noinput
flate/testdata/huffman-pi.golden
flate/testdata/huffman-pi.in
flate/testdata/huffman-pi.sync.expect
flate/testdata/huffman-pi.sync.expect-noinput
flate/testdata/huffman-pi.wb.expect
flate/testdata/huffman-pi.wb.expect-noinput
flate/testdata/huffman-rand-1k.dyn.expect
flate/testdata/huffman-rand-1k.dyn.expect-noinput
flate/testdata/huffman-rand-1k.golden
flate/testdata/huffman-rand-1k.in
flate/testdata/huffman-rand-1k.sync.expect
flate/testdata/huffman-rand-1k.sync.expect-noinput
flate/testdata/huffman-rand-1k.wb.expect
flate/testdata/huffman-rand-1k.wb.expect-noinput
flate/testdata/huffman-rand-limit.dyn.expect
flate/testdata/huffman-rand-limit.dyn.expect-noinput
flate/testdata/huffman-rand-limit.golden
flate/testdata/huffman-rand-limit.in
flate/testdata/huffman-rand-limit.sync.expect
flate/testdata/huffman-rand-limit.sync.expect-noinput
flate/testdata/huffman-rand-limit.wb.expect
flate/testdata/huffman-rand-limit.wb.expect-noinput
flate/testdata/huffman-rand-max.golden
flate/testdata/huffman-rand-max.in
flate/testdata/huffman-shifts.dyn.expect
flate/testdata/huffman-shifts.dyn.expect-noinput
flate/testdata/huffman-shifts.golden
flate/testdata/huffman-shifts.in
flate/testdata/huffman-shifts.sync.expect
flate/testdata/huffman-shifts.sync.expect-noinput
flate/testdata/huffman-shifts.wb.expect
flate/testdata/huffman-shifts.wb.expect-noinput
flate/testdata/huffman-text-shift.dyn.expect
flate/testdata/huffman-text-shift.dyn.expect-noinput
flate/testdata/huffman-text-shift.golden
flate/testdata/huffman-text-shift.in
flate/testdata/huffman-text-shift.sync.expect
flate/testdata/huffman-text-shift.sync.expect-noinput
flate/testdata/huffman-text-shift.wb.expect
flate/testdata/huffman-text-shift.wb.expect-noinput
flate/testdata/huffman-text.dyn.expect
flate/testdata/huffman-text.dyn.expect-noinput
flate/testdata/huffman-text.golden
flate/testdata/huffman-text.in
flate/testdata/huffman-text.sync.expect
flate/testdata/huffman-text.sync.expect-noinput
flate/testdata/huffman-text.wb.expect
flate/testdata/huffman-text.wb.expect-noinput
flate/testdata/huffman-zero.dyn.expect
flate/testdata/huffman-zero.dyn.expect-noinput
flate/testdata/huffman-zero.golden
flate/testdata/huffman-zero.in
flate/testdata/huffman-zero.sync.expect
flate/testdata/huffman-zero.sync.expect-noinput
flate/testdata/huffman-zero.wb.expect
flate/testdata/huffman-zero.wb.expect-noinput
flate/testdata/null-long-match.dyn.expect-noinput
flate/testdata/null-long-match.sync.expect-noinput
flate/testdata/null-long-match.wb.expect-noinput
flate/testdata/partial-block
flate/testdata/regression.zip
flate/testdata/tokens.bin
flate/token.go
flate/token_test.go
flate/writer_test.go
There is already a `large_low_entropy_test.go` in the package, so I’m checking whether it captures this exact failure and where the compressor currently chooses stored/fixed/dynamic block forms.
shell
sed -n '1,240p' flate/deflate.go
output
Chunk ID: 71c157
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1772
Output:
// Copyright 2009 The Go Authors. All rights reserved.
// Copyright (c) 2015 Klaus Post
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package flate

import (
	"errors"
	"fmt"
	"io"
	"math"

	"[code-host]/klauspost/compress/internal/le"
)

const (
	NoCompression      = 0
	BestSpeed          = 1
	BestCompression    = 9
	DefaultCompression = -1

	// HuffmanOnly disables Lempel-Ziv match searching and only performs Huffman
	// entropy encoding. This mode is useful in compressing data that has
	// already been compressed with an LZ style algorithm (e.g. Snappy or LZ4)
	// that lacks an entropy encoder. Compression gains are achieved when
	// certain bytes in the input stream occur more frequently than others.
	//
	// Note that HuffmanOnly produces a compressed output that is
	// RFC 1951 compliant. That is, any valid DEFLATE decompressor will
	// continue to be able to decompress this output.
	HuffmanOnly         = -2
	ConstantCompression = HuffmanOnly // compatibility alias.

	logWindowSize    = 15
	windowSize       = 1 << logWindowSize
	windowMask       = windowSize - 1
	logMaxOffsetSize = 15  // Standard DEFLATE
	minMatchLength   = 4   // The smallest match that the compressor looks for
	maxMatchLength   = 258 // The longest match for the compressor
	minOffsetSize    = 1   // The shortest offset that makes any sense

	// The maximum number of tokens we will encode at the time.
	// Smaller sizes usually creates less optimal blocks.
	// Bigger can make context switching slow.
	// We use this for levels 7-9, so we make it big.
	maxFlateBlockTokens = 1 << 15
	maxStoreBlockSize   = 65535
	hashBits            = 17 // After 17 performance degrades
	hashSize            = 1 << hashBits
	hashMask            = (1 << hashBits) - 1
	hashShift           = (hashBits + minMatchLength - 1) / minMatchLength
	maxHashOffset       = 1 << 28

	skipNever = math.MaxInt32

	debugDeflate = false
)

type compressionLevel struct {
	good, lazy, nice, chain, fastSkipHashing, level int
}

// Compression levels have been rebalanced from zlib deflate defaults
// to give a bigger spread in speed and compression.
// See https://blog.klauspost.com/rebalancing-deflate-compression-levels/
var levels = []compressionLevel{
	{}, // 0
	// Level 1-6 uses specialized algorithm - values not used
	{0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 2},
	{0, 0, 0, 0, 0, 3},
	{0, 0, 0, 0, 0, 4},
	{0, 0, 0, 0, 0, 5},
	{0, 0, 0, 0, 0, 6},
	// Levels 7-9 use increasingly more lazy matching
	// and increasingly stringent conditions for "good enough".
	{8, 12, 16, 24, skipNever, 7},
	{16, 30, 40, 64, skipNever, 8},
	{32, 258, 258, 1024, skipNever, 9},
}

// advancedState contains state for the advanced levels, with bigger hash tables, etc.
type advancedState struct {
	// deflate state
	length         int
	offset         int
	maxInsertIndex int
	chainHead      int
	hashOffset     int

	ii uint16 // position of last match, intended to overflow to reset.

	// input window: unprocessed data is window[index:windowEnd]
	index     int
	hashMatch [maxMatchLength + minMatchLength]uint32

	// Input hash chains
	// hashHead[hashValue] contains the largest inputIndex with the specified hash value
	// If hashHead[hashValue] is within the current window, then
	// hashPrev[hashHead[hashValue] & windowMask] contains the previous index
	// with the same hash value.
	hashHead [hashSize]uint32
	hashPrev [windowSize]uint32
}

type compressor struct {
	compressionLevel

	h *huffmanEncoder
	w *huffmanBitWriter

	// compression algorithm
	fill func(*compressor, []byte) int // copy data to window
	step func(*compressor)             // process window

	window     []byte
	windowEnd  int
	blockStart int // window index where current tokens start
	err        error

	// queued output tokens
	tokens tokens
	fast   fastEnc
	state  *advancedState

	sync          bool // requesting flush
	byteAvailable bool // if true, still need to process window[index-1].
}

func (d *compressor) fillDeflate(b []byte) int {
	s := d.state
	if s.index >= 2*windowSize-(minMatchLength+maxMatchLength) {
		// shift the window by windowSize
		//copy(d.window[:], d.window[windowSize:2*windowSize])
		*(*[windowSize]byte)(d.window) = *(*[windowSize]byte)(d.window[windowSize:])
		s.index -= windowSize
		d.windowEnd -= windowSize
		if d.blockStart >= windowSize {
			d.blockStart -= windowSize
		} else {
			d.blockStart = math.MaxInt32
		}
		s.hashOffset += windowSize
		if s.hashOffset > maxHashOffset {
			delta := s.hashOffset - 1
			s.hashOffset -= delta
			s.chainHead -= delta
			// Iterate over slices instead of arrays to avoid copying
			// the entire table onto the stack (Issue #18625).
			for i, v := range s.hashPrev[:] {
				if int(v) > delta {
					s.hashPrev[i] = uint32(int(v) - delta)
				} else {
					s.hashPrev[i] = 0
				}
			}
			for i, v := range s.hashHead[:] {
				if int(v) > delta {
					s.hashHead[i] = uint32(int(v) - delta)
				} else {
					s.hashHead[i] = 0
				}
			}
		}
	}
	n := copy(d.window[d.windowEnd:], b)
	d.windowEnd += n
	return n
}

func (d *compressor) writeBlock(tok *tokens, index int, eof bool) error {
	if index > 0 || eof {
		var window []byte
		if d.blockStart <= index {
			window = d.window[d.blockStart:index]
		}
		d.blockStart = index
		//d.w.writeBlock(tok, eof, window)
		d.w.writeBlockDynamic(tok, eof, window, d.sync)
		return d.w.err
	}
	return nil
}

// writeBlockSkip writes the current block and uses the number of tokens
// to determine if the block should be stored on no matches, or
// only huffman encoded.
func (d *compressor) writeBlockSkip(tok *tokens, index int, eof bool) error {
	if index > 0 || eof {
		if d.blockStart <= index {
			window := d.window[d.blockStart:index]
			// If we removed less than a 64th of all literals
			// we huffman compress the block.
			if int(tok.n) > len(window)-int(tok.n>>6) {
				d.w.writeBlockHuff(eof, window, d.sync)
			} else {
				// Write a dynamic huffman block.
				d.w.writeBlockDynamic(tok, eof, window, d.sync)
			}
		} else {
			d.w.writeBlock(tok, eof, nil)
		}
		d.blockStart = index
		return d.w.err
	}
	return nil
}

// fillWindow will fill the current window with the supplied
// dictionary and calculate all hashes.
// This is much faster than doing a full encode.
// Should only be used after a start/reset.
func (d *compressor) fillWindow(b []byte) {
	// Do not fill window if we are in store-only or huffman mode.
	if d.level <= 0 && d.level > -MinCustomWindowSize {
		return
	}
	if d.fast != nil {
		// encode the last data, but discard the result
		if len(b) > maxMatchOffset {
			b = b[len(b)-maxMatchOffset:]
		}
		d.fast.Encode(&d.tokens, b)
		d.tokens.Reset()
		return
	}
	s := d.state
	// If we are given too much, cut it.
	if len(b) > windowSize {
		b = b[len(b)-windowSize:]
	}
	// Add all to window.
	n := copy(d.window[d.windowEnd:], b)

	// Calculate 256 hashes at the time (more L1 cache hits)
	loops := (n + 256 - minMatchLength) / 256
	for j := range loops {
		startindex := j * 256
		end := min(startindex+256+minMatchLength-1, n)
shell
sed -n '400,690p' flate/deflate.go
output
Chunk ID: beac05
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 2237
Output:
	s.hashOffset = 1
	s.length = minMatchLength - 1
	s.offset = 0
	s.chainHead = -1
}

// deflateLazy is the same as deflate, but with d.fastSkipHashing == skipNever,
// meaning it always has lazy matching on.
func (d *compressor) deflateLazy() {
	s := d.state
	// Sanity enables additional runtime tests.
	// It's intended to be used during development
	// to supplement the currently ad-hoc unit tests.
	const sanity = debugDeflate

	if d.windowEnd-s.index < minMatchLength+maxMatchLength && !d.sync {
		return
	}
	if d.windowEnd != s.index && d.chain > 100 {
		// Get literal huffman coder.
		if d.h == nil {
			d.h = newHuffmanEncoder(maxFlateBlockTokens)
		}
		var tmp [256]uint16
		for _, v := range d.window[s.index:d.windowEnd] {
			tmp[v]++
		}
		d.h.generate(tmp[:], 15)
	}

	s.maxInsertIndex = d.windowEnd - (minMatchLength - 1)

	for {
		if sanity && s.index > d.windowEnd {
			panic("index > windowEnd")
		}
		lookahead := d.windowEnd - s.index
		if lookahead < minMatchLength+maxMatchLength {
			if !d.sync {
				return
			}
			if sanity && s.index > d.windowEnd {
				panic("index > windowEnd")
			}
			if lookahead == 0 {
				// Flush current output block if any.
				if d.byteAvailable {
					// There is still one pending token that needs to be flushed
					d.tokens.AddLiteral(d.window[s.index-1])
					d.byteAvailable = false
				}
				if d.tokens.n > 0 {
					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
						return
					}
					d.tokens.Reset()
				}
				return
			}
		}
		if s.index < s.maxInsertIndex {
			// Update the hash
			hash := hash4(d.window[s.index:])
			ch := s.hashHead[hash]
			s.chainHead = int(ch)
			s.hashPrev[s.index&windowMask] = ch
			s.hashHead[hash] = uint32(s.index + s.hashOffset)
		}
		prevLength := s.length
		prevOffset := s.offset
		s.length = minMatchLength - 1
		s.offset = 0
		minIndex := max(s.index-windowSize, 0)

		if s.chainHead-s.hashOffset >= minIndex && lookahead > prevLength && prevLength < d.lazy {
			if newLength, newOffset, ok := d.findMatch(s.index, s.chainHead-s.hashOffset, lookahead); ok {
				s.length = newLength
				s.offset = newOffset
			}
		}

		if prevLength >= minMatchLength && s.length <= prevLength {
			// No better match, but check for better match at end...
			//
			// Skip forward a number of bytes.
			// Offset of 2 seems to yield best results. 3 is sometimes better.
			const checkOff = 2

			// Check all, except full length
			if prevLength < maxMatchLength-checkOff {
				prevIndex := s.index - 1
				if prevIndex+prevLength < s.maxInsertIndex {
					end := min(lookahead, maxMatchLength+checkOff)
					end += prevIndex

					// Hash at match end.
					h := hash4(d.window[prevIndex+prevLength:])
					ch2 := int(s.hashHead[h]) - s.hashOffset - prevLength
					if prevIndex-ch2 != prevOffset && ch2 > minIndex+checkOff {
						length := matchLen(d.window[prevIndex+checkOff:end], d.window[ch2+checkOff:])
						// It seems like a pure length metric is best.
						if length > prevLength {
							prevLength = length
							prevOffset = prevIndex - ch2

							// Extend back...
							for i := checkOff - 1; i >= 0; i-- {
								if prevLength >= maxMatchLength || d.window[prevIndex+i] != d.window[ch2+i] {
									// Emit tokens we "owe"
									for j := 0; j <= i; j++ {
										d.tokens.AddLiteral(d.window[prevIndex+j])
										if d.tokens.n == maxFlateBlockTokens {
											// The block includes the current character
											if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
												return
											}
											d.tokens.Reset()
										}
										s.index++
										if s.index < s.maxInsertIndex {
											h := hash4(d.window[s.index:])
											ch := s.hashHead[h]
											s.chainHead = int(ch)
											s.hashPrev[s.index&windowMask] = ch
											s.hashHead[h] = uint32(s.index + s.hashOffset)
										}
									}
									break
								} else {
									prevLength++
								}
							}
						} else if false {
							// Check one further ahead.
							// Only rarely better, disabled for now.
							prevIndex++
							h := hash4(d.window[prevIndex+prevLength:])
							ch2 := int(s.hashHead[h]) - s.hashOffset - prevLength
							if prevIndex-ch2 != prevOffset && ch2 > minIndex+checkOff {
								length := matchLen(d.window[prevIndex+checkOff:end], d.window[ch2+checkOff:])
								// It seems like a pure length metric is best.
								if length > prevLength+checkOff {
									prevLength = length
									prevOffset = prevIndex - ch2
									prevIndex--

									// Extend back...
									for i := checkOff; i >= 0; i-- {
										if prevLength >= maxMatchLength || d.window[prevIndex+i] != d.window[ch2+i-1] {
											// Emit tokens we "owe"
											for j := 0; j <= i; j++ {
												d.tokens.AddLiteral(d.window[prevIndex+j])
												if d.tokens.n == maxFlateBlockTokens {
													// The block includes the current character
													if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
														return
													}
													d.tokens.Reset()
												}
												s.index++
												if s.index < s.maxInsertIndex {
													h := hash4(d.window[s.index:])
													ch := s.hashHead[h]
													s.chainHead = int(ch)
													s.hashPrev[s.index&windowMask] = ch
													s.hashHead[h] = uint32(s.index + s.hashOffset)
												}
											}
											break
										} else {
											prevLength++
										}
									}
								}
							}
						}
					}
				}
			}
			// There was a match at the previous step, and the current match is
			// not better. Output the previous match.
			d.tokens.AddMatch(uint32(prevLength-3), uint32(prevOffset-minOffsetSize))

			// Insert in the hash table all strings up to the end of the match.
			// index and index-1 are already inserted. If there is not enough
			// lookahead, the last two strings are not inserted into the hash
			// table.
			newIndex := s.index + prevLength - 1
			// Calculate missing hashes
			end := min(newIndex, s.maxInsertIndex)
			end += minMatchLength - 1
			startindex := min(s.index+1, s.maxInsertIndex)
			tocheck := d.window[startindex:end]
			dstSize := len(tocheck) - minMatchLength + 1
			if dstSize > 0 {
				dst := s.hashMatch[:dstSize]
				bulkHash4(tocheck, dst)
				var newH uint32
				for i, val := range dst {
					di := i + startindex
					newH = val & hashMask
					// Get previous value with the same hash.
					// Our chain should point to the previous value.
					s.hashPrev[di&windowMask] = s.hashHead[newH]
					// Set the head of the hash chain to us.
					s.hashHead[newH] = uint32(di + s.hashOffset)
				}
			}

			s.index = newIndex
			d.byteAvailable = false
			s.length = minMatchLength - 1
			if d.tokens.n == maxFlateBlockTokens {
				// The block includes the current character
				if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
					return
				}
				d.tokens.Reset()
			}
			s.ii = 0
		} else {
			// Reset, if we got a match this run.
			if s.length >= minMatchLength {
				s.ii = 0
			}
			// We have a byte waiting. Emit it.
			if d.byteAvailable {
				s.ii++
				d.tokens.AddLiteral(d.window[s.index-1])
				if d.tokens.n == maxFlateBlockTokens {
					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
						return
					}
					d.tokens.Reset()
				}
				s.index++

				// If we have a long run of no matches, skip additional bytes
				// Resets when s.ii overflows after 64KB.
				if n := int(s.ii) - d.chain; n > 0 {
					n = 1 + int(n>>6)
					for j := 0; j < n; j++ {
						if s.index >= d.windowEnd-1 {
							break
						}
						d.tokens.AddLiteral(d.window[s.index-1])
						if d.tokens.n == maxFlateBlockTokens {
							if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
								return
							}
							d.tokens.Reset()
						}
						// Index...
						if s.index < s.maxInsertIndex {
							h := hash4(d.window[s.index:])
							ch := s.hashHead[h]
							s.chainHead = int(ch)
							s.hashPrev[s.index&windowMask] = ch
							s.hashHead[h] = uint32(s.index + s.hashOffset)
						}
						s.index++
					}
					// Flush last byte
					d.tokens.AddLiteral(d.window[s.index-1])
					d.byteAvailable = false
					// s.length = minMatchLength - 1 // not needed, since s.ii is reset above, so it should never be > minMatchLength
					if d.tokens.n == maxFlateBlockTokens {
						if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
							return
						}
						d.tokens.Reset()
					}
				}
			} else {
				s.index++
				d.byteAvailable = true
			}
		}
	}
}

func (d *compressor) store() {
	if d.windowEnd > 0 && (d.windowEnd == maxStoreBlockSize || d.sync) {
		d.err = d.writeStoredBlock(d.window[:d.windowEnd])
		d.windowEnd = 0
	}
}

// fillWindow will fill the buffer with data for huffman-only compression.
// The number of bytes copied is returned.
func (d *compressor) fillBlock(b []byte) int {
shell
sed -n '540,780p' flate/huffman_bit_writer.go
output
Chunk ID: 6512a0
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1657
Output:

	// Indicate that we are a fixed Huffman block
	var value int32 = 2
	if isEof {
		value = 3
	}
	w.writeBits(value, 3)
}

// writeBlock will write a block of tokens with the smallest encoding.
// The original input can be supplied, and if the huffman encoded data
// is larger than the original bytes, the data will be written as a
// stored block.
// If the input is nil, the tokens will always be Huffman encoded.
func (w *huffmanBitWriter) writeBlock(tokens *tokens, eof bool, input []byte) {
	if w.err != nil {
		return
	}

	tokens.AddEOB()
	if w.lastHeader > 0 {
		// We owe an EOB
		w.writeCode(w.literalEncoding.codes[endBlockMarker])
		w.lastHeader = 0
	}
	numLiterals, numOffsets := w.indexTokens(tokens, false)
	w.generate()
	var extraBits int
	storedSize, storable := w.storedSize(input)
	if storable {
		extraBits = w.extraBitSize()
	}

	// Figure out smallest code.
	// Fixed Huffman baseline.
	var literalEncoding = fixedLiteralEncoding
	var offsetEncoding = fixedOffsetEncoding
	var size = math.MaxInt32
	if tokens.n < maxPredefinedTokens {
		size = w.fixedSize(extraBits)
	}

	// Dynamic Huffman?
	var numCodegens int

	// Generate codegen and codegenFrequencies, which indicates how to encode
	// the literalEncoding and the offsetEncoding.
	w.generateCodegen(numLiterals, numOffsets, w.literalEncoding, w.offsetEncoding)
	w.codegenEncoding.generate(w.codegenFreq[:], 7)
	dynamicSize, numCodegens := w.dynamicSize(w.literalEncoding, w.offsetEncoding, extraBits)

	if dynamicSize < size {
		size = dynamicSize
		literalEncoding = w.literalEncoding
		offsetEncoding = w.offsetEncoding
	}

	// Stored bytes?
	if storable && storedSize <= size {
		w.writeStoredHeader(len(input), eof)
		w.writeBytes(input)
		return
	}

	// Huffman.
	if literalEncoding == fixedLiteralEncoding {
		w.writeFixedHeader(eof)
	} else {
		w.writeDynamicHeader(numLiterals, numOffsets, numCodegens, eof)
	}

	// Write the tokens.
	w.writeTokens(tokens.Slice(), literalEncoding.codes, offsetEncoding.codes)
}

// writeBlockDynamic encodes a block using a dynamic Huffman table.
// This should be used if the symbols used have a disproportionate
// histogram distribution.
// If input is supplied and the compression savings are below 1/16th of the
// input size the block is stored.
func (w *huffmanBitWriter) writeBlockDynamic(tokens *tokens, eof bool, input []byte, sync bool) {
	if w.err != nil {
		return
	}

	sync = sync || eof
	if sync {
		tokens.AddEOB()
	}

	// We cannot reuse pure huffman table, and must mark as EOF.
	if (w.lastHuffMan || eof) && w.lastHeader > 0 {
		// We will not try to reuse.
		w.writeCode(w.literalEncoding.codes[endBlockMarker])
		w.lastHeader = 0
		w.lastHuffMan = false
	}

	// fillReuse enables filling of empty values.
	// This will make encodings always reusable without testing.
	// However, this does not appear to benefit on most cases.
	const fillReuse = false

	// Check if we can reuse...
	if !fillReuse && w.lastHeader > 0 && !w.canReuse(tokens) {
		w.writeCode(w.literalEncoding.codes[endBlockMarker])
		w.lastHeader = 0
	}

	numLiterals, numOffsets := w.indexTokens(tokens, fillReuse && !sync)
	extraBits := 0
	ssize, storable := w.storedSize(input)

	const usePrefs = true
	if storable || w.lastHeader > 0 {
		extraBits = w.extraBitSize()
	}

	var size int

	// Check if we should reuse.
	if w.lastHeader > 0 {
		// Estimate size for using a new table.
		// Use the previous header size as the best estimate.
		newSize := w.lastHeader + tokens.EstimatedBits()
		newSize += int(w.literalEncoding.codes[endBlockMarker].len()) + newSize>>w.logNewTablePenalty

		// The estimated size is calculated as an optimal table.
		// We add a penalty to make it more realistic and re-use a bit more.
		reuseSize := w.dynamicReuseSize(w.literalEncoding, w.offsetEncoding) + extraBits

		// Check if a new table is better.
		if newSize < reuseSize {
			// Write the EOB we owe.
			w.writeCode(w.literalEncoding.codes[endBlockMarker])
			size = newSize
			w.lastHeader = 0
		} else {
			size = reuseSize
		}

		if tokens.n < maxPredefinedTokens {
			if preSize := w.fixedSize(extraBits) + 7; usePrefs && preSize < size {
				// Check if we get a reasonable size decrease.
				if storable && ssize <= size {
					w.writeStoredHeader(len(input), eof)
					w.writeBytes(input)
					return
				}
				w.writeFixedHeader(eof)
				if !sync {
					tokens.AddEOB()
				}
				w.writeTokens(tokens.Slice(), fixedLiteralEncoding.codes, fixedOffsetEncoding.codes)
				return
			}
		}
		// Check if we get a reasonable size decrease.
		if storable && ssize <= size {
			w.writeStoredHeader(len(input), eof)
			w.writeBytes(input)
			return
		}
	}

	// We want a new block/table
	if w.lastHeader == 0 {
		if fillReuse && !sync {
			w.fillTokens()
			numLiterals, numOffsets = maxNumLit, maxNumDist
		} else {
			w.literalFreq[endBlockMarker] = 1
		}

		w.generate()
		// Generate codegen and codegenFrequencies, which indicates how to encode
		// the literalEncoding and the offsetEncoding.
		w.generateCodegen(numLiterals, numOffsets, w.literalEncoding, w.offsetEncoding)
		w.codegenEncoding.generate(w.codegenFreq[:], 7)

		var numCodegens int
		if fillReuse && !sync {
			// Reindex for accurate size...
			w.indexTokens(tokens, true)
		}
		size, numCodegens = w.dynamicSize(w.literalEncoding, w.offsetEncoding, extraBits)

		// Store predefined, if we don't get a reasonable improvement.
		if tokens.n < maxPredefinedTokens {
			if preSize := w.fixedSize(extraBits); usePrefs && preSize <= size {
				// Store bytes, if we don't get an improvement.
				if storable && ssize <= preSize {
					w.writeStoredHeader(len(input), eof)
					w.writeBytes(input)
					return
				}
				w.writeFixedHeader(eof)
				if !sync {
					tokens.AddEOB()
				}
				w.writeTokens(tokens.Slice(), fixedLiteralEncoding.codes, fixedOffsetEncoding.codes)
				return
			}
		}

		if storable && ssize <= size {
			// Store bytes, if we don't get an improvement.
			w.writeStoredHeader(len(input), eof)
			w.writeBytes(input)
			return
		}

		// Write Huffman table.
		w.writeDynamicHeader(numLiterals, numOffsets, numCodegens, eof)
		if !sync {
			w.lastHeader, _ = w.headerSize()
		}
		w.lastHuffMan = false
	}

	if sync {
		w.lastHeader = 0
	}
	// Write the tokens.
	w.writeTokens(tokens.Slice(), w.literalEncoding.codes, w.offsetEncoding.codes)
}

func (w *huffmanBitWriter) fillTokens() {
	for i, v := range w.literalFreq[:literalCount] {
		if v == 0 {
			w.literalFreq[i] = 1
		}
	}
	for i, v := range w.offsetFreq[:offsetCodeCount] {
		if v == 0 {
			w.offsetFreq[i] = 1
		}
	}
}

// indexTokens indexes a slice of tokens, and updates
shell
sed -n '1,240p' flate/large_low_entropy_test.go
output
Chunk ID: 9bfc71
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 276
Output:
package flate

import (
	"bytes"
	stdflate "compress/flate"
	"io"
	"testing"
)

func TestLargeLowEntropyRoundTripVisible(t *testing.T) {
	input := make([]byte, 1<<20)

	var compressed bytes.Buffer
	w, err := NewWriter(&compressed, BestCompression)
	if err != nil {
		t.Fatalf("NewWriter: %v", err)
	}
	if _, err := w.Write(input); err != nil {
		t.Fatalf("Write: %v", err)
	}
	if err := w.Close(); err != nil {
		t.Fatalf("Close: %v", err)
	}

	stdReader := stdflate.NewReader(bytes.NewReader(compressed.Bytes()))
	stdOut, err := io.ReadAll(stdReader)
	_ = stdReader.Close()
	if err != nil {
		t.Fatalf("standard reader rejected stream: %v", err)
	}
	if !bytes.Equal(stdOut, input) {
		t.Fatalf("standard reader mismatch: got %d bytes, want %d", len(stdOut), len(input))
	}

	localReader := NewReader(bytes.NewReader(compressed.Bytes()))
	localOut, err := io.ReadAll(localReader)
	_ = localReader.Close()
	if err != nil {
		t.Fatalf("local reader rejected stream: %v", err)
	}
	if !bytes.Equal(localOut, input) {
		t.Fatalf("local reader mismatch: got %d bytes, want %d", len(localOut), len(input))
	}
}
write_stdin
{
  "session_id": 28995,
  "chars": "",
  "yield_time_ms": 1000,
  "max_output_tokens": 20000
}

, output, 
Chunk ID: e0f0f8
Wall time: 0.0000 seconds
Process exited with code 1
Original token count: 394
Output:
--- FAIL: TestDeflateInflateString (0.01s)
    deflate_test.go:387: open ../testdata/e.txt: no such file or directory
    deflate_test.go:320: level: 0 - Size:0.00%, 2 b
    deflate_test.go:320: level: 1 - Size:0.00%, 2 b
    deflate_test.go:320: level: 2 - Size:0.00%, 2 b
    deflate_test.go:320: level: 3 - Size:0.00%, 2 b
    deflate_test.go:320: level: 4 - Size:0.00%, 2 b
    deflate_test.go:320: level: 5 - Size:0.00%, 2 b
    deflate_test.go:320: level: 6 - Size:0.00%, 2 b
    deflate_test.go:320: level: 7 - Size:0.00%, 2 b
    deflate_test.go:320: level: 8 - Size:0.00%, 2 b
    deflate_test.go:320: level: 9 - Size:0.00%, 2 b
    deflate_test.go:320: level: -2 - Size:0.00%, 2 b
    deflate_test.go:387: open ../testdata/Mark.Twain-Tom.Sawyer.txt: no such file or directory
    deflate_test.go:320: level: 0 - Size:0.00%, 2 b
    deflate_test.go:320: level: 1 - Size:0.00%, 2 b
    deflate_test.go:320: level: 2 - Size:0.00%, 2 b
    deflate_test.go:320: level: 3 - Size:0.00%, 2 b
    deflate_test.go:320: level: 4 - Size:0.00%, 2 b
    deflate_test.go:320: level: 5 - Size:0.00%, 2 b
    deflate_test.go:320: level: 6 - Size:0.00%, 2 b
    deflate_test.go:320: level: 7 - Size:0.00%, 2 b
    deflate_test.go:320: level: 8 - Size:0.00%, 2 b
    deflate_test.go:320: level: 9 - Size:0.00%, 2 b
    deflate_test.go:320: level: -2 - Size:0.00%, 2 b
--- FAIL: TestLargeLowEntropyRoundTripVisible (0.56s)
    large_low_entropy_test.go:29: standard reader rejected stream: flate: corrupt input before offset 10
FAIL
FAIL	[code-host]/klauspost/compress/flate	6.071s
FAIL
The broad package test is failing only because the upstream `../testdata` corpora are absent, as expected. The generated low-entropy repro fails against the standard reader, so I’m narrowing the fix to the emitted block transition rather than the reader.
shell
rg -n "d\.h|writeBlockDynamic|writeBlock\(|lastHeader|lastHuffMan|writeBlockHuff|huffman" flate/deflate.go flate/huffman_bit_writer.go
output
Chunk ID: 9a5808
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 2245
Output:
flate/huffman_bit_writer.go:98:type huffmanBitWriter struct {
flate/huffman_bit_writer.go:109:	lastHuffMan     bool
flate/huffman_bit_writer.go:110:	literalEncoding *huffmanEncoder
flate/huffman_bit_writer.go:111:	tmpLitEncoding  *huffmanEncoder
flate/huffman_bit_writer.go:112:	offsetEncoding  *huffmanEncoder
flate/huffman_bit_writer.go:113:	codegenEncoding *huffmanEncoder
flate/huffman_bit_writer.go:115:	lastHeader      int
flate/huffman_bit_writer.go:129:// The huffmanBitWriter supports reusing huffman tables and thereby combining block sections.
flate/huffman_bit_writer.go:133:// If lastHeader is non-zero the Huffman table can be reused.
flate/huffman_bit_writer.go:139:// If lastHuffMan is set, a table for outputting literals has been generated and offsets are invalid.
flate/huffman_bit_writer.go:146:func newHuffmanBitWriter(w io.Writer) *huffmanBitWriter {
flate/huffman_bit_writer.go:147:	return &huffmanBitWriter{
flate/huffman_bit_writer.go:156:func (w *huffmanBitWriter) reset(writer io.Writer) {
flate/huffman_bit_writer.go:159:	w.lastHeader = 0
flate/huffman_bit_writer.go:160:	w.lastHuffMan = false
flate/huffman_bit_writer.go:163:func (w *huffmanBitWriter) canReuse(t *tokens) (ok bool) {
flate/huffman_bit_writer.go:192:func (w *huffmanBitWriter) flush() {
flate/huffman_bit_writer.go:197:	if w.lastHeader > 0 {
flate/huffman_bit_writer.go:200:		w.lastHeader = 0
flate/huffman_bit_writer.go:220:func (w *huffmanBitWriter) write(b []byte) {
flate/huffman_bit_writer.go:227:func (w *huffmanBitWriter) writeBits(b int32, nb uint8) {
flate/huffman_bit_writer.go:235:func (w *huffmanBitWriter) writeBytes(bytes []byte) {
flate/huffman_bit_writer.go:269:func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litEnc, offEnc *huffmanEncoder) {
flate/huffman_bit_writer.go:350:func (w *huffmanBitWriter) codegens() int {
flate/huffman_bit_writer.go:358:func (w *huffmanBitWriter) headerSize() (size, numCodegens int) {
flate/huffman_bit_writer.go:371:func (w *huffmanBitWriter) dynamicReuseSize(litEnc, offEnc *huffmanEncoder) (size int) {
flate/huffman_bit_writer.go:378:func (w *huffmanBitWriter) dynamicSize(litEnc, offEnc *huffmanEncoder, extraBits int) (size, numCodegens int) {
flate/huffman_bit_writer.go:389:func (w *huffmanBitWriter) extraBitSize() int {
flate/huffman_bit_writer.go:401:func (w *huffmanBitWriter) fixedSize(extraBits int) int {
flate/huffman_bit_writer.go:411:func (w *huffmanBitWriter) storedSize(in []byte) (int, bool) {
flate/huffman_bit_writer.go:421:func (w *huffmanBitWriter) writeCode(c hcode) {
flate/huffman_bit_writer.go:431:func (w *huffmanBitWriter) writeOutBits() {
flate/huffman_bit_writer.go:458:func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, numCodegens int, isEof bool) {
flate/huffman_bit_writer.go:501:// it is replaced with a fixed huffman block.
flate/huffman_bit_writer.go:502:func (w *huffmanBitWriter) writeStoredHeader(length int, isEof bool) {
flate/huffman_bit_writer.go:506:	if w.lastHeader > 0 {
flate/huffman_bit_writer.go:509:		w.lastHeader = 0
flate/huffman_bit_writer.go:531:func (w *huffmanBitWriter) writeFixedHeader(isEof bool) {
flate/huffman_bit_writer.go:535:	if w.lastHeader > 0 {
flate/huffman_bit_writer.go:538:		w.lastHeader = 0
flate/huffman_bit_writer.go:550:// The original input can be supplied, and if the huffman encoded data
flate/huffman_bit_writer.go:554:func (w *huffmanBitWriter) writeBlock(tokens *tokens, eof bool, input []byte) {
flate/huffman_bit_writer.go:560:	if w.lastHeader > 0 {
flate/huffman_bit_writer.go:563:		w.lastHeader = 0
flate/huffman_bit_writer.go:615:// writeBlockDynamic encodes a block using a dynamic Huffman table.
flate/huffman_bit_writer.go:620:func (w *huffmanBitWriter) writeBlockDynamic(tokens *tokens, eof bool, input []byte, sync bool) {
flate/huffman_bit_writer.go:630:	// We cannot reuse pure huffman table, and must mark as EOF.
flate/huffman_bit_writer.go:631:	if (w.lastHuffMan || eof) && w.lastHeader > 0 {
flate/huffman_bit_writer.go:634:		w.lastHeader = 0
flate/huffman_bit_writer.go:635:		w.lastHuffMan = false
flate/huffman_bit_writer.go:644:	if !fillReuse && w.lastHeader > 0 && !w.canReuse(tokens) {
flate/huffman_bit_writer.go:646:		w.lastHeader = 0
flate/huffman_bit_writer.go:654:	if storable || w.lastHeader > 0 {
flate/huffman_bit_writer.go:661:	if w.lastHeader > 0 {
flate/huffman_bit_writer.go:664:		newSize := w.lastHeader + tokens.EstimatedBits()
flate/huffman_bit_writer.go:676:			w.lastHeader = 0
flate/huffman_bit_writer.go:706:	if w.lastHeader == 0 {
flate/huffman_bit_writer.go:755:			w.lastHeader, _ = w.headerSize()
flate/huffman_bit_writer.go:757:		w.lastHuffMan = false
flate/huffman_bit_writer.go:761:		w.lastHeader = 0
flate/huffman_bit_writer.go:767:func (w *huffmanBitWriter) fillTokens() {
flate/huffman_bit_writer.go:784:func (w *huffmanBitWriter) indexTokens(t *tokens, filled bool) (numLiterals, numOffsets int) {
flate/huffman_bit_writer.go:809:		// we should count at least one offset to be sure that the offset huffman tree could be encoded.
flate/huffman_bit_writer.go:816:func (w *huffmanBitWriter) generate() {
flate/huffman_bit_writer.go:823:func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode) {
flate/huffman_bit_writer.go:972:// huffOffset is a static offset encoder used for huffman only encoding.
flate/huffman_bit_writer.go:974:var huffOffset *huffmanEncoder
flate/huffman_bit_writer.go:983:// writeBlockHuff encodes a block of bytes as either
flate/huffman_bit_writer.go:986:func (w *huffmanBitWriter) writeBlockHuff(eof bool, input []byte, sync bool) {
flate/huffman_bit_writer.go:995:	if !w.lastHuffMan {
flate/huffman_bit_writer.go:1037:		estBits += w.lastHeader
flate/huffman_bit_writer.go:1038:		if w.lastHeader == 0 {
flate/huffman_bit_writer.go:1054:	if w.lastHeader > 0 {
flate/huffman_bit_writer.go:1059:				fmt.Println("NOT reusing, reuse:", reuseSize/8, "> new:", estBits/8, "header est:", w.lastHeader/8, "bytes")
flate/huffman_bit_writer.go:1063:			w.lastHeader = 0
flate/huffman_bit_writer.go:1065:			fmt.Println("reusing, reuse:", reuseSize/8, "> new:", estBits/8, "- header est:", w.lastHeader/8)
flate/huffman_bit_writer.go:1070:	if w.lastHeader == 0 {
flate/huffman_bit_writer.go:1081:		w.lastHuffMan = true
flate/huffman_bit_writer.go:1082:		w.lastHeader, _ = w.headerSize()
flate/huffman_bit_writer.go:1084:			count += w.lastHeader
flate/huffman_bit_writer.go:1170:		w.lastHeader = 0
flate/huffman_bit_writer.go:1171:		w.lastHuffMan = false
flate/deflate.go:110:	h *huffmanEncoder
flate/deflate.go:111:	w *huffmanBitWriter
flate/deflate.go:172:func (d *compressor) writeBlock(tok *tokens, index int, eof bool) error {
flate/deflate.go:179:		//d.w.writeBlock(tok, eof, window)
flate/deflate.go:180:		d.w.writeBlockDynamic(tok, eof, window, d.sync)
flate/deflate.go:188:// only huffman encoded.
flate/deflate.go:194:			// we huffman compress the block.
flate/deflate.go:196:				d.w.writeBlockHuff(eof, window, d.sync)
flate/deflate.go:198:				// Write a dynamic huffman block.
flate/deflate.go:199:				d.w.writeBlockDynamic(tok, eof, window, d.sync)
flate/deflate.go:202:			d.w.writeBlock(tok, eof, nil)
flate/deflate.go:215:	// Do not fill window if we are in store-only or huffman mode.
flate/deflate.go:326:				newGain := d.h.bitLengthRaw(wPos[:n]) - int(offsetExtraBits[offsetCode(uint32(pos-i))]) - baseCost - int(lengthExtraBits[lengthCodes[(n-3)&255]])
flate/deflate.go:328:				//fmt.Println("gain:", newGain, "prev:", cGain, "raw:", d.h.bitLengthRaw(wPos[:n]), "this-len:", n, "prev-len:", length)
flate/deflate.go:419:		// Get literal huffman coder.
flate/deflate.go:420:		if d.h == nil {
flate/deflate.go:421:			d.h = newHuffmanEncoder(maxFlateBlockTokens)
flate/deflate.go:427:		d.h.generate(tmp[:], 15)
flate/deflate.go:452:					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:513:											if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:554:													if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:614:				if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:630:					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:647:							if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:667:						if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
flate/deflate.go:688:// fillWindow will fill the buffer with data for huffman-only compression.
flate/deflate.go:703:	d.w.writeBlockHuff(false, d.window[:d.windowEnd], d.sync)
flate/deflate.go:725:				d.w.writeBlockHuff(false, d.window[:d.windowEnd], true)
flate/deflate.go:739:		// If we removed less than 1/16th, huffman compress the block.
flate/deflate.go:741:		d.w.writeBlockHuff(false, d.window[:d.windowEnd], d.sync)
flate/deflate.go:744:		d.w.writeBlockDynamic(&d.tokens, false, d.window[:d.windowEnd], d.sync)
shell
sed -n '240,430p' flate/deflate.go
output
Chunk ID: 676440
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1252
Output:
		end := min(startindex+256+minMatchLength-1, n)
		tocheck := d.window[startindex:end]
		dstSize := len(tocheck) - minMatchLength + 1

		if dstSize <= 0 {
			continue
		}

		dst := s.hashMatch[:dstSize]
		bulkHash4(tocheck, dst)
		var newH uint32
		for i, val := range dst {
			di := i + startindex
			newH = val & hashMask
			// Get previous value with the same hash.
			// Our chain should point to the previous value.
			s.hashPrev[di&windowMask] = s.hashHead[newH]
			// Set the head of the hash chain to us.
			s.hashHead[newH] = uint32(di + s.hashOffset)
		}
	}
	// Update window information.
	d.windowEnd += n
	s.index = n
}

// Try to find a match starting at index whose length is greater than prevSize.
// We only look at chainCount possibilities before giving up.
// pos = s.index, prevHead = s.chainHead-s.hashOffset, prevLength=minMatchLength-1, lookahead
func (d *compressor) findMatch(pos int, prevHead int, lookahead int) (length, offset int, ok bool) {
	minMatchLook := min(lookahead, maxMatchLength)

	win := d.window[0 : pos+minMatchLook]

	// We quit when we get a match that's at least nice long
	nice := min(d.nice, len(win)-pos)

	// If we've got a match that's good enough, only look in 1/4 the chain.
	tries := d.chain
	length = minMatchLength - 1

	wEnd := win[pos+length]
	wPos := win[pos:]
	minIndex := max(pos-windowSize, 0)
	offset = 0

	if d.chain < 100 {
		for i := prevHead; tries > 0; tries-- {
			if wEnd == win[i+length] {
				n := matchLen(win[i:i+minMatchLook], wPos)
				if n > length {
					length = n
					offset = pos - i
					ok = true
					if n >= nice {
						// The match is good enough that we don't try to find a better one.
						break
					}
					wEnd = win[pos+n]
				}
			}
			if i <= minIndex {
				// hashPrev[i & windowMask] has already been overwritten, so stop now.
				break
			}
			i = int(d.state.hashPrev[i&windowMask]) - d.state.hashOffset
			if i < minIndex {
				break
			}
		}
		return
	}

	// Minimum gain to accept a match.
	cGain := 4

	// Some like it higher (CSV), some like it lower (JSON)
	const baseCost = 3
	// Base is 4 bytes at with an additional cost.
	// Matches must be better than this.

	for i := prevHead; tries > 0; tries-- {
		if wEnd == win[i+length] {
			n := matchLen(win[i:i+minMatchLook], wPos)
			if n > length {
				// Calculate gain. Estimate
				newGain := d.h.bitLengthRaw(wPos[:n]) - int(offsetExtraBits[offsetCode(uint32(pos-i))]) - baseCost - int(lengthExtraBits[lengthCodes[(n-3)&255]])

				//fmt.Println("gain:", newGain, "prev:", cGain, "raw:", d.h.bitLengthRaw(wPos[:n]), "this-len:", n, "prev-len:", length)
				if newGain > cGain {
					length = n
					offset = pos - i
					cGain = newGain
					ok = true
					if n >= nice {
						// The match is good enough that we don't try to find a better one.
						break
					}
					wEnd = win[pos+n]
				}
			}
		}
		if i <= minIndex {
			// hashPrev[i & windowMask] has already been overwritten, so stop now.
			break
		}
		i = int(d.state.hashPrev[i&windowMask]) - d.state.hashOffset
		if i < minIndex {
			break
		}
	}
	return
}

func (d *compressor) writeStoredBlock(buf []byte) error {
	if d.w.writeStoredHeader(len(buf), false); d.w.err != nil {
		return d.w.err
	}
	d.w.writeBytes(buf)
	return d.w.err
}

// hash4 returns a hash representation of the first 4 bytes
// of the supplied slice.
// The caller must ensure that len(b) >= 4.
func hash4(b []byte) uint32 {
	return hash4u(le.Load32(b, 0), hashBits)
}

// hash4 returns the hash of u to fit in a hash table with h bits.
// Preferably h should be a constant and should always be <32.
func hash4u(u uint32, h uint8) uint32 {
	return (u * prime4bytes) >> (32 - h)
}

// bulkHash4 will compute hashes using the same
// algorithm as hash4
func bulkHash4(b []byte, dst []uint32) {
	if len(b) < 4 {
		return
	}
	hb := le.Load32(b, 0)

	dst[0] = hash4u(hb, hashBits)
	end := len(b) - 4 + 1
	for i := 1; i < end; i++ {
		hb = (hb >> 8) | uint32(b[i+3])<<24
		dst[i] = hash4u(hb, hashBits)
	}
}

func (d *compressor) initDeflate() {
	d.window = make([]byte, 2*windowSize)
	d.byteAvailable = false
	d.err = nil
	if d.state == nil {
		return
	}
	s := d.state
	s.index = 0
	s.hashOffset = 1
	s.length = minMatchLength - 1
	s.offset = 0
	s.chainHead = -1
}

// deflateLazy is the same as deflate, but with d.fastSkipHashing == skipNever,
// meaning it always has lazy matching on.
func (d *compressor) deflateLazy() {
	s := d.state
	// Sanity enables additional runtime tests.
	// It's intended to be used during development
	// to supplement the currently ad-hoc unit tests.
	const sanity = debugDeflate

	if d.windowEnd-s.index < minMatchLength+maxMatchLength && !d.sync {
		return
	}
	if d.windowEnd != s.index && d.chain > 100 {
		// Get literal huffman coder.
		if d.h == nil {
			d.h = newHuffmanEncoder(maxFlateBlockTokens)
		}
		var tmp [256]uint16
		for _, v := range d.window[s.index:d.windowEnd] {
			tmp[v]++
		}
		d.h.generate(tmp[:], 15)
	}

	s.maxInsertIndex = d.windowEnd - (minMatchLength - 1)
shell
sed -n '430,560p' flate/huffman_bit_writer.go
output
Chunk ID: d2ca7c
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 726
Output:
// writeOutBits will write bits to the buffer.
func (w *huffmanBitWriter) writeOutBits() {
	bits := w.bits
	w.bits >>= 48
	w.nbits -= 48
	n := w.nbytes

	// We overwrite, but faster...
	le.Store64(w.bytes[:], n, bits)
	n += 6

	if n >= bufferFlushSize {
		if w.err != nil {
			n = 0
			return
		}
		w.write(w.bytes[:n])
		n = 0
	}

	w.nbytes = n
}

// Write the header of a dynamic Huffman block to the output stream.
//
//	numLiterals  The number of literals specified in codegen
//	numOffsets   The number of offsets specified in codegen
//	numCodegens  The number of codegens used in codegen
func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, numCodegens int, isEof bool) {
	if w.err != nil {
		return
	}
	var firstBits int32 = 4
	if isEof {
		firstBits = 5
	}
	w.writeBits(firstBits, 3)
	w.writeBits(int32(numLiterals-257), 5)
	w.writeBits(int32(numOffsets-1), 5)
	w.writeBits(int32(numCodegens-4), 4)

	for i := range numCodegens {
		value := uint(w.codegenEncoding.codes[codegenOrder[i]].len())
		w.writeBits(int32(value), 3)
	}

	i := 0
	for {
		var codeWord = uint32(w.codegen[i])
		i++
		if codeWord == badCode {
			break
		}
		w.writeCode(w.codegenEncoding.codes[codeWord])

		switch codeWord {
		case 16:
			w.writeBits(int32(w.codegen[i]), 2)
			i++
		case 17:
			w.writeBits(int32(w.codegen[i]), 3)
			i++
		case 18:
			w.writeBits(int32(w.codegen[i]), 7)
			i++
		}
	}
}

// writeStoredHeader will write a stored header.
// If the stored block is only used for EOF,
// it is replaced with a fixed huffman block.
func (w *huffmanBitWriter) writeStoredHeader(length int, isEof bool) {
	if w.err != nil {
		return
	}
	if w.lastHeader > 0 {
		// We owe an EOB
		w.writeCode(w.literalEncoding.codes[endBlockMarker])
		w.lastHeader = 0
	}

	// To write EOF, use a fixed encoding block. 10 bits instead of 5 bytes.
	if length == 0 && isEof {
		w.writeFixedHeader(isEof)
		// EOB: 7 bits, value: 0
		w.writeBits(0, 7)
		w.flush()
		return
	}

	var flag int32
	if isEof {
		flag = 1
	}
	w.writeBits(flag, 3)
	w.flush()
	w.writeBits(int32(length), 16)
	w.writeBits(int32(^uint16(length)), 16)
}

func (w *huffmanBitWriter) writeFixedHeader(isEof bool) {
	if w.err != nil {
		return
	}
	if w.lastHeader > 0 {
		// We owe an EOB
		w.writeCode(w.literalEncoding.codes[endBlockMarker])
		w.lastHeader = 0
	}

	// Indicate that we are a fixed Huffman block
	var value int32 = 2
	if isEof {
		value = 3
	}
	w.writeBits(value, 3)
}

// writeBlock will write a block of tokens with the smallest encoding.
// The original input can be supplied, and if the huffman encoded data
// is larger than the original bytes, the data will be written as a
// stored block.
// If the input is nil, the tokens will always be Huffman encoded.
func (w *huffmanBitWriter) writeBlock(tokens *tokens, eof bool, input []byte) {
	if w.err != nil {
		return
	}

	tokens.AddEOB()
	if w.lastHeader > 0 {
shell
sed -n '780,875p' flate/huffman_bit_writer.go
output
Chunk ID: faff54
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 639
Output:
// indexTokens indexes a slice of tokens, and updates
// literalFreq and offsetFreq, and generates literalEncoding
// and offsetEncoding.
// The number of literal and offset tokens is returned.
func (w *huffmanBitWriter) indexTokens(t *tokens, filled bool) (numLiterals, numOffsets int) {
	//copy(w.literalFreq[:], t.litHist[:])
	*(*[256]uint16)(w.literalFreq[:]) = t.litHist
	//copy(w.literalFreq[256:], t.extraHist[:])
	*(*[32]uint16)(w.literalFreq[256:]) = t.extraHist
	w.offsetFreq = t.offHist

	if t.n == 0 {
		return
	}
	if filled {
		return maxNumLit, maxNumDist
	}
	// get the number of literals
	numLiterals = len(w.literalFreq)
	for w.literalFreq[numLiterals-1] == 0 {
		numLiterals--
	}
	// get the number of offsets
	numOffsets = len(w.offsetFreq)
	for numOffsets > 0 && w.offsetFreq[numOffsets-1] == 0 {
		numOffsets--
	}
	if numOffsets == 0 {
		// We haven't found a single match. If we want to go with the dynamic encoding,
		// we should count at least one offset to be sure that the offset huffman tree could be encoded.
		w.offsetFreq[0] = 1
		numOffsets = 1
	}
	return
}

func (w *huffmanBitWriter) generate() {
	w.literalEncoding.generate(w.literalFreq[:literalCount], 15)
	w.offsetEncoding.generate(w.offsetFreq[:offsetCodeCount], 15)
}

// writeTokens writes a slice of tokens to the output.
// codes for literal and offset encoding must be supplied.
func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode) {
	if w.err != nil {
		return
	}
	if len(tokens) == 0 {
		return
	}

	// Only last token should be endBlockMarker.
	var deferEOB bool
	if tokens[len(tokens)-1] == endBlockMarker {
		tokens = tokens[:len(tokens)-1]
		deferEOB = true
	}

	// Create slices up to the next power of two to avoid bounds checks.
	lits := leCodes[:256]
	offs := oeCodes[:32]
	lengths := leCodes[lengthCodesStart:]
	lengths = lengths[:32]

	// Go 1.16 LOVES having these on stack.
	bits, nbits, nbytes := w.bits, w.nbits, w.nbytes

	for _, t := range tokens {
		if t < 256 {
			//w.writeCode(lits[t.literal()])
			c := lits[t]
			bits |= c.code64() << (nbits & 63)
			nbits += c.len()
			if nbits >= 48 {
				le.Store64(w.bytes[:], nbytes, bits)
				bits >>= 48
				nbits -= 48
				nbytes += 6
				if nbytes >= bufferFlushSize {
					if w.err != nil {
						nbytes = 0
						return
					}
					_, w.err = w.writer.Write(w.bytes[:nbytes])
					nbytes = 0
				}
			}
			continue
		}

		// Write the length
		length := t.length()
		lengthCode := lengthCode(length) & 31
		if false {
			w.writeCode(lengths[lengthCode])
		} else {
shell
go test ./flate -run TestLargeLowEntropyRoundTripVisible -count=1 -v
output
Chunk ID: 3991df
Wall time: 0.4649 seconds
Process exited with code 1
Original token count: 66
Output:
=== RUN   TestLargeLowEntropyRoundTripVisible
    large_low_entropy_test.go:29: standard reader rejected stream: flate: corrupt input before offset 10
--- FAIL: TestLargeLowEntropyRoundTripVisible (0.53s)
FAIL
FAIL	[code-host]/klauspost/compress/flate	0.531s
FAIL
The writer already closes a deferred dynamic block before switching to fixed or stored block headers, so the corrupt stream is more likely coming from mismatched block byte ranges when the high-compression path flushes tokens. I’m checking the exact compressed output and the boundary state around the failing case.
shell
sed -n '780,870p' flate/deflate.go
output
Chunk ID: 093dac
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 558
Output:
	}
	d.sync = false
	return d.err
}

func (d *compressor) init(w io.Writer, level int) (err error) {
	d.w = newHuffmanBitWriter(w)

	switch {
	case level == NoCompression:
		d.window = make([]byte, maxStoreBlockSize)
		d.fill = (*compressor).fillBlock
		d.step = (*compressor).store
	case level == ConstantCompression:
		d.w.logNewTablePenalty = 10
		d.window = make([]byte, 32<<10)
		d.fill = (*compressor).fillBlock
		d.step = (*compressor).storeHuff
	case level == DefaultCompression:
		level = 5
		fallthrough
	case level >= 1 && level <= 6:
		d.w.logNewTablePenalty = 7
		d.fast = newFastEnc(level)
		d.window = make([]byte, maxStoreBlockSize)
		d.fill = (*compressor).fillBlock
		d.step = (*compressor).storeFast
	case 7 <= level && level <= 9:
		d.w.logNewTablePenalty = 8
		d.state = &advancedState{}
		d.compressionLevel = levels[level]
		d.initDeflate()
		d.fill = (*compressor).fillDeflate
		d.step = (*compressor).deflateLazy
	case -level >= MinCustomWindowSize && -level <= MaxCustomWindowSize:
		d.w.logNewTablePenalty = 7
		d.fast = &fastEncL5Window{maxOffset: int32(-level), cur: maxStoreBlockSize}
		d.window = make([]byte, maxStoreBlockSize)
		d.fill = (*compressor).fillBlock
		d.step = (*compressor).storeFast
	default:
		return fmt.Errorf("flate: invalid compression level %d: want value in range [-2, 9]", level)
	}
	d.level = level
	return nil
}

// reset the state of the compressor.
func (d *compressor) reset(w io.Writer) {
	d.w.reset(w)
	d.sync = false
	d.err = nil
	// We only need to reset a few things for Snappy.
	if d.fast != nil {
		d.fast.Reset()
		d.windowEnd = 0
		d.tokens.Reset()
		return
	}
	switch d.compressionLevel.chain {
	case 0:
		// level was NoCompression or ConstantCompression.
		d.windowEnd = 0
	default:
		s := d.state
		s.chainHead = -1
		for i := range s.hashHead {
			s.hashHead[i] = 0
		}
		for i := range s.hashPrev {
			s.hashPrev[i] = 0
		}
		s.hashOffset = 1
		s.index, d.windowEnd = 0, 0
		d.blockStart, d.byteAvailable = 0, false
		d.tokens.Reset()
		s.length = minMatchLength - 1
		s.offset = 0
		s.ii = 0
		s.maxInsertIndex = 0
	}
}

func (d *compressor) close() error {
	if d.err != nil {
		return d.err
	}
	d.sync = true
	d.step(d)
	if d.err != nil {
		return d.err
shell
sed -n '870,940p' flate/deflate.go
output
Chunk ID: 512def
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 640
Output:
		return d.err
	}
	if d.w.writeStoredHeader(0, true); d.w.err != nil {
		return d.w.err
	}
	d.w.flush()
	d.w.reset(nil)
	return d.w.err
}

// NewWriter returns a new Writer compressing data at the given level.
// Following zlib, levels range from 1 (BestSpeed) to 9 (BestCompression);
// higher levels typically run slower but compress more.
// Level 0 (NoCompression) does not attempt any compression; it only adds the
// necessary DEFLATE framing.
// Level -1 (DefaultCompression) uses the default compression level.
// Level -2 (ConstantCompression) will use Huffman compression only, giving
// a very fast compression for all types of input, but sacrificing considerable
// compression efficiency.
//
// If level is in the range [-2, 9] then the error returned will be nil.
// Otherwise the error returned will be non-nil.
func NewWriter(w io.Writer, level int) (*Writer, error) {
	var dw Writer
	if err := dw.d.init(w, level); err != nil {
		return nil, err
	}
	return &dw, nil
}

// NewWriterDict is like NewWriter but initializes the new
// Writer with a preset dictionary.  The returned Writer behaves
// as if the dictionary had been written to it without producing
// any compressed output.  The compressed data written to w
// can only be decompressed by a Reader initialized with the
// same dictionary.
func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error) {
	zw, err := NewWriter(w, level)
	if err != nil {
		return nil, err
	}
	zw.d.fillWindow(dict)
	zw.dict = append(zw.dict, dict...) // duplicate dictionary for Reset method.
	return zw, err
}

// MinCustomWindowSize is the minimum window size that can be sent to NewWriterWindow.
const MinCustomWindowSize = 32

// MaxCustomWindowSize is the maximum custom window that can be sent to NewWriterWindow.
const MaxCustomWindowSize = windowSize

// NewWriterWindow returns a new Writer compressing data with a custom window size.
// windowSize must be from MinCustomWindowSize to MaxCustomWindowSize.
func NewWriterWindow(w io.Writer, windowSize int) (*Writer, error) {
	if windowSize < MinCustomWindowSize {
		return nil, errors.New("flate: requested window size less than MinWindowSize")
	}
	if windowSize > MaxCustomWindowSize {
		return nil, errors.New("flate: requested window size bigger than MaxCustomWindowSize")
	}
	var dw Writer
	if err := dw.d.init(w, -windowSize); err != nil {
		return nil, err
	}
	return &dw, nil
}

// A Writer takes data written to it and writes the compressed
// form of that data to an underlying writer (see NewWriter).
type Writer struct {
shell
sed -n '940,1095p' flate/huffman_bit_writer.go
output
Chunk ID: 15f3a1
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1058
Output:
			}
		}

		if offsetCode >= offsetExtraBitsMinCode {
			offsetComb := offsetCombined[offsetCode]
			//w.writeBits(extraOffset, extraOffsetBits)
			bits |= uint64((offset-(offsetComb>>8))&matchOffsetOnlyMask) << (nbits & 63)
			nbits += uint8(offsetComb)
			if nbits >= 48 {
				le.Store64(w.bytes[:], nbytes, bits)
				bits >>= 48
				nbits -= 48
				nbytes += 6
				if nbytes >= bufferFlushSize {
					if w.err != nil {
						nbytes = 0
						return
					}
					_, w.err = w.writer.Write(w.bytes[:nbytes])
					nbytes = 0
				}
			}
		}
	}
	// Restore...
	w.bits, w.nbits, w.nbytes = bits, nbits, nbytes

	if deferEOB {
		w.writeCode(leCodes[endBlockMarker])
	}
}

// huffOffset is a static offset encoder used for huffman only encoding.
// It can be reused since we will not be encoding offset values.
var huffOffset *huffmanEncoder

func init() {
	w := newHuffmanBitWriter(nil)
	w.offsetFreq[0] = 1
	huffOffset = newHuffmanEncoder(offsetCodeCount)
	huffOffset.generate(w.offsetFreq[:offsetCodeCount], 15)
}

// writeBlockHuff encodes a block of bytes as either
// Huffman encoded literals or uncompressed bytes if the
// results only gains very little from compression.
func (w *huffmanBitWriter) writeBlockHuff(eof bool, input []byte, sync bool) {
	if w.err != nil {
		return
	}

	// Clear histogram
	for i := range w.literalFreq[:] {
		w.literalFreq[i] = 0
	}
	if !w.lastHuffMan {
		for i := range w.offsetFreq[:] {
			w.offsetFreq[i] = 0
		}
	}

	const numLiterals = endBlockMarker + 1
	const numOffsets = 1

	// Add everything as literals
	// We have to estimate the header size.
	// Assume header is around 70 bytes:
	// https://stackoverflow.com/a/25454430
	const guessHeaderSizeBits = 70 * 8
	histogram(input, w.literalFreq[:numLiterals])
	ssize, storable := w.storedSize(input)
	if storable && len(input) > 1024 {
		// Quick check for incompressible content.
		abs := float64(0)
		avg := float64(len(input)) / 256
		max := float64(len(input) * 2)
		for _, v := range w.literalFreq[:256] {
			diff := float64(v) - avg
			abs += diff * diff
			if abs > max {
				break
			}
		}
		if abs < max {
			if debugDeflate {
				fmt.Println("stored", abs, "<", max)
			}
			// No chance we can compress this...
			w.writeStoredHeader(len(input), eof)
			w.writeBytes(input)
			return
		}
	}
	w.literalFreq[endBlockMarker] = 1
	w.tmpLitEncoding.generate(w.literalFreq[:numLiterals], 15)
	estBits := w.tmpLitEncoding.canReuseBits(w.literalFreq[:numLiterals])
	if estBits < math.MaxInt32 {
		estBits += w.lastHeader
		if w.lastHeader == 0 {
			estBits += guessHeaderSizeBits
		}
		estBits += estBits >> w.logNewTablePenalty
	}

	// Store bytes, if we don't get a reasonable improvement.
	if storable && ssize <= estBits {
		if debugDeflate {
			fmt.Println("stored,", ssize, "<=", estBits)
		}
		w.writeStoredHeader(len(input), eof)
		w.writeBytes(input)
		return
	}

	if w.lastHeader > 0 {
		reuseSize := w.literalEncoding.canReuseBits(w.literalFreq[:256])

		if estBits < reuseSize {
			if debugDeflate {
				fmt.Println("NOT reusing, reuse:", reuseSize/8, "> new:", estBits/8, "header est:", w.lastHeader/8, "bytes")
			}
			// We owe an EOB
			w.writeCode(w.literalEncoding.codes[endBlockMarker])
			w.lastHeader = 0
		} else if debugDeflate {
			fmt.Println("reusing, reuse:", reuseSize/8, "> new:", estBits/8, "- header est:", w.lastHeader/8)
		}
	}

	count := 0
	if w.lastHeader == 0 {
		// Use the temp encoding, so swap.
		w.literalEncoding, w.tmpLitEncoding = w.tmpLitEncoding, w.literalEncoding
		// Generate codegen and codegenFrequencies, which indicates how to encode
		// the literalEncoding and the offsetEncoding.
		w.generateCodegen(numLiterals, numOffsets, w.literalEncoding, huffOffset)
		w.codegenEncoding.generate(w.codegenFreq[:], 7)
		numCodegens := w.codegens()

		// Huffman.
		w.writeDynamicHeader(numLiterals, numOffsets, numCodegens, eof)
		w.lastHuffMan = true
		w.lastHeader, _ = w.headerSize()
		if debugDeflate {
			count += w.lastHeader
			fmt.Println("header:", count/8)
		}
	}

	encoding := w.literalEncoding.codes[:256]
	// Go 1.16 LOVES having these on stack. At least 1.5x the speed.
	bits, nbits, nbytes := w.bits, w.nbits, w.nbytes

	if debugDeflate {
		count -= int(nbytes)*8 + int(nbits)
	}
shell
go test ./flate -run TestLargeLowEntropyRoundTripVisible -count=1 -v 2>&1 | sed -n '1,80p'
output
Chunk ID: 30c5d6
Wall time: 0.4654 seconds
Process exited with code 0
Original token count: 66
Output:
=== RUN   TestLargeLowEntropyRoundTripVisible
    large_low_entropy_test.go:29: standard reader rejected stream: flate: corrupt input before offset 10
--- FAIL: TestLargeLowEntropyRoundTripVisible (0.53s)
FAIL
FAIL	[code-host]/klauspost/compress/flate	0.529s
FAIL
shell
git status --short
output
Chunk ID: 494d1b
Wall time: 0.0000 seconds
Process exited with code 128
Original token count: 18
Output:
fatal: not a git repository (or any of the parent directories): .git
shell
git diff -- flate/large_low_entropy_test.go flate/deflate.go flate/huffman_bit_writer.go
output
Chunk ID: 5a068c
Wall time: 0.0000 seconds
Process exited with code 129
Original token count: 1817
Output:
warning: Not a git repository. Use --no-index to compare two paths outside a working tree
usage: git diff --no-index [<options>] <path> <path>

Diff output format options
    -p, --patch           generate patch
    -s, --no-patch        suppress diff output
    -u                    generate patch
    -U, --unified[=<n>]   generate diffs with <n> lines context
    -W, --function-context
                          generate diffs with <n> lines context
    --raw                 generate the diff in raw format
    --patch-with-raw      synonym for '-p --raw'
    --patch-with-stat     synonym for '-p --stat'
    --numstat             machine friendly --stat
    --shortstat           output only the last line of --stat
    -X, --dirstat[=<param1,param2>...]
                          output the distribution of relative amount of changes for each sub-directory
    --cumulative          synonym for --dirstat=cumulative
    --dirstat-by-file[=<param1,param2>...]
                          synonym for --dirstat=files,param1,param2...
    --check               warn if changes introduce conflict markers or whitespace errors
    --summary             condensed summary such as creations, renames and mode changes
    --name-only           show only names of changed files
    --name-status         show only names and status of changed files
    --stat[=<width>[,<name-width>[,<count>]]]
                          generate diffstat
    --stat-width <width>  generate diffstat with a given width
    --stat-name-width <width>
                          generate diffstat with a given name width
    --stat-graph-width <width>
                          generate diffstat with a given graph width
    --stat-count <count>  generate diffstat with limited lines
    --compact-summary     generate compact summary in diffstat
    --binary              output a binary diff that can be applied
    --full-index          show full pre- and post-image object names on the "index" lines
    --color[=<when>]      show colored diff
    --ws-error-highlight <kind>
                          highlight whitespace errors in the 'context', 'old' or 'new' lines in the diff
    -z                    do not munge pathnames and use NULs as output field terminators in --raw or --numstat
    --abbrev[=<n>]        use <n> digits to display object names
    --src-prefix <prefix>
                          show the given source prefix instead of "a/"
    --dst-prefix <prefix>
                          show the given destination prefix instead of "b/"
    --line-prefix <prefix>
                          prepend an additional prefix to every line of output
    --no-prefix           do not show any source or destination prefix
    --inter-hunk-context <n>
                          show context between diff hunks up to the specified number of lines
    --output-indicator-new <char>
                          specify the character to indicate a new line instead of '+'
    --output-indicator-old <char>
                          specify the character to indicate an old line instead of '-'
    --output-indicator-context <char>
                          specify the character to indicate a context instead of ' '

Diff rename options
    -B, --break-rewrites[=<n>[/<m>]]
                          break complete rewrite changes into pairs of delete and create
    -M, --find-renames[=<n>]
                          detect renames
    -D, --irreversible-delete
                          omit the preimage for deletes
    -C, --find-copies[=<n>]
                          detect copies
    --find-copies-harder  use unmodified files as source to find copies
    --no-renames          disable rename detection
    --rename-empty        use empty blobs as rename source
    --follow              continue listing the history of a file beyond renames
    -l <n>                prevent rename/copy detection if the number of rename/copy targets exceeds given limit

Diff algorithm options
    --minimal             produce the smallest possible diff
    -w, --ignore-all-space
                          ignore whitespace when comparing lines
    -b, --ignore-space-change
                          ignore changes in amount of whitespace
    --ignore-space-at-eol
                          ignore changes in whitespace at EOL
    --ignore-cr-at-eol    ignore carrier-return at the end of line
    --ignore-blank-lines  ignore changes whose lines are all blank
    -I, --ignore-matching-lines <regex>
                          ignore changes whose all lines match <regex>
    --indent-heuristic    heuristic to shift diff hunk boundaries for easy reading
    --patience            generate diff using the "patience diff" algorithm
    --histogram           generate diff using the "histogram diff" algorithm
    --diff-algorithm <algorithm>
                          choose a diff algorithm
    --anchored <text>     generate diff using the "anchored diff" algorithm
    --word-diff[=<mode>]  show word diff, using <mode> to delimit changed words
    --word-diff-regex <regex>
                          use <regex> to decide what a word is
    --color-words[=<regex>]
                          equivalent to --word-diff=color --word-diff-regex=<regex>
    --color-moved[=<mode>]
                          moved lines of code are colored differently
    --color-moved-ws <mode>
                          how white spaces are ignored in --color-moved

Other diff options
    --relative[=<prefix>]
                          when run from subdir, exclude changes outside and show relative paths
    -a, --text            treat all files as text
    -R                    swap two inputs, reverse the diff
    --exit-code           exit with 1 if there were differences, 0 otherwise
    --quiet               disable all output of the program
    --ext-diff            allow an external diff helper to be executed
    --textconv            run external text conversion filters when comparing binary files
    --ignore-submodules[=<when>]
                          ignore changes to submodules in the diff generation
    --submodule[=<format>]
                          specify how differences in submodules are shown
    --ita-[redacted source]-in-index
                          hide 'git add -N' entries from the index
    --ita-visible-in-index
                          treat 'git add -N' entries as real in the index
    -S <string>           look for differences that change the number of occurrences of the specified string
    -G <regex>            look for differences that change the number of occurrences of the specified regex
    --pickaxe-all         show all changes in the changeset with -S or -G
    --pickaxe-regex       treat <string> in -S as extended POSIX regular expression
    -O <file>             control the order in which files appear in the output
    --rotate-to <path>    show the change in the specified path first
    --skip-to <path>      skip the output to the specified path
    --find-object <object-id>
                          look for differences that change the number of occurrences of the specified object
    --diff-filter [(A|C|D|M|R|T|U|X|B)...[*]]
                          select files by diff type
    --output <file>       output to a specific file

shell
go test ./flate -run TestHuffmanBitWriter -count=1
output
Chunk ID: 8b533f
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 17
Output:
ok  	[code-host]/klauspost/compress/flate	0.001s [no tests to run]
shell
go env GOROOT GOMOD GOPATH GOVERSION
output
Chunk ID: a10371
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 10
Output:
/usr/local/go
/app/go.mod
/go
go1.26.4
shell
rg -n "func \(d \*compressor\) deflate|deflateLazy|writeBlock" $(go env GOROOT)/src/compress/flate/deflate.go
output
Chunk ID: d0e283
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 148
Output:
166:func (d *compressor) writeBlock(tokens []token, index int) error {
173:		d.w.writeBlock(tokens, false, window)
349:				d.w.writeBlockHuff(false, d.window[:d.windowEnd])
363:		d.w.writeBlockHuff(false, d.window[:d.windowEnd])
365:		d.w.writeBlockDynamic(d.tokens, false, d.window[:d.windowEnd])
383:func (d *compressor) deflate() {
411:					if d.err = d.writeBlock(d.tokens, d.index); d.err != nil {
489:				if d.err = d.writeBlock(d.tokens, d.index); d.err != nil {
502:					if d.err = d.writeBlock(d.tokens, i+1); d.err != nil {
536:	d.w.writeBlockHuff(false, d.window[:d.windowEnd])
shell
sed -n '330,620p' $(go env GOROOT)/src/compress/flate/deflate.go
output
Chunk ID: e66b0a
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1965
Output:

// encSpeed will compress and store the currently added data,
// if enough has been accumulated or we at the end of the stream.
// Any error that occurred will be in d.err
func (d *compressor) encSpeed() {
	// We only compress if we have maxStoreBlockSize.
	if d.windowEnd < maxStoreBlockSize {
		if !d.sync {
			return
		}

		// Handle small sizes.
		if d.windowEnd < 128 {
			switch {
			case d.windowEnd == 0:
				return
			case d.windowEnd <= 16:
				d.err = d.writeStoredBlock(d.window[:d.windowEnd])
			default:
				d.w.writeBlockHuff(false, d.window[:d.windowEnd])
				d.err = d.w.err
			}
			d.windowEnd = 0
			d.bestSpeed.reset()
			return
		}

	}
	// Encode the block.
	d.tokens = d.bestSpeed.encode(d.tokens[:0], d.window[:d.windowEnd])

	// If we removed less than 1/16th, Huffman compress the block.
	if len(d.tokens) > d.windowEnd-(d.windowEnd>>4) {
		d.w.writeBlockHuff(false, d.window[:d.windowEnd])
	} else {
		d.w.writeBlockDynamic(d.tokens, false, d.window[:d.windowEnd])
	}
	d.err = d.w.err
	d.windowEnd = 0
}

func (d *compressor) initDeflate() {
	d.window = make([]byte, 2*windowSize)
	d.hashOffset = 1
	d.tokens = make([]token, 0, maxFlateBlockTokens+1)
	d.length = minMatchLength - 1
	d.offset = 0
	d.byteAvailable = false
	d.index = 0
	d.chainHead = -1
	d.bulkHasher = bulkHash4
}

func (d *compressor) deflate() {
	if d.windowEnd-d.index < minMatchLength+maxMatchLength && !d.sync {
		return
	}

	d.maxInsertIndex = d.windowEnd - (minMatchLength - 1)

Loop:
	for {
		if d.index > d.windowEnd {
			panic("index > windowEnd")
		}
		lookahead := d.windowEnd - d.index
		if lookahead < minMatchLength+maxMatchLength {
			if !d.sync {
				break Loop
			}
			if d.index > d.windowEnd {
				panic("index > windowEnd")
			}
			if lookahead == 0 {
				// Flush current output block if any.
				if d.byteAvailable {
					// There is still one pending token that needs to be flushed
					d.tokens = append(d.tokens, literalToken(uint32(d.window[d.index-1])))
					d.byteAvailable = false
				}
				if len(d.tokens) > 0 {
					if d.err = d.writeBlock(d.tokens, d.index); d.err != nil {
						return
					}
					d.tokens = d.tokens[:0]
				}
				break Loop
			}
		}
		if d.index < d.maxInsertIndex {
			// Update the hash
			hash := hash4(d.window[d.index : d.index+minMatchLength])
			hh := &d.hashHead[hash&hashMask]
			d.chainHead = int(*hh)
			d.hashPrev[d.index&windowMask] = uint32(d.chainHead)
			*hh = uint32(d.index + d.hashOffset)
		}
		prevLength := d.length
		prevOffset := d.offset
		d.length = minMatchLength - 1
		d.offset = 0
		minIndex := d.index - windowSize
		if minIndex < 0 {
			minIndex = 0
		}

		if d.chainHead-d.hashOffset >= minIndex &&
			(d.fastSkipHashing != skipNever && lookahead > minMatchLength-1 ||
				d.fastSkipHashing == skipNever && lookahead > prevLength && prevLength < d.lazy) {
			if newLength, newOffset, ok := d.findMatch(d.index, d.chainHead-d.hashOffset, minMatchLength-1, lookahead); ok {
				d.length = newLength
				d.offset = newOffset
			}
		}
		if d.fastSkipHashing != skipNever && d.length >= minMatchLength ||
			d.fastSkipHashing == skipNever && prevLength >= minMatchLength && d.length <= prevLength {
			// There was a match at the previous step, and the current match is
			// not better. Output the previous match.
			if d.fastSkipHashing != skipNever {
				d.tokens = append(d.tokens, matchToken(uint32(d.length-baseMatchLength), uint32(d.offset-baseMatchOffset)))
			} else {
				d.tokens = append(d.tokens, matchToken(uint32(prevLength-baseMatchLength), uint32(prevOffset-baseMatchOffset)))
			}
			// Insert in the hash table all strings up to the end of the match.
			// index and index-1 are already inserted. If there is not enough
			// lookahead, the last two strings are not inserted into the hash
			// table.
			if d.length <= d.fastSkipHashing {
				var newIndex int
				if d.fastSkipHashing != skipNever {
					newIndex = d.index + d.length
				} else {
					newIndex = d.index + prevLength - 1
				}
				index := d.index
				for index++; index < newIndex; index++ {
					if index < d.maxInsertIndex {
						hash := hash4(d.window[index : index+minMatchLength])
						// Get previous value with the same hash.
						// Our chain should point to the previous value.
						hh := &d.hashHead[hash&hashMask]
						d.hashPrev[index&windowMask] = *hh
						// Set the head of the hash chain to us.
						*hh = uint32(index + d.hashOffset)
					}
				}
				d.index = index

				if d.fastSkipHashing == skipNever {
					d.byteAvailable = false
					d.length = minMatchLength - 1
				}
			} else {
				// For matches this long, we don't bother inserting each individual
				// item into the table.
				d.index += d.length
			}
			if len(d.tokens) == maxFlateBlockTokens {
				// The block includes the current character
				if d.err = d.writeBlock(d.tokens, d.index); d.err != nil {
					return
				}
				d.tokens = d.tokens[:0]
			}
		} else {
			if d.fastSkipHashing != skipNever || d.byteAvailable {
				i := d.index - 1
				if d.fastSkipHashing != skipNever {
					i = d.index
				}
				d.tokens = append(d.tokens, literalToken(uint32(d.window[i])))
				if len(d.tokens) == maxFlateBlockTokens {
					if d.err = d.writeBlock(d.tokens, i+1); d.err != nil {
						return
					}
					d.tokens = d.tokens[:0]
				}
			}
			d.index++
			if d.fastSkipHashing == skipNever {
				d.byteAvailable = true
			}
		}
	}
}

func (d *compressor) fillStore(b []byte) int {
	n := copy(d.window[d.windowEnd:], b)
	d.windowEnd += n
	return n
}

func (d *compressor) store() {
	if d.windowEnd > 0 && (d.windowEnd == maxStoreBlockSize || d.sync) {
		d.err = d.writeStoredBlock(d.window[:d.windowEnd])
		d.windowEnd = 0
	}
}

// storeHuff compresses and stores the currently added data
// when the d.window is full or we are at the end of the stream.
// Any error that occurred will be in d.err
func (d *compressor) storeHuff() {
	if d.windowEnd < len(d.window) && !d.sync || d.windowEnd == 0 {
		return
	}
	d.w.writeBlockHuff(false, d.window[:d.windowEnd])
	d.err = d.w.err
	d.windowEnd = 0
}

func (d *compressor) write(b []byte) (n int, err error) {
	if d.err != nil {
		return 0, d.err
	}
	n = len(b)
	for len(b) > 0 {
		d.step(d)
		b = b[d.fill(d, b):]
		if d.err != nil {
			return 0, d.err
		}
	}
	return n, nil
}

func (d *compressor) syncFlush() error {
	if d.err != nil {
		return d.err
	}
	d.sync = true
	d.step(d)
	if d.err == nil {
		d.w.writeStoredHeader(0, false)
		d.w.flush()
		d.err = d.w.err
	}
	d.sync = false
	return d.err
}

func (d *compressor) init(w io.Writer, level int) (err error) {
	d.w = newHuffmanBitWriter(w)

	switch {
	case level == NoCompression:
		d.window = make([]byte, maxStoreBlockSize)
		d.fill = (*compressor).fillStore
		d.step = (*compressor).store
	case level == HuffmanOnly:
		d.window = make([]byte, maxStoreBlockSize)
		d.fill = (*compressor).fillStore
		d.step = (*compressor).storeHuff
	case level == BestSpeed:
		d.compressionLevel = levels[level]
		d.window = make([]byte, maxStoreBlockSize)
		d.fill = (*compressor).fillStore
		d.step = (*compressor).encSpeed
		d.bestSpeed = newDeflateFast()
		d.tokens = make([]token, maxStoreBlockSize)
	case level == DefaultCompression:
		level = 6
		fallthrough
	case 2 <= level && level <= 9:
		d.compressionLevel = levels[level]
		d.initDeflate()
		d.fill = (*compressor).fillDeflate
		d.step = (*compressor).deflate
	default:
		return fmt.Errorf("flate: invalid compression level %d: want value in range [-2, 9]", level)
	}
	return nil
}

func (d *compressor) reset(w io.Writer) {
	d.w.reset(w)
	d.sync = false
	d.err = nil
	switch d.compressionLevel.level {
	case NoCompression:
		d.windowEnd = 0
	case BestSpeed:
		d.windowEnd = 0
		d.tokens = d.tokens[:0]
		d.bestSpeed.reset()
	default:
		d.chainHead = -1
		clear(d.hashHead[:])
		clear(d.hashPrev[:])
		d.hashOffset = 1
		d.index, d.windowEnd = 0, 0
The standard library’s simpler lazy path passes the literal boundary as `i+1` for full literal blocks and the match end for full match blocks. The local fork adds more lookahead and block reuse, so I’m checking places where a token flush happens before the encoded byte boundary is advanced.
shell
sed -n '150,185p' $(go env GOROOT)/src/compress/flate/deflate.go
output
Chunk ID: 509f4d
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 209
Output:
				}
			}
			for i, v := range d.hashHead[:] {
				if int(v) > delta {
					d.hashHead[i] = uint32(int(v) - delta)
				} else {
					d.hashHead[i] = 0
				}
			}
		}
	}
	n := copy(d.window[d.windowEnd:], b)
	d.windowEnd += n
	return n
}

func (d *compressor) writeBlock(tokens []token, index int) error {
	if index > 0 {
		var window []byte
		if d.blockStart <= index {
			window = d.window[d.blockStart:index]
		}
		d.blockStart = index
		d.w.writeBlock(tokens, false, window)
		return d.w.err
	}
	return nil
}

// fillWindow will fill the current window with the supplied
// dictionary and calculate all hashes.
// This is much faster than doing a full encode.
// Should only be used after a reset.
func (d *compressor) fillWindow(b []byte) {
	// Do not fill window if we are in store-only mode.
	if d.compressionLevel.level < 2 {
shell
rg -n "writeBlock\(&d\.tokens, s\.index|AddLiteral|AddMatch" flate/deflate.go
output
Chunk ID: 073ab8
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 237
Output:
448:					d.tokens.AddLiteral(d.window[s.index-1])
452:					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
510:										d.tokens.AddLiteral(d.window[prevIndex+j])
513:											if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
551:												d.tokens.AddLiteral(d.window[prevIndex+j])
554:													if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
581:			d.tokens.AddMatch(uint32(prevLength-3), uint32(prevOffset-minOffsetSize))
614:				if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
628:				d.tokens.AddLiteral(d.window[s.index-1])
630:					if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
645:						d.tokens.AddLiteral(d.window[s.index-1])
647:							if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
663:					d.tokens.AddLiteral(d.window[s.index-1])
667:						if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
shell
sed -n '690,760p' flate/deflate.go
output
Chunk ID: 380845
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 496
Output:
func (d *compressor) fillBlock(b []byte) int {
	n := copy(d.window[d.windowEnd:], b)
	d.windowEnd += n
	return n
}

// storeHuff will compress and store the currently added data,
// if enough has been accumulated or we at the end of the stream.
// Any error that occurred will be in d.err
func (d *compressor) storeHuff() {
	if d.windowEnd < len(d.window) && !d.sync || d.windowEnd == 0 {
		return
	}
	d.w.writeBlockHuff(false, d.window[:d.windowEnd], d.sync)
	d.err = d.w.err
	d.windowEnd = 0
}

// storeFast will compress and store the currently added data,
// if enough has been accumulated or we at the end of the stream.
// Any error that occurred will be in d.err
func (d *compressor) storeFast() {
	// We only compress if we have maxStoreBlockSize.
	if d.windowEnd < len(d.window) {
		if !d.sync {
			return
		}
		// Handle extremely small sizes.
		if d.windowEnd < 128 {
			if d.windowEnd == 0 {
				return
			}
			if d.windowEnd <= 32 {
				d.err = d.writeStoredBlock(d.window[:d.windowEnd])
			} else {
				d.w.writeBlockHuff(false, d.window[:d.windowEnd], true)
				d.err = d.w.err
			}
			d.tokens.Reset()
			d.windowEnd = 0
			d.fast.Reset()
			return
		}
	}

	d.fast.Encode(&d.tokens, d.window[:d.windowEnd])
	// If we made zero matches, store the block as is.
	if d.tokens.n == 0 {
		d.err = d.writeStoredBlock(d.window[:d.windowEnd])
		// If we removed less than 1/16th, huffman compress the block.
	} else if int(d.tokens.n) > d.windowEnd-(d.windowEnd>>4) {
		d.w.writeBlockHuff(false, d.window[:d.windowEnd], d.sync)
		d.err = d.w.err
	} else {
		d.w.writeBlockDynamic(&d.tokens, false, d.window[:d.windowEnd], d.sync)
		d.err = d.w.err
	}
	d.tokens.Reset()
	d.windowEnd = 0
}

// write will add input byte to the stream.
// Unless an error occurs all bytes will be consumed.
func (d *compressor) write(b []byte) (n int, err error) {
	if d.err != nil {
		return 0, d.err
	}
	n = len(b)
	for len(b) > 0 {
		if d.windowEnd == len(d.window) || d.sync {
			d.step(d)
I’m going to add temporary diagnostics to the focused test to print the compressed prefix and local-reader behavior, then remove that debug output once the failing block shape is clear.
apply_patch
*** Begin Patch
*** Update File: flate/large_low_entropy_test.go
@@
 	if err := w.Close(); err != nil {
 		t.Fatalf("Close: %v", err)
 	}
+	t.Logf("compressed len=%d prefix=% x", compressed.Len(), compressed.Bytes()[:min(compressed.Len(), 32)])
+
+	localReader := NewReader(bytes.NewReader(compressed.Bytes()))
+	localOut, localErr := io.ReadAll(localReader)
+	_ = localReader.Close()
+	t.Logf("local err=%v len=%d", localErr, len(localOut))
 
 	stdReader := stdflate.NewReader(bytes.NewReader(compressed.Bytes()))
 	stdOut, err := io.ReadAll(stdReader)
@@
-	localReader := NewReader(bytes.NewReader(compressed.Bytes()))
-	localOut, err := io.ReadAll(localReader)
-	_ = localReader.Close()
+	localReader = NewReader(bytes.NewReader(compressed.Bytes()))
+	localOut, err = io.ReadAll(localReader)
+	_ = localReader.Close()
*** End Patch


Exit code: 0
Wall time: 0 seconds
Output:
Success. Updated the following files:
M flate/large_low_entropy_test.go
shell
go test ./flate -run TestLargeLowEntropyRoundTripVisible -count=1 -v
output
Chunk ID: 5049a2
Wall time: 0.7056 seconds
Process exited with code 1
Original token count: 127
Output:
=== RUN   TestLargeLowEntropyRoundTripVisible
    large_low_entropy_test.go:24: compressed len=9184 prefix=04 f8 ff ff ff ff ff ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    large_low_entropy_test.go:29: local err=flate: corrupt input before offset 10 len=0
    large_low_entropy_test.go:35: standard reader rejected stream: flate: corrupt input before offset 10
--- FAIL: TestLargeLowEntropyRoundTripVisible (0.53s)
FAIL
FAIL	[code-host]/klauspost/compress/flate	0.527s
FAIL
The stream starts as a dynamic block and both readers fail before producing output, so this is not a final stored-block transition. I’m checking the dynamic Huffman table generation for the all-zero block, especially the case with a very small literal alphabet and one distance symbol.
shell
go test ./flate -run 'Test.*Huffman|TestHuffman.*|Test.*Golden|TestLargeLowEntropy' -count=1 -v
output
Chunk ID: 6ddb18
Wall time: 0.4771 seconds
Process exited with code 1
Original token count: 127
Output:
=== RUN   TestLargeLowEntropyRoundTripVisible
    large_low_entropy_test.go:24: compressed len=9184 prefix=04 f8 ff ff ff ff ff ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    large_low_entropy_test.go:29: local err=flate: corrupt input before offset 10 len=0
    large_low_entropy_test.go:35: standard reader rejected stream: flate: corrupt input before offset 10
--- FAIL: TestLargeLowEntropyRoundTripVisible (0.54s)
FAIL
FAIL	[code-host]/klauspost/compress/flate	0.541s
FAIL
shell
rg -n "huffman-zero|golden|expect|writeToType|writeBlockDynamic" flate/*_test.go
output
Chunk ID: 62246f
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1439
Output:
flate/deflate_test.go:98:					expect := hash4(y[i:])
flate/deflate_test.go:99:					if got != expect && got == uint32(i)+100 {
flate/deflate_test.go:100:						t.Errorf("Len:%d Index:%d, expected 0x%08x but not modified", len(y), i, expect)
flate/deflate_test.go:101:					} else if got != expect {
flate/deflate_test.go:102:						t.Errorf("Len:%d Index:%d, got 0x%08x expected:0x%08x", len(y), i, got, expect)
flate/deflate_test.go:574:			t.Errorf("got %d, expected %d bytes", len(out2), len(out1))
flate/deflate_test.go:580:					t.Errorf("mismatch index %d: %02x, expected %02x", i, out2[i], b)
flate/example_test.go:79:	// that are expected to be found in the actual data stream.
flate/inflate_test.go:63:		if err != io.ErrUnexpectedEOF {
flate/inflate_test.go:64:			t.Errorf("test %d, error mismatch: got %v, want io.ErrUnexpectedEOF", i, err)
flate/inflate_test.go:274:		t.Error("Returned length did not match, expected", len(input), "got", written)
flate/inflate_test.go:277:		t.Error("Actual Length did not match, expected", len(input), "got", wtbuf.Len())
flate/inflate_test.go:297:	expected := "hello, world"
flate/inflate_test.go:299:	if expected != actual {
flate/inflate_test.go:300:		t.Fatalf("expected: %v, got: %v", expected, actual)
flate/writer_test.go:314:				t.Fatal("Level", l, "Got unexpected error after reset:", err)
flate/writer_test.go:317:				t.Fatal("Level", l, "Got 0 length write, expected > 0")
flate/huffman_bit_writer_test.go:33:			out = in[:len(in)-len(".in")] + ".golden"
flate/huffman_bit_writer_test.go:102:	want        string // File name of data with the expected output with input available.
flate/huffman_bit_writer_test.go:103:	wantNoInput string // File name of the expected output when no input is available.
flate/huffman_bit_writer_test.go:111:		want:        "testdata/huffman-null-max.%s.expect",
flate/huffman_bit_writer_test.go:112:		wantNoInput: "testdata/huffman-null-max.%s.expect-noinput",
flate/huffman_bit_writer_test.go:117:		want:        "testdata/huffman-pi.%s.expect",
flate/huffman_bit_writer_test.go:118:		wantNoInput: "testdata/huffman-pi.%s.expect-noinput",
flate/huffman_bit_writer_test.go:123:		want:        "testdata/huffman-rand-1k.%s.expect",
flate/huffman_bit_writer_test.go:124:		wantNoInput: "testdata/huffman-rand-1k.%s.expect-noinput",
flate/huffman_bit_writer_test.go:129:		want:        "testdata/huffman-rand-limit.%s.expect",
flate/huffman_bit_writer_test.go:130:		wantNoInput: "testdata/huffman-rand-limit.%s.expect-noinput",
flate/huffman_bit_writer_test.go:135:		want:        "testdata/huffman-shifts.%s.expect",
flate/huffman_bit_writer_test.go:136:		wantNoInput: "testdata/huffman-shifts.%s.expect-noinput",
flate/huffman_bit_writer_test.go:141:		want:        "testdata/huffman-text-shift.%s.expect",
flate/huffman_bit_writer_test.go:142:		wantNoInput: "testdata/huffman-text-shift.%s.expect-noinput",
flate/huffman_bit_writer_test.go:147:		want:        "testdata/huffman-text.%s.expect",
flate/huffman_bit_writer_test.go:148:		wantNoInput: "testdata/huffman-text.%s.expect-noinput",
flate/huffman_bit_writer_test.go:152:		input:       "testdata/huffman-zero.in",
flate/huffman_bit_writer_test.go:153:		want:        "testdata/huffman-zero.%s.expect",
flate/huffman_bit_writer_test.go:154:		wantNoInput: "testdata/huffman-zero.%s.expect-noinput",
flate/huffman_bit_writer_test.go:160:		wantNoInput: "testdata/null-long-match.%s.expect-noinput",
flate/huffman_bit_writer_test.go:173:// TestWriteBlockDynamic tests if the writeBlockDynamic encoding has changed.
flate/huffman_bit_writer_test.go:181:// TestWriteBlockDynamic tests if the writeBlockDynamic encoding has changed.
flate/huffman_bit_writer_test.go:214:			writeToType(t, ttype, bw, tokens, input)
flate/huffman_bit_writer_test.go:225:		writeToType(t, ttype, bw, tokens, nil)
flate/huffman_bit_writer_test.go:243:		writeToType(t, ttype, bw, tokens, input)
flate/huffman_bit_writer_test.go:247:			t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+gotSuffix)
flate/huffman_bit_writer_test.go:257:		writeToType(t, ttype, bw, tokens, input)
flate/huffman_bit_writer_test.go:261:			t.Errorf("reset: writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+".reset"+gotSuffix)
flate/huffman_bit_writer_test.go:278:	writeToType(t, ttype, bw, tokens, nil)
flate/huffman_bit_writer_test.go:282:		t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.wantNoInput, test.wantNoInput+gotSuffix)
flate/huffman_bit_writer_test.go:287:		t.Error("got unexpected EOF")
flate/huffman_bit_writer_test.go:296:	writeToType(t, ttype, bw, tokens, nil)
flate/huffman_bit_writer_test.go:300:		t.Errorf("reset: writeBlock did not yield expected result for file %q without input. See %q", test.wantNoInput, test.wantNoInput+".reset"+gotSuffix)
flate/huffman_bit_writer_test.go:310:func writeToType(t *testing.T, ttype string, bw *huffmanBitWriter, tok tokens, input []byte) {
flate/huffman_bit_writer_test.go:315:		bw.writeBlockDynamic(&tok, false, input, false)
flate/huffman_bit_writer_test.go:317:		bw.writeBlockDynamic(&tok, false, input, true)
flate/huffman_bit_writer_test.go:355:		bw.writeBlockDynamic(&tokens, true, input, true)
flate/token_test.go:31:	const expect = 221057
flate/token_test.go:35:	wr.writeBlockDynamic(tok, true, nil, true)
flate/token_test.go:41:	if n != expect {
flate/token_test.go:42:		t.Error("want:", expect, "bits, got:", n)
flate/flate_test.go:198:		want   string // Expected result. Use "fail" to expect failure
flate/flate_test.go:334:		"issue 11030 - empty HDistTree unexpectedly leads to error",
flate/flate_test.go:338:		"issue 11033 - empty HDistTree unexpectedly leads to error",
shell
sed -n '180,370p' flate/huffman_bit_writer_test.go
output
Chunk ID: 4984e2
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1170
Output:

// TestWriteBlockDynamic tests if the writeBlockDynamic encoding has changed.
// To update the reference files use the "-update" flag on the test.
func TestWriteBlockDynamicSync(t *testing.T) {
	for _, test := range writeBlockTests {
		testBlock(t, test, "sync")
	}
}

// testBlock tests a block against its references,
// or regenerate the references, if "-update" flag is set.
func testBlock(t *testing.T, test huffTest, ttype string) {
	if test.want != "" {
		test.want = fmt.Sprintf(test.want, ttype)
	}
	const gotSuffix = ".got"
	test.wantNoInput = fmt.Sprintf(test.wantNoInput, ttype)
	tokens := indexTokens(test.tokens)
	if *update {
		if test.input != "" {
			t.Logf("Updating %q", test.want)
			input, err := os.ReadFile(test.input)
			if err != nil {
				t.Error(err)
				return
			}

			f, err := os.Create(test.want)
			if err != nil {
				t.Error(err)
				return
			}
			defer f.Close()
			bw := newHuffmanBitWriter(f)
			writeToType(t, ttype, bw, tokens, input)
		}

		t.Logf("Updating %q", test.wantNoInput)
		f, err := os.Create(test.wantNoInput)
		if err != nil {
			t.Error(err)
			return
		}
		defer f.Close()
		bw := newHuffmanBitWriter(f)
		writeToType(t, ttype, bw, tokens, nil)
		return
	}

	if test.input != "" {
		t.Logf("Testing %q", test.want)
		input, err := os.ReadFile(test.input)
		if err != nil {
			t.Error(err)
			return
		}
		want, err := os.ReadFile(test.want)
		if err != nil {
			t.Error(err)
			return
		}
		var buf bytes.Buffer
		bw := newHuffmanBitWriter(&buf)
		writeToType(t, ttype, bw, tokens, input)

		got := buf.Bytes()
		if !bytes.Equal(got, want) {
			t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+gotSuffix)
			if err := os.WriteFile(test.want+gotSuffix, got, 0666); err != nil {
				t.Error(err)
			}
		}
		t.Log("Output ok")

		// Test if the writer produces the same output after reset.
		buf.Reset()
		bw.reset(&buf)
		writeToType(t, ttype, bw, tokens, input)
		bw.flush()
		got = buf.Bytes()
		if !bytes.Equal(got, want) {
			t.Errorf("reset: writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+".reset"+gotSuffix)
			if err := os.WriteFile(test.want+".reset"+gotSuffix, got, 0666); err != nil {
				t.Error(err)
			}
			return
		}
		t.Log("Reset ok")
		testWriterEOF(t, "wb", test, true)
	}
	t.Logf("Testing %q", test.wantNoInput)
	wantNI, err := os.ReadFile(test.wantNoInput)
	if err != nil {
		t.Error(err)
		return
	}
	var buf bytes.Buffer
	bw := newHuffmanBitWriter(&buf)
	writeToType(t, ttype, bw, tokens, nil)

	got := buf.Bytes()
	if !bytes.Equal(got, wantNI) {
		t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.wantNoInput, test.wantNoInput+gotSuffix)
		if err := os.WriteFile(test.wantNoInput+gotSuffix, got, 0666); err != nil {
			t.Error(err)
		}
	} else if got[0]&1 == 1 {
		t.Error("got unexpected EOF")
		return
	}

	t.Log("Output ok")

	// Test if the writer produces the same output after reset.
	buf.Reset()
	bw.reset(&buf)
	writeToType(t, ttype, bw, tokens, nil)
	bw.flush()
	got = buf.Bytes()
	if !bytes.Equal(got, wantNI) {
		t.Errorf("reset: writeBlock did not yield expected result for file %q without input. See %q", test.wantNoInput, test.wantNoInput+".reset"+gotSuffix)
		if err := os.WriteFile(test.wantNoInput+".reset"+gotSuffix, got, 0666); err != nil {
			t.Error(err)
		}
		return
	}
	t.Log("Reset ok")
	testWriterEOF(t, "wb", test, false)
}

func writeToType(t *testing.T, ttype string, bw *huffmanBitWriter, tok tokens, input []byte) {
	switch ttype {
	case "wb":
		bw.writeBlock(&tok, false, input)
	case "dyn":
		bw.writeBlockDynamic(&tok, false, input, false)
	case "sync":
		bw.writeBlockDynamic(&tok, false, input, true)
	default:
		panic("unknown test type")
	}

	if bw.err != nil {
		t.Error(bw.err)
		return
	}

	bw.flush()
	if bw.err != nil {
		t.Error(bw.err)
		return
	}
}

// testWriterEOF tests if the written block contains an EOF marker.
func testWriterEOF(t *testing.T, ttype string, test huffTest, useInput bool) {
	if useInput && test.input == "" {
		return
	}
	var input []byte
	if useInput {
		var err error
		input, err = os.ReadFile(test.input)
		if err != nil {
			t.Error(err)
			return
		}
	}
	var buf bytes.Buffer
	bw := newHuffmanBitWriter(&buf)
	tokens := indexTokens(test.tokens)
	switch ttype {
	case "wb":
		bw.writeBlock(&tokens, true, input)
	case "dyn":
		bw.writeBlockDynamic(&tokens, true, input, true)
	case "huff":
		bw.writeBlockHuff(true, input, true)
	default:
		panic("unknown test type")
	}
	if bw.err != nil {
		t.Error(bw.err)
		return
	}

	bw.flush()
	if bw.err != nil {
		t.Error(bw.err)
		return
	}
shell
sed -n '1,178p' flate/huffman_bit_writer_test.go
output
Chunk ID: b7d64f
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 9227
Output:
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package flate

import (
	"bytes"
	"flag"
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"testing"
)

var update = flag.Bool("update", false, "update reference files")

// TestBlockHuff tests huffman encoding against reference files
// to detect possible regressions.
// If encoding/bit allocation changes you can regenerate these files
// by using the -update flag.
func TestBlockHuff(t *testing.T) {
	// determine input files
	match, err := filepath.Glob("testdata/huffman-*.in")
	if err != nil {
		t.Fatal(err)
	}

	for _, in := range match {
		out := in // for files where input and output are identical
		if strings.HasSuffix(in, ".in") {
			out = in[:len(in)-len(".in")] + ".golden"
		}
		t.Run(in, func(t *testing.T) {
			testBlockHuff(t, in, out)
		})
	}
}

func testBlockHuff(t *testing.T, in, out string) {
	all, err := os.ReadFile(in)
	if err != nil {
		t.Error(err)
		return
	}
	var buf bytes.Buffer
	bw := newHuffmanBitWriter(&buf)
	bw.logNewTablePenalty = 8
	bw.writeBlockHuff(false, all, false)
	bw.flush()
	got := buf.Bytes()

	want, err := os.ReadFile(out)
	if err != nil && !*update {
		t.Error(err)
		return
	}

	t.Logf("Testing %q", in)
	if !bytes.Equal(got, want) {
		if *update {
			if in != out {
				t.Logf("Updating %q", out)
				if err := os.WriteFile(out, got, 0666); err != nil {
					t.Error(err)
				}
				return
			}
			// in == out: don't accidentally destroy input
			t.Errorf("WARNING: -update did not rewrite input file %s", in)
		}

		t.Errorf("%q != %q (see %q)", in, out, in+".got")
		if err := os.WriteFile(in+".got", got, 0666); err != nil {
			t.Error(err)
		}
		return
	}
	t.Log("Output ok")

	// Test if the writer produces the same output after reset.
	buf.Reset()
	bw.reset(&buf)
	bw.writeBlockHuff(false, all, false)
	bw.flush()
	got = buf.Bytes()
	if !bytes.Equal(got, want) {
		t.Errorf("after reset %q != %q (see %q)", in, out, in+".reset.got")
		if err := os.WriteFile(in+".reset.got", got, 0666); err != nil {
			t.Error(err)
		}
		return
	}
	t.Log("Reset ok")
	testWriterEOF(t, "huff", huffTest{input: in}, true)
}

type huffTest struct {
	tokens      []token
	input       string // File name of input data matching the tokens.
	want        string // File name of data with the expected output with input available.
	wantNoInput string // File name of the expected output when no input is available.
}

const ml = 0x7fc00000 // Maximum length token. Used to reduce the size of writeBlockTests

var writeBlockTests = []huffTest{
	{
		input:       "testdata/huffman-null-max.in",
		want:        "testdata/huffman-null-max.%s.expect",
		wantNoInput: "testdata/huffman-null-max.%s.expect-noinput",
		tokens:      []token{0x0, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, 0x0, 0x0},
	},
	{
		input:       "testdata/huffman-pi.in",
		want:        "testdata/huffman-pi.%s.expect",
		wantNoInput: "testdata/huffman-pi.%s.expect-noinput",
		tokens:      []token{0x33, 0x2e, 0x31, 0x34, 0x31, 0x35, 0x39, 0x32, 0x36, 0x35, 0x33, 0x35, 0x38, 0x39, 0x37, 0x39, 0x33, 0x32, 0x33, 0x38, 0x34, 0x36, 0x32, 0x36, 0x34, 0x33, 0x33, 0x38, 0x33, 0x32, 0x37, 0x39, 0x35, 0x30, 0x32, 0x38, 0x38, 0x34, 0x31, 0x39, 0x37, 0x31, 0x36, 0x39, 0x33, 0x39, 0x39, 0x33, 0x37, 0x35, 0x31, 0x30, 0x35, 0x38, 0x32, 0x30, 0x39, 0x37, 0x34, 0x39, 0x34, 0x34, 0x35, 0x39, 0x32, 0x33, 0x30, 0x37, 0x38, 0x31, 0x36, 0x34, 0x30, 0x36, 0x32, 0x38, 0x36, 0x32, 0x30, 0x38, 0x39, 0x39, 0x38, 0x36, 0x32, 0x38, 0x30, 0x33, 0x34, 0x38, 0x32, 0x35, 0x33, 0x34, 0x32, 0x31, 0x31, 0x37, 0x30, 0x36, 0x37, 0x39, 0x38, 0x32, 0x31, 0x34, 0x38, 0x30, 0x38, 0x36, 0x35, 0x31, 0x33, 0x32, 0x38, 0x32, 0x33, 0x30, 0x36, 0x36, 0x34, 0x37, 0x30, 0x39, 0x33, 0x38, 0x34, 0x34, 0x36, 0x30, 0x39, 0x35, 0x35, 0x30, 0x35, 0x38, 0x32, 0x32, 0x33, 0x31, 0x37, 0x32, 0x35, 0x33, 0x35, 0x39, 0x34, 0x30, 0x38, 0x31, 0x32, 0x38, 0x34, 0x38, 0x31, 0x31, 0x31, 0x37, 0x34, 0x4040007e, 0x34, 0x31, 0x30, 0x32, 0x37, 0x30, 0x31, 0x39, 0x33, 0x38, 0x35, 0x32, 0x31, 0x31, 0x30, 0x35, 0x35, 0x35, 0x39, 0x36, 0x34, 0x34, 0x36, 0x32, 0x32, 0x39, 0x34, 0x38, 0x39, 0x35, 0x34, 0x39, 0x33, 0x30, 0x33, 0x38, 0x31, 0x40400012, 0x32, 0x38, 0x38, 0x31, 0x30, 0x39, 0x37, 0x35, 0x36, 0x36, 0x35, 0x39, 0x33, 0x33, 0x34, 0x34, 0x36, 0x40400047, 0x37, 0x35, 0x36, 0x34, 0x38, 0x32, 0x33, 0x33, 0x37, 0x38, 0x36, 0x37, 0x38, 0x33, 0x31, 0x36, 0x35, 0x32, 0x37, 0x31, 0x32, 0x30, 0x31, 0x39, 0x30, 0x39, 0x31, 0x34, 0x4040001a, 0x35, 0x36, 0x36, 0x39, 0x32, 0x33, 0x34, 0x36, 0x404000b2, 0x36, 0x31, 0x30, 0x34, 0x35, 0x34, 0x33, 0x32, 0x36, 0x40400032, 0x31, 0x33, 0x33, 0x39, 0x33, 0x36, 0x30, 0x37, 0x32, 0x36, 0x30, 0x32, 0x34, 0x39, 0x31, 0x34, 0x31, 0x32, 0x37, 0x33, 0x37, 0x32, 0x34, 0x35, 0x38, 0x37, 0x30, 0x30, 0x36, 0x36, 0x30, 0x36, 0x33, 0x31, 0x35, 0x35, 0x38, 0x38, 0x31, 0x37, 0x34, 0x38, 0x38, 0x31, 0x35, 0x32, 0x30, 0x39, 0x32, 0x30, 0x39, 0x36, 0x32, 0x38, 0x32, 0x39, 0x32, 0x35, 0x34, 0x30, 0x39, 0x31, 0x37, 0x31, 0x35, 0x33, 0x36, 0x34, 0x33, 0x36, 0x37, 0x38, 0x39, 0x32, 0x35, 0x39, 0x30, 0x33, 0x36, 0x30, 0x30, 0x31, 0x31, 0x33, 0x33, 0x30, 0x35, 0x33, 0x30, 0x35, 0x34, 0x38, 0x38, 0x32, 0x30, 0x34, 0x36, 0x36, 0x35, 0x32, 0x31, 0x33, 0x38, 0x34, 0x31, 0x34, 0x36, 0x39, 0x35, 0x31, 0x39, 0x34, 0x31, 0x35, 0x31, 0x31, 0x36, 0x30, 0x39, 0x34, 0x33, 0x33, 0x30, 0x35, 0x37, 0x32, 0x37, 0x30, 0x33, 0x36, 0x35, 0x37, 0x35, 0x39, 0x35, 0x39, 0x31, 0x39, 0x35, 0x33, 0x30, 0x39, 0x32, 0x31, 0x38, 0x36, 0x31, 0x31, 0x37, 0x404000e9, 0x33, 0x32, 0x40400009, 0x39, 0x33, 0x31, 0x30, 0x35, 0x31, 0x31, 0x38, 0x35, 0x34, 0x38, 0x30, 0x37, 0x4040010e, 0x33, 0x37, 0x39, 0x39, 0x36, 0x32, 0x37, 0x34, 0x39, 0x35, 0x36, 0x37, 0x33, 0x35, 0x31, 0x38, 0x38, 0x35, 0x37, 0x35, 0x32, 0x37, 0x32, 0x34, 0x38, 0x39, 0x31, 0x32, 0x32, 0x37, 0x39, 0x33, 0x38, 0x31, 0x38, 0x33, 0x30, 0x31, 0x31, 0x39, 0x34, 0x39, 0x31, 0x32, 0x39, 0x38, 0x33, 0x33, 0x36, 0x37, 0x33, 0x33, 0x36, 0x32, 0x34, 0x34, 0x30, 0x36, 0x35, 0x36, 0x36, 0x34, 0x33, 0x30, 0x38, 0x36, 0x30, 0x32, 0x31, 0x33, 0x39, 0x34, 0x39, 0x34, 0x36, 0x33, 0x39, 0x35, 0x32, 0x32, 0x34, 0x37, 0x33, 0x37, 0x31, 0x39, 0x30, 0x37, 0x30, 0x32, 0x31, 0x37, 0x39, 0x38, 0x40800099, 0x37, 0x30, 0x32, 0x37, 0x37, 0x30, 0x35, 0x33, 0x39, 0x32, 0x31, 0x37, 0x31, 0x37, 0x36, 0x32, 0x39, 0x33, 0x31, 0x37, 0x36, 0x37, 0x35, 0x40800232, 0x37, 0x34, 0x38, 0x31, 0x40400006, 0x36, 0x36, 0x39, 0x34, 0x30, 0x404001e7, 0x30, 0x30, 0x30, 0x35, 0x36, 0x38, 0x31, 0x32, 0x37, 0x31, 0x34, 0x35, 0x32, 0x36, 0x33, 0x35, 0x36, 0x30, 0x38, 0x32, 0x37, 0x37, 0x38, 0x35, 0x37, 0x37, 0x31, 0x33, 0x34, 0x32, 0x37, 0x35, 0x37, 0x37, 0x38, 0x39, 0x36, 0x40400129, 0x33, 0x36, 0x33, 0x37, 0x31, 0x37, 0x38, 0x37, 0x32, 0x31, 0x34, 0x36, 0x38, 0x34, 0x34, 0x30, 0x39, 0x30, 0x31, 0x32, 0x32, 0x34, 0x39, 0x35, 0x33, 0x34, 0x33, 0x30, 0x31, 0x34, 0x36, 0x35, 0x34, 0x39, 0x35, 0x38, 0x35, 0x33, 0x37, 0x31, 0x30, 0x35, 0x30, 0x37, 0x39, 0x404000ca, 0x36, 0x40400153, 0x38, 0x39, 0x32, 0x33, 0x35, 0x34, 0x404001c9, 0x39, 0x35, 0x36, 0x31, 0x31, 0x32, 0x31, 0x32, 0x39, 0x30, 0x32, 0x31, 0x39, 0x36, 0x30, 0x38, 0x36, 0x34, 0x30, 0x33, 0x34, 0x34, 0x31, 0x38, 0x31, 0x35, 0x39, 0x38, 0x31, 0x33, 0x36, 0x32, 0x39, 0x37, 0x37, 0x34, 0x40400074, 0x30, 0x39, 0x39, 0x36, 0x30, 0x35, 0x31, 0x38, 0x37, 0x30, 0x37, 0x32, 0x31, 0x31, 0x33, 0x34, 0x39, 0x40800000, 0x38, 0x33, 0x37, 0x32, 0x39, 0x37, 0x38, 0x30, 0x34, 0x39, 0x39, 0x404002da, 0x39, 0x37, 0x33, 0x31, 0x37, 0x33, 0x32, 0x38, 0x4040018a, 0x36, 0x33, 0x31, 0x38, 0x35, 0x40400301, 0x404002e8, 0x34, 0x35, 0x35, 0x33, 0x34, 0x36, 0x39, 0x30, 0x38, 0x33, 0x30, 0x32, 0x36, 0x34, 0x32, 0x35, 0x32, 0x32, 0x33, 0x30, 0x404002e3, 0x40400267, 0x38, 0x35, 0x30, 0x33, 0x35, 0x32, 0x36, 0x31, 0x39, 0x33, 0x31, 0x31, 0x40400212, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30, 0x33, 0x31, 0x33, 0x37, 0x38, 0x33, 0x38, 0x37, 0x35, 0x32, 0x38, 0x38, 0x36, 0x35, 0x38, 0x37, 0x35, 0x33, 0x33, 0x32, 0x30, 0x38, 0x33, 0x38, 0x31, 0x34, 0x32, 0x30, 0x36, 0x40400140, 0x4040012b, 0x31, 0x34, 0x37, 0x33, 0x30, 0x33, 0x35, 0x39, 0x4080032e, 0x39, 0x30, 0x34, 0x32, 0x38, 0x37, 0x35, 0x35, 0x34, 0x36, 0x38, 0x37, 0x33, 0x31, 0x31, 0x35, 0x39, 0x35, 0x40400355, 0x33, 0x38, 0x38, 0x32, 0x33, 0x35, 0x33, 0x37, 0x38, 0x37, 0x35, 0x4080037f, 0x39, 0x4040013a, 0x31, 0x40400148, 0x38, 0x30, 0x35, 0x33, 0x4040018a, 0x32, 0x32, 0x36, 0x38, 0x30, 0x36, 0x36, 0x31, 0x33, 0x30, 0x30, 0x31, 0x39, 0x32, 0x37, 0x38, 0x37, 0x36, 0x36, 0x31, 0x31, 0x31, 0x39, 0x35, 0x39, 0x40400237, 0x36, 0x40800124, 0x38, 0x39, 0x33, 0x38, 0x30, 0x39, 0x35, 0x32, 0x35, 0x37, 0x32, 0x30, 0x31, 0x30, 0x36, 0x35, 0x34, 0x38, 0x35, 0x38, 0x36, 0x33, 0x32, 0x37, 0x4040009a, 0x39, 0x33, 0x36, 0x31, 0x35, 0x33, 0x40400220, 0x4080015c, 0x32, 0x33, 0x30, 0x33, 0x30, 0x31, 0x39, 0x35, 0x32, 0x30, 0x33, 0x35, 0x33, 0x30, 0x31, 0x38, 0x35, 0x32, 0x40400171, 0x40400075, 0x33, 0x36, 0x32, 0x32, 0x35, 0x39, 0x39, 0x34, 0x31, 0x33, 0x40400254, 0x34, 0x39, 0x37, 0x32, 0x31, 0x37, 0x404000de, 0x33, 0x34, 0x37, 0x39, 0x31, 0x33, 0x31, 0x35, 0x31, 0x35, 0x35, 0x37, 0x34, 0x38, 0x35, 0x37, 0x32, 0x34, 0x32, 0x34, 0x35, 0x34, 0x31, 0x35, 0x30, 0x36, 0x39, 0x4040013f, 0x38, 0x32, 0x39, 0x35, 0x33, 0x33, 0x31, 0x31, 0x36, 0x38, 0x36, 0x31, 0x37, 0x32, 0x37, 0x38, 0x40400337, 0x39, 0x30, 0x37, 0x35, 0x30, 0x39, 0x4040010d, 0x37, 0x35, 0x34, 0x36, 0x33, 0x37, 0x34, 0x36, 0x34, 0x39, 0x33, 0x39, 0x33, 0x31, 0x39, 0x32, 0x35, 0x35, 0x30, 0x36, 0x30, 0x34, 0x30, 0x30, 0x39, 0x4040026b, 0x31, 0x36, 0x37, 0x31, 0x31, 0x33, 0x39, 0x30, 0x30, 0x39, 0x38, 0x40400335, 0x34, 0x30, 0x31, 0x32, 0x38, 0x35, 0x38, 0x33, 0x36, 0x31, 0x36, 0x30, 0x33, 0x35, 0x36, 0x33, 0x37, 0x30, 0x37, 0x36, 0x36, 0x30, 0x31, 0x30, 0x34, 0x40400172, 0x38, 0x31, 0x39, 0x34, 0x32, 0x39, 0x4080041e, 0x404000ef, 0x4040028b, 0x37, 0x38, 0x33, 0x37, 0x34, 0x404004a8, 0x38, 0x32, 0x35, 0x35, 0x33, 0x37, 0x40800209, 0x32, 0x36, 0x38, 0x4040002e, 0x34, 0x30, 0x34, 0x37, 0x404001d1, 0x34, 0x404004b5, 0x4040038d, 0x38, 0x34, 0x404003a8, 0x36, 0x40c0031f, 0x33, 0x33, 0x31, 0x33, 0x36, 0x37, 0x37, 0x30, 0x32, 0x38, 0x39, 0x38, 0x39, 0x31, 0x35, 0x32, 0x40400062, 0x35, 0x32, 0x31, 0x36, 0x32, 0x30, 0x35, 0x36, 0x39, 0x36, 0x40400411, 0x30, 0x35, 0x38, 0x40400477, 0x35, 0x40400498, 0x35, 0x31, 0x31, 0x40400209, 0x38, 0x32, 0x34, 0x33, 0x30, 0x30, 0x33, 0x35, 0x35, 0x38, 0x37, 0x36, 0x34, 0x30, 0x32, 0x34, 0x37, 0x34, 0x39, 0x36, 0x34, 0x37, 0x33, 0x32, 0x36, 0x33, 0x4040043e, 0x39, 0x39, 0x32, 0x4040044b, 0x34, 0x32, 0x36, 0x39, 0x40c002c5, 0x37, 0x404001d6, 0x34, 0x4040053d, 0x4040041d, 0x39, 0x33, 0x34, 0x31, 0x37, 0x404001ad, 0x31, 0x32, 0x4040002a, 0x34, 0x4040019e, 0x31, 0x35, 0x30, 0x33, 0x30, 0x32, 0x38, 0x36, 0x31, 0x38, 0x32, 0x39, 0x37, 0x34, 0x35, 0x35, 0x35, 0x37, 0x30, 0x36, 0x37, 0x34, 0x40400135, 0x35, 0x30, 0x35, 0x34, 0x39, 0x34, 0x35, 0x38, 0x404001c5, 0x39, 0x40400051, 0x35, 0x36, 0x404001ec, 0x37, 0x32, 0x31, 0x30, 0x37, 0x39, 0x40400159, 0x33, 0x30, 0x4040010a, 0x33, 0x32, 0x31, 0x31, 0x36, 0x35, 0x33, 0x34, 0x34, 0x39, 0x38, 0x37, 0x32, 0x30, 0x32, 0x37, 0x4040011b, 0x30, 0x32, 0x33, 0x36, 0x34, 0x4040022e, 0x35, 0x34, 0x39, 0x39, 0x31, 0x31, 0x39, 0x38, 0x40400418, 0x34, 0x4040011b, 0x35, 0x33, 0x35, 0x36, 0x36, 0x33, 0x36, 0x39, 0x40400450, 0x32, 0x36, 0x35, 0x404002e4, 0x37, 0x38, 0x36, 0x32, 0x35, 0x35, 0x31, 0x404003da, 0x31, 0x37, 0x35, 0x37, 0x34, 0x36, 0x37, 0x32, 0x38, 0x39, 0x30, 0x39, 0x37, 0x37, 0x37, 0x37, 0x40800453, 0x30, 0x30, 0x30, 0x404005fd, 0x37, 0x30, 0x404004df, 0x36, 0x404003e9, 0x34, 0x39, 0x31, 0x4040041e, 0x40400297, 0x32, 0x31, 0x34, 0x37, 0x37, 0x32, 0x33, 0x35, 0x30, 0x31, 0x34, 0x31, 0x34, 0x40400643, 0x33, 0x35, 0x36, 0x404004af, 0x31, 0x36, 0x31, 0x33, 0x36, 0x31, 0x31, 0x35, 0x37, 0x33, 0x35, 0x32, 0x35, 0x40400504, 0x33, 0x34, 0x4040005b, 0x31, 0x38, 0x4040047b, 0x38, 0x34, 0x404005e7, 0x33, 0x33, 0x32, 0x33, 0x39, 0x30, 0x37, 0x33, 0x39, 0x34, 0x31, 0x34, 0x33, 0x33, 0x33, 0x34, 0x35, 0x34, 0x37, 0x37, 0x36, 0x32, 0x34, 0x40400242, 0x32, 0x35, 0x31, 0x38, 0x39, 0x38, 0x33, 0x35, 0x36, 0x39, 0x34, 0x38, 0x35, 0x35, 0x36, 0x32, 0x30, 0x39, 0x39, 0x32, 0x31, 0x39, 0x32, 0x32, 0x32, 0x31, 0x38, 0x34, 0x32, 0x37, 0x4040023e, 0x32, 0x404000ba, 0x36, 0x38, 0x38, 0x37, 0x36, 0x37, 0x31, 0x37, 0x39, 0x30, 0x40400055, 0x30, 0x40800106, 0x36, 0x36, 0x404003e7, 0x38, 0x38, 0x36, 0x32, 0x37, 0x32, 0x404006dc, 0x31, 0x37, 0x38, 0x36, 0x30, 0x38, 0x35, 0x37, 0x40400073, 0x33, 0x408002fc, 0x37, 0x39, 0x37, 0x36, 0x36, 0x38, 0x31, 0x404002bd, 0x30, 0x30, 0x39, 0x35, 0x33, 0x38, 0x38, 0x40400638, 0x33, 0x404006a5, 0x30, 0x36, 0x38, 0x30, 0x30, 0x36, 0x34, 0x32, 0x32, 0x35, 0x31, 0x32, 0x35, 0x32, 0x4040057b, 0x37, 0x33, 0x39, 0x32, 0x40400297, 0x40400474, 0x34, 0x408006b3, 0x38, 0x36, 0x32, 0x36, 0x39, 0x34, 0x35, 0x404001e5, 0x34, 0x31, 0x39, 0x36, 0x35, 0x32, 0x38, 0x35, 0x30, 0x40400099, 0x4040039c, 0x31, 0x38, 0x36, 0x33, 0x404001be, 0x34, 0x40800154, 0x32, 0x30, 0x33, 0x39, 0x4040058b, 0x34, 0x35, 0x404002bc, 0x32, 0x33, 0x37, 0x4040042c, 0x36, 0x40400510, 0x35, 0x36, 0x40400638, 0x37, 0x31, 0x39, 0x31, 0x37, 0x32, 0x38, 0x40400171, 0x37, 0x36, 0x34, 0x36, 0x35, 0x37, 0x35, 0x37, 0x33, 0x39, 0x40400101, 0x33, 0x38, 0x39, 0x40400748, 0x38, 0x33, 0x32, 0x36, 0x34, 0x35, 0x39, 0x39, 0x35, 0x38, 0x404006a7, 0x30, 0x34, 0x37, 0x38, 0x404001de, 0x40400328, 0x39, 0x4040002d, 0x36, 0x34, 0x30, 0x37, 0x38, 0x39, 0x35, 0x31, 0x4040008e, 0x36, 0x38, 0x33, 0x4040012f, 0x32, 0x35, 0x39, 0x35, 0x37, 0x30, 0x40400468, 0x38, 0x32, 0x32, 0x404002c8, 0x32, 0x4040061b, 0x34, 0x30, 0x37, 0x37, 0x32, 0x36, 0x37, 0x31, 0x39, 0x34, 0x37, 0x38, 0x40400319, 0x38, 0x32, 0x36, 0x30, 0x31, 0x34, 0x37, 0x36, 0x39, 0x39, 0x30, 0x39, 0x404004e8, 0x30, 0x31, 0x33, 0x36, 0x33, 0x39, 0x34, 0x34, 0x33, 0x4040027f, 0x33, 0x30, 0x40400105, 0x32, 0x30, 0x33, 0x34, 0x39, 0x36, 0x32, 0x35, 0x32, 0x34, 0x35, 0x31, 0x37, 0x404003b5, 0x39, 0x36, 0x35, 0x31, 0x34, 0x33, 0x31, 0x34, 0x32, 0x39, 0x38, 0x30, 0x39, 0x31, 0x39, 0x30, 0x36, 0x35, 0x39, 0x32, 0x40400282, 0x37, 0x32, 0x32, 0x31, 0x36, 0x39, 0x36, 0x34, 0x36, 0x40400419, 0x4040007a, 0x35, 0x4040050e, 0x34, 0x40800565, 0x38, 0x40400559, 0x39, 0x37, 0x4040057b, 0x35, 0x34, 0x4040049d, 0x4040023e, 0x37, 0x4040065a, 0x38, 0x34, 0x36, 0x38, 0x31, 0x33, 0x4040008c, 0x36, 0x38, 0x33, 0x38, 0x36, 0x38, 0x39, 0x34, 0x32, 0x37, 0x37, 0x34, 0x31, 0x35, 0x35, 0x39, 0x39, 0x31, 0x38, 0x35, 0x4040005a, 0x32, 0x34, 0x35, 0x39, 0x35, 0x33, 0x39, 0x35, 0x39, 0x34, 0x33, 0x31, 0x404005b7, 0x37, 0x40400012, 0x36, 0x38, 0x30, 0x38, 0x34, 0x35, 0x404002e7, 0x37, 0x33, 0x4040081e, 0x39, 0x35, 0x38, 0x34, 0x38, 0x36, 0x35, 0x33, 0x38, 0x404006e8, 0x36, 0x32, 0x404000f2, 0x36, 0x30, 0x39, 0x404004b6, 0x36, 0x30, 0x38, 0x30, 0x35, 0x31, 0x32, 0x34, 0x33, 0x38, 0x38, 0x34, 0x4040013a, 0x4040000b, 0x34, 0x31, 0x33, 0x4040030f, 0x37, 0x36, 0x32, 0x37, 0x38, 0x40400341, 0x37, 0x31, 0x35, 0x4040059b, 0x33, 0x35, 0x39, 0x39, 0x37, 0x37, 0x30, 0x30, 0x31, 0x32, 0x39, 0x40400472, 0x38, 0x39, 0x34, 0x34, 0x31, 0x40400277, 0x36, 0x38, 0x35, 0x35, 0x4040005f, 0x34, 0x30, 0x36, 0x33, 0x404008e6, 0x32, 0x30, 0x37, 0x32, 0x32, 0x40400158, 0x40800203, 0x34, 0x38, 0x31, 0x35, 0x38, 0x40400205, 0x404001fe, 0x4040027a, 0x40400298, 0x33, 0x39, 0x34, 0x35, 0x32, 0x32, 0x36, 0x37, 0x40c00496, 0x38, 0x4040058a, 0x32, 0x31, 0x404002ea, 0x32, 0x40400387, 0x35, 0x34, 0x36, 0x36, 0x36, 0x4040051b, 0x32, 0x33, 0x39, 0x38, 0x36, 0x34, 0x35, 0x36, 0x404004c4, 0x31, 0x36, 0x33, 0x35, 0x40800253, 0x40400811, 0x37, 0x404008ad, 0x39, 0x38, 0x4040045e, 0x39, 0x33, 0x36, 0x33, 0x34, 0x4040075b, 0x37, 0x34, 0x33, 0x32, 0x34, 0x4040047b, 0x31, 0x35, 0x30, 0x37, 0x36, 0x404004bb, 0x37, 0x39, 0x34, 0x35, 0x31, 0x30, 0x39, 0x4040003e, 0x30, 0x39, 0x34, 0x30, 0x404006a6, 0x38, 0x38, 0x37, 0x39, 0x37, 0x31, 0x30, 0x38, 0x39, 0x33, 0x404008f0, 0x36, 0x39, 0x31, 0x33, 0x36, 0x38, 0x36, 0x37, 0x32, 0x4040025b, 0x404001fe, 0x35, 0x4040053f, 0x40400468, 0x40400801, 0x31, 0x37, 0x39, 0x32, 0x38, 0x36, 0x38, 0x404008cc, 0x38, 0x37, 0x34, 0x37, 0x4080079e, 0x38, 0x32, 0x34, 0x4040097a, 0x38, 0x4040025b, 0x37, 0x31, 0x34, 0x39, 0x30, 0x39, 0x36, 0x37, 0x35, 0x39, 0x38, 0x404006ef, 0x33, 0x36, 0x35, 0x40400134, 0x38, 0x31, 0x4040005c, 0x40400745, 0x40400936, 0x36, 0x38, 0x32, 0x39, 0x4040057e, 0x38, 0x37, 0x32, 0x32, 0x36, 0x35, 0x38, 0x38, 0x30, 0x40400611, 0x35, 0x40400249, 0x34, 0x32, 0x37, 0x30, 0x34, 0x37, 0x37, 0x35, 0x35, 0x4040081e, 0x33, 0x37, 0x39, 0x36, 0x34, 0x31, 0x34, 0x35, 0x31, 0x35, 0x32, 0x404005fd, 0x32, 0x33, 0x34, 0x33, 0x36, 0x34, 0x35, 0x34, 0x404005de, 0x34, 0x34, 0x34, 0x37, 0x39, 0x35, 0x4040003c, 0x40400523, 0x408008e6, 0x34, 0x31, 0x4040052a, 0x33, 0x40400304, 0x35, 0x32, 0x33, 0x31, 0x40800841, 0x31, 0x36, 0x36, 0x31, 0x404008b2, 0x35, 0x39, 0x36, 0x39, 0x35, 0x33, 0x36, 0x32, 0x33, 0x31, 0x34, 0x404005ff, 0x32, 0x34, 0x38, 0x34, 0x39, 0x33, 0x37, 0x31, 0x38, 0x37, 0x31, 0x31, 0x30, 0x31, 0x34, 0x35, 0x37, 0x36, 0x35, 0x34, 0x40400761, 0x30, 0x32, 0x37, 0x39, 0x39, 0x33, 0x34, 0x34, 0x30, 0x33, 0x37, 0x34, 0x32, 0x30, 0x30, 0x37, 0x4040093f, 0x37, 0x38, 0x35, 0x33, 0x39, 0x30, 0x36, 0x32, 0x31, 0x39, 0x40800299, 0x40400345, 0x38, 0x34, 0x37, 0x408003d2, 0x38, 0x33, 0x33, 0x32, 0x31, 0x34, 0x34, 0x35, 0x37, 0x31, 0x40400284, 0x40400776, 0x34, 0x33, 0x35, 0x30, 0x40400928, 0x40400468, 0x35, 0x33, 0x31, 0x39, 0x31, 0x30, 0x34, 0x38, 0x34, 0x38, 0x31, 0x30, 0x30, 0x35, 0x33, 0x37, 0x30, 0x36, 0x404008bc, 0x4080059d, 0x40800781, 0x31, 0x40400559, 0x37, 0x4040031b, 0x35, 0x404007ec, 0x4040040c, 0x36, 0x33, 0x408007dc, 0x34, 0x40400971, 0x4080034e, 0x408003f5, 0x38, 0x4080052d, 0x40800887, 0x39, 0x40400187, 0x39, 0x31, 0x404008ce, 0x38, 0x31, 0x34, 0x36, 0x37, 0x35, 0x31, 0x4040062b, 0x31, 0x32, 0x33, 0x39, 0x40c001a9, 0x39, 0x30, 0x37, 0x31, 0x38, 0x36, 0x34, 0x39, 0x34, 0x32, 0x33, 0x31, 0x39, 0x36, 0x31, 0x35, 0x36, 0x404001ec, 0x404006bc, 0x39, 0x35, 0x40400926, 0x40400469, 0x4040011b, 0x36, 0x30, 0x33, 0x38, 0x40400a25, 0x4040016f, 0x40400384, 0x36, 0x32, 0x4040045a, 0x35, 0x4040084c, 0x36, 0x33, 0x38, 0x39, 0x33, 0x37, 0x37, 0x38, 0x37, 0x404008c5, 0x404000f8, 0x39, 0x37, 0x39, 0x32, 0x30, 0x37, 0x37, 0x33, 0x404005d7, 0x32, 0x31, 0x38, 0x32, 0x35, 0x36, 0x404007df, 0x36, 0x36, 0x404006d6, 0x34, 0x32, 0x4080067e, 0x36, 0x404006e6, 0x34, 0x34, 0x40400024, 0x35, 0x34, 0x39, 0x32, 0x30, 0x32, 0x36, 0x30, 0x35, 0x40400ab3, 0x408003e4, 0x32, 0x30, 0x31, 0x34, 0x39, 0x404004d2, 0x38, 0x35, 0x30, 0x37, 0x33, 0x40400599, 0x36, 0x36, 0x36, 0x30, 0x40400194, 0x32, 0x34, 0x33, 0x34, 0x30, 0x40400087, 0x30, 0x4040076b, 0x38, 0x36, 0x33, 0x40400956, 0x404007e4, 0x4040042b, 0x40400174, 0x35, 0x37, 0x39, 0x36, 0x32, 0x36, 0x38, 0x35, 0x36, 0x40400140, 0x35, 0x30, 0x38, 0x40400523, 0x35, 0x38, 0x37, 0x39, 0x36, 0x39, 0x39, 0x40400711, 0x35, 0x37, 0x34, 0x40400a18, 0x38, 0x34, 0x30, 0x404008b3, 0x31, 0x34, 0x35, 0x39, 0x31, 0x4040078c, 0x37, 0x30, 0x40400234, 0x30, 0x31, 0x40400be7, 0x31, 0x32, 0x40400c74, 0x30, 0x404003c3, 0x33, 0x39, 0x40400b2a, 0x40400112, 0x37, 0x31, 0x35, 0x404003b0, 0x34, 0x32, 0x30, 0x40800bf2, 0x39, 0x40400bc2, 0x30, 0x37, 0x40400341, 0x40400795, 0x40400aaf, 0x40400c62, 0x32, 0x31, 0x40400960, 0x32, 0x35, 0x31, 0x4040057b, 0x40400944, 0x39, 0x32, 0x404001b2, 0x38, 0x32, 0x36, 0x40400b66, 0x32, 0x40400278, 0x33, 0x32, 0x31, 0x35, 0x37, 0x39, 0x31, 0x39, 0x38, 0x34, 0x31, 0x34, 0x4080087b, 0x39, 0x31, 0x36, 0x34, 0x408006e8, 0x39, 0x40800b58, 0x404008db, 0x37, 0x32, 0x32, 0x40400321, 0x35, 0x404008a4, 0x40400141, 0x39, 0x31, 0x30, 0x404000bc, 0x40400c5b, 0x35, 0x32, 0x38, 0x30, 0x31, 0x37, 0x40400231, 0x37, 0x31, 0x32, 0x40400914, 0x38, 0x33, 0x32, 0x40400373, 0x31, 0x40400589, 0x30, 0x39, 0x33, 0x35, 0x33, 0x39, 0x36, 0x35, 0x37, 0x4040064b, 0x31, 0x30, 0x38, 0x33, 0x40400069, 0x35, 0x31, 0x4040077a, 0x40400d5a, 0x31, 0x34, 0x34, 0x34, 0x32, 0x31, 0x30, 0x30, 0x40400202, 0x30, 0x33, 0x4040019c, 0x31, 0x31, 0x30, 0x33, 0x40400c81, 0x40400009, 0x40400026, 0x40c00602, 0x35, 0x31, 0x36, 0x404005d9, 0x40800883, 0x4040092a, 0x35, 0x40800c42, 0x38, 0x35, 0x31, 0x37, 0x31, 0x34, 0x33, 0x37, 0x40400605, 0x4040006d, 0x31, 0x35, 0x35, 0x36, 0x35, 0x30, 0x38, 0x38, 0x404003b9, 0x39, 0x38, 0x39, 0x38, 0x35, 0x39, 0x39, 0x38, 0x32, 0x33, 0x38, 0x404001cf, 0x404009ba, 0x33, 0x4040016c, 0x4040043e, 0x404009c3, 0x38, 0x40800e05, 0x33, 0x32, 0x40400107, 0x35, 0x40400305, 0x33, 0x404001ca, 0x39, 0x4040041b, 0x39, 0x38, 0x4040087d, 0x34, 0x40400cb8, 0x37, 0x4040064b, 0x30, 0x37, 0x404000e5, 0x34, 0x38, 0x31, 0x34, 0x31, 0x40400539, 0x38, 0x35, 0x39, 0x34, 0x36, 0x31, 0x40400bc9, 0x38, 0x30},
	},
	{
		input:       "testdata/huffman-rand-1k.in",
		want:        "testdata/huffman-rand-1k.%s.expect",
		wantNoInput: "testdata/huffman-rand-1k.%s.expect-noinput",
		tokens:      []token{0xf8, 0x8b, 0x96, 0x76, 0x48, 0xd, 0x85, 0x94, 0x25, 0x80, 0xaf, 0xc2, 0xfe, 0x8d, 0xe8, 0x20, 0xeb, 0x17, 0x86, 0xc9, 0xb7, 0xc5, 0xde, 0x6, 0xea, 0x7d, 0x18, 0x8b, 0xe7, 0x3e, 0x7, 0xda, 0xdf, 0xff, 0x6c, 0x73, 0xde, 0xcc, 0xe7, 0x6d, 0x8d, 0x4, 0x19, 0x49, 0x7f, 0x47, 0x1f, 0x48, 0x15, 0xb0, 0xe8, 0x9e, 0xf2, 0x31, 0x59, 0xde, 0x34, 0xb4, 0x5b, 0xe5, 0xe0, 0x9, 0x11, 0x30, 0xc2, 0x88, 0x5b, 0x7c, 0x5d, 0x14, 0x13, 0x6f, 0x23, 0xa9, 0xd, 0xbc, 0x2d, 0x23, 0xbe, 0xd9, 0xed, 0x75, 0x4, 0x6c, 0x99, 0xdf, 0xfd, 0x70, 0x66, 0xe6, 0xee, 0xd9, 0xb1, 0x9e, 0x6e, 0x83, 0x59, 0xd5, 0xd4, 0x80, 0x59, 0x98, 0x77, 0x89, 0x43, 0x38, 0xc9, 0xaf, 0x30, 0x32, 0x9a, 0x20, 0x1b, 0x46, 0x3d, 0x67, 0x6e, 0xd7, 0x72, 0x9e, 0x4e, 0x21, 0x4f, 0xc6, 0xe0, 0xd4, 0x7b, 0x4, 0x8d, 0xa5, 0x3, 0xf6, 0x5, 0x9b, 0x6b, 0xdc, 0x2a, 0x93, 0x77, 0x28, 0xfd, 0xb4, 0x62, 0xda, 0x20, 0xe7, 0x1f, 0xab, 0x6b, 0x51, 0x43, 0x39, 0x2f, 0xa0, 0x92, 0x1, 0x6c, 0x75, 0x3e, 0xf4, 0x35, 0xfd, 0x43, 0x2e, 0xf7, 0xa4, 0x75, 0xda, 0xea, 0x9b, 0xa, 0x64, 0xb, 0xe0, 0x23, 0x29, 0xbd, 0xf7, 0xe7, 0x83, 0x3c, 0xfb, 0xdf, 0xb3, 0xae, 0x4f, 0xa4, 0x47, 0x55, 0x99, 0xde, 0x2f, 0x96, 0x6e, 0x1c, 0x43, 0x4c, 0x87, 0xe2, 0x7c, 0xd9, 0x5f, 0x4c, 0x7c, 0xe8, 0x90, 0x3, 0xdb, 0x30, 0x95, 0xd6, 0x22, 0xc, 0x47, 0xb8, 0x4d, 0x6b, 0xbd, 0x24, 0x11, 0xab, 0x2c, 0xd7, 0xbe, 0x6e, 0x7a, 0xd6, 0x8, 0xa3, 0x98, 0xd8, 0xdd, 0x15, 0x6a, 0xfa, 0x93, 0x30, 0x1, 0x25, 0x1d, 0xa2, 0x74, 0x86, 0x4b, 0x6a, 0x95, 0xe8, 0xe1, 0x4e, 0xe, 0x76, 0xb9, 0x49, 0xa9, 0x5f, 0xa0, 0xa6, 0x63, 0x3c, 0x7e, 0x7e, 0x20, 0x13, 0x4f, 0xbb, 0x66, 0x92, 0xb8, 0x2e, 0xa4, 0xfa, 0x48, 0xcb, 0xae, 0xb9, 0x3c, 0xaf, 0xd3, 0x1f, 0xe1, 0xd5, 0x8d, 0x42, 0x6d, 0xf0, 0xfc, 0x8c, 0xc, 0x0, 0xde, 0x40, 0xab, 0x8b, 0x47, 0x97, 0x4e, 0xa8, 0xcf, 0x8e, 0xdb, 0xa6, 0x8b, 0x20, 0x9, 0x84, 0x7a, 0x66, 0xe5, 0x98, 0x29, 0x2, 0x95, 0xe6, 0x38, 0x32, 0x60, 0x3, 0xe3, 0x9a, 0x1e, 0x54, 0xe8, 0x63, 0x80, 0x48, 0x9c, 0xe7, 0x63, 0x33, 0x6e, 0xa0, 0x65, 0x83, 0xfa, 0xc6, 0xba, 0x7a, 0x43, 0x71, 0x5, 0xf5, 0x68, 0x69, 0x85, 0x9c, 0xba, 0x45, 0xcd, 0x6b, 0xb, 0x19, 0xd1, 0xbb, 0x7f, 0x70, 0x85, 0x92, 0xd1, 0xb4, 0x64, 0x82, 0xb1, 0xe4, 0x62, 0xc5, 0x3c, 0x46, 0x1f, 0x92, 0x31, 0x1c, 0x4e, 0x41, 0x77, 0xf7, 0xe7, 0x87, 0xa2, 0xf, 0x6e, 0xe8, 0x92, 0x3, 0x6b, 0xa, 0xe7, 0xa9, 0x3b, 0x11, 0xda, 0x66, 0x8a, 0x29, 0xda, 0x79, 0xe1, 0x64, 0x8d, 0xe3, 0x54, 0xd4, 0xf5, 0xef, 0x64, 0x87, 0x3b, 0xf4, 0xc2, 0xf4, 0x71, 0x13, 0xa9, 0xe9, 0xe0, 0xa2, 0x6, 0x14, 0xab, 0x5d, 0xa7, 0x96, 0x0, 0xd6, 0xc3, 0xcc, 0x57, 0xed, 0x39, 0x6a, 0x25, 0xcd, 0x76, 0xea, 0xba, 0x3a, 0xf2, 0xa1, 0x95, 0x5d, 0xe5, 0x71, 0xcf, 0x9c, 0x62, 0x9e, 0x6a, 0xfa, 0xd5, 0x31, 0xd1, 0xa8, 0x66, 0x30, 0x33, 0xaa, 0x51, 0x17, 0x13, 0x82, 0x99, 0xc8, 0x14, 0x60, 0x9f, 0x4d, 0x32, 0x6d, 0xda, 0x19, 0x26, 0x21, 0xdc, 0x7e, 0x2e, 0x25, 0x67, 0x72, 0xca, 0xf, 0x92, 0xcd, 0xf6, 0xd6, 0xcb, 0x97, 0x8a, 0x33, 0x58, 0x73, 0x70, 0x91, 0x1d, 0xbf, 0x28, 0x23, 0xa3, 0xc, 0xf1, 0x83, 0xc3, 0xc8, 0x56, 0x77, 0x68, 0xe3, 0x82, 0xba, 0xb9, 0x57, 0x56, 0x57, 0x9c, 0xc3, 0xd6, 0x14, 0x5, 0x3c, 0xb1, 0xaf, 0x93, 0xc8, 0x8a, 0x57, 0x7f, 0x53, 0xfa, 0x2f, 0xaa, 0x6e, 0x66, 0x83, 0xfa, 0x33, 0xd1, 0x21, 0xab, 0x1b, 0x71, 0xb4, 0x7c, 0xda, 0xfd, 0xfb, 0x7f, 0x20, 0xab, 0x5e, 0xd5, 0xca, 0xfd, 0xdd, 0xe0, 0xee, 0xda, 0xba, 0xa8, 0x27, 0x99, 0x97, 0x69, 0xc1, 0x3c, 0x82, 0x8c, 0xa, 0x5c, 0x2d, 0x5b, 0x88, 0x3e, 0x34, 0x35, 0x86, 0x37, 0x46, 0x79, 0xe1, 0xaa, 0x19, 0xfb, 0xaa, 0xde, 0x15, 0x9, 0xd, 0x1a, 0x57, 0xff, 0xb5, 0xf, 0xf3, 0x2b, 0x5a, 0x6a, 0x4d, 0x19, 0x77, 0x71, 0x45, 0xdf, 0x4f, 0xb3, 0xec, 0xf1, 0xeb, 0x18, 0x53, 0x3e, 0x3b, 0x47, 0x8, 0x9a, 0x73, 0xa0, 0x5c, 0x8c, 0x5f, 0xeb, 0xf, 0x3a, 0xc2, 0x43, 0x67, 0xb4, 0x66, 0x67, 0x80, 0x58, 0xe, 0xc1, 0xec, 0x40, 0xd4, 0x22, 0x94, 0xca, 0xf9, 0xe8, 0x92, 0xe4, 0x69, 0x38, 0xbe, 0x67, 0x64, 0xca, 0x50, 0xc7, 0x6, 0x67, 0x42, 0x6e, 0xa3, 0xf0, 0xb7, 0x6c, 0xf2, 0xe8, 0x5f, 0xb1, 0xaf, 0xe7, 0xdb, 0xbb, 0x77, 0xb5, 0xf8, 0xcb, 0x8, 0xc4, 0x75, 0x7e, 0xc0, 0xf9, 0x1c, 0x7f, 0x3c, 0x89, 0x2f, 0xd2, 0x58, 0x3a, 0xe2, 0xf8, 0x91, 0xb6, 0x7b, 0x24, 0x27, 0xe9, 0xae, 0x84, 0x8b, 0xde, 0x74, 0xac, 0xfd, 0xd9, 0xb7, 0x69, 0x2a, 0xec, 0x32, 0x6f, 0xf0, 0x92, 0x84, 0xf1, 0x40, 0xc, 0x8a, 0xbc, 0x39, 0x6e, 0x2e, 0x73, 0xd4, 0x6e, 0x8a, 0x74, 0x2a, 0xdc, 0x60, 0x1f, 0xa3, 0x7, 0xde, 0x75, 0x8b, 0x74, 0xc8, 0xfe, 0x63, 0x75, 0xf6, 0x3d, 0x63, 0xac, 0x33, 0x89, 0xc3, 0xf0, 0xf8, 0x2d, 0x6b, 0xb4, 0x9e, 0x74, 0x8b, 0x5c, 0x33, 0xb4, 0xca, 0xa8, 0xe4, 0x99, 0xb6, 0x90, 0xa1, 0xef, 0xf, 0xd3, 0x61, 0xb2, 0xc6, 0x1a, 0x94, 0x7c, 0x44, 0x55, 0xf4, 0x45, 0xff, 0x9e, 0xa5, 0x5a, 0xc6, 0xa0, 0xe8, 0x2a, 0xc1, 0x8d, 0x6f, 0x34, 0x11, 0xb9, 0xbe, 0x4e, 0xd9, 0x87, 0x97, 0x73, 0xcf, 0x3d, 0x23, 0xae, 0xd5, 0x1a, 0x5e, 0xae, 0x5d, 0x6a, 0x3, 0xf9, 0x22, 0xd, 0x10, 0xd9, 0x47, 0x69, 0x15, 0x3f, 0xee, 0x52, 0xa3, 0x8, 0xd2, 0x3c, 0x51, 0xf4, 0xf8, 0x9d, 0xe4, 0x98, 0x89, 0xc8, 0x67, 0x39, 0xd5, 0x5e, 0x35, 0x78, 0x27, 0xe8, 0x3c, 0x80, 0xae, 0x79, 0x71, 0xd2, 0x93, 0xf4, 0xaa, 0x51, 0x12, 0x1c, 0x4b, 0x1b, 0xe5, 0x6e, 0x15, 0x6f, 0xe4, 0xbb, 0x51, 0x9b, 0x45, 0x9f, 0xf9, 0xc4, 0x8c, 0x2a, 0xfb, 0x1a, 0xdf, 0x55, 0xd3, 0x48, 0x93, 0x27, 0x1, 0x26, 0xc2, 0x6b, 0x55, 0x6d, 0xa2, 0xfb, 0x84, 0x8b, 0xc9, 0x9e, 0x28, 0xc2, 0xef, 0x1a, 0x24, 0xec, 0x9b, 0xae, 0xbd, 0x60, 0xe9, 0x15, 0x35, 0xee, 0x42, 0xa4, 0x33, 0x5b, 0xfa, 0xf, 0xb6, 0xf7, 0x1, 0xa6, 0x2, 0x4c, 0xca, 0x90, 0x58, 0x3a, 0x96, 0x41, 0xe7, 0xcb, 0x9, 0x8c, 0xdb, 0x85, 0x4d, 0xa8, 0x89, 0xf3, 0xb5, 0x8e, 0xfd, 0x75, 0x5b, 0x4f, 0xed, 0xde, 0x3f, 0xeb, 0x38, 0xa3, 0xbe, 0xb0, 0x73, 0xfc, 0xb8, 0x54, 0xf7, 0x4c, 0x30, 0x67, 0x2e, 0x38, 0xa2, 0x54, 0x18, 0xba, 0x8, 0xbf, 0xf2, 0x39, 0xd5, 0xfe, 0xa5, 0x41, 0xc6, 0x66, 0x66, 0xba, 0x81, 0xef, 0x67, 0xe4, 0xe6, 0x3c, 0xc, 0xca, 0xa4, 0xa, 0x79, 0xb3, 0x57, 0x8b, 0x8a, 0x75, 0x98, 0x18, 0x42, 0x2f, 0x29, 0xa3, 0x82, 0xef, 0x9f, 0x86, 0x6, 0x23, 0xe1, 0x75, 0xfa, 0x8, 0xb1, 0xde, 0x17, 0x4a},
	},
	{
		input:       "testdata/huffman-rand-limit.in",
		want:        "testdata/huffman-rand-limit.%s.expect",
		wantNoInput: "testdata/huffman-rand-limit.%s.expect-noinput",
		tokens:      []token{0x61, 0x51c00000, 0xa, 0xf8, 0x8b, 0x96, 0x76, 0x48, 0xa, 0x85, 0x94, 0x25, 0x80, 0xaf, 0xc2, 0xfe, 0x8d, 0xe8, 0x20, 0xeb, 0x17, 0x86, 0xc9, 0xb7, 0xc5, 0xde, 0x6, 0xea, 0x7d, 0x18, 0x8b, 0xe7, 0x3e, 0x7, 0xda, 0xdf, 0xff, 0x6c, 0x73, 0xde, 0xcc, 0xe7, 0x6d, 0x8d, 0x4, 0x19, 0x49, 0x7f, 0x47, 0x1f, 0x48, 0x15, 0xb0, 0xe8, 0x9e, 0xf2, 0x31, 0x59, 0xde, 0x34, 0xb4, 0x5b, 0xe5, 0xe0, 0x9, 0x11, 0x30, 0xc2, 0x88, 0x5b, 0x7c, 0x5d, 0x14, 0x13, 0x6f, 0x23, 0xa9, 0xa, 0xbc, 0x2d, 0x23, 0xbe, 0xd9, 0xed, 0x75, 0x4, 0x6c, 0x99, 0xdf, 0xfd, 0x70, 0x66, 0xe6, 0xee, 0xd9, 0xb1, 0x9e, 0x6e, 0x83, 0x59, 0xd5, 0xd4, 0x80, 0x59, 0x98, 0x77, 0x89, 0x43, 0x38, 0xc9, 0xaf, 0x30, 0x32, 0x9a, 0x20, 0x1b, 0x46, 0x3d, 0x67, 0x6e, 0xd7, 0x72, 0x9e, 0x4e, 0x21, 0x4f, 0xc6, 0xe0, 0xd4, 0x7b, 0x4, 0x8d, 0xa5, 0x3, 0xf6, 0x5, 0x9b, 0x6b, 0xdc, 0x2a, 0x93, 0x77, 0x28, 0xfd, 0xb4, 0x62, 0xda, 0x20, 0xe7, 0x1f, 0xab, 0x6b, 0x51, 0x43, 0x39, 0x2f, 0xa0, 0x92, 0x1, 0x6c, 0x75, 0x3e, 0xf4, 0x35, 0xfd, 0x43, 0x2e, 0xf7, 0xa4, 0x75, 0xda, 0xea, 0x9b, 0xa},
	},
	{
		input:       "testdata/huffman-shifts.in",
		want:        "testdata/huffman-shifts.%s.expect",
		wantNoInput: "testdata/huffman-shifts.%s.expect-noinput",
		tokens:      []token{0x31, 0x30, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x52400001, 0xd, 0xa, 0x32, 0x33, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7fc00001, 0x7f400001},
	},
	{
		input:       "testdata/huffman-text-shift.in",
		want:        "testdata/huffman-text-shift.%s.expect",
		wantNoInput: "testdata/huffman-text-shift.%s.expect-noinput",
		tokens:      []token{0x2f, 0x2f, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x32, 0x30, 0x30, 0x39, 0x54, 0x68, 0x47, 0x6f, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x2e, 0x41, 0x6c, 0x6c, 0x40800016, 0x72, 0x72, 0x76, 0x64, 0x2e, 0xd, 0xa, 0x2f, 0x2f, 0x55, 0x6f, 0x66, 0x74, 0x68, 0x69, 0x6f, 0x75, 0x72, 0x63, 0x63, 0x6f, 0x64, 0x69, 0x67, 0x6f, 0x76, 0x72, 0x6e, 0x64, 0x62, 0x79, 0x42, 0x53, 0x44, 0x2d, 0x74, 0x79, 0x6c, 0x40400020, 0x6c, 0x69, 0x63, 0x6e, 0x74, 0x68, 0x74, 0x63, 0x6e, 0x62, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74, 0x68, 0x4c, 0x49, 0x43, 0x45, 0x4e, 0x53, 0x45, 0x66, 0x69, 0x6c, 0x2e, 0xd, 0xa, 0xd, 0xa, 0x70, 0x63, 0x6b, 0x67, 0x6d, 0x69, 0x6e, 0x4040000a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x6f, 0x22, 0x4040000c, 0x66, 0x75, 0x6e, 0x63, 0x6d, 0x69, 0x6e, 0x28, 0x29, 0x7b, 0xd, 0xa, 0x9, 0x76, 0x72, 0x62, 0x3d, 0x6d, 0x6b, 0x28, 0x5b, 0x5d, 0x62, 0x79, 0x74, 0x2c, 0x36, 0x35, 0x35, 0x33, 0x35, 0x29, 0xd, 0xa, 0x9, 0x66, 0x2c, 0x5f, 0x3a, 0x3d, 0x6f, 0x2e, 0x43, 0x72, 0x74, 0x28, 0x22, 0x68, 0x75, 0x66, 0x66, 0x6d, 0x6e, 0x2d, 0x6e, 0x75, 0x6c, 0x6c, 0x2d, 0x6d, 0x78, 0x2e, 0x69, 0x6e, 0x22, 0x40800021, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x28, 0x62, 0x29, 0xd, 0xa, 0x7d, 0xd, 0xa, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58, 0x78, 0x79, 0x7a, 0x21, 0x22, 0x23, 0xc2, 0xa4, 0x25, 0x26, 0x2f, 0x3f, 0x22},
	},
	{
		input:       "testdata/huffman-text.in",
		want:        "testdata/huffman-text.%s.expect",
		wantNoInput: "testdata/huffman-text.%s.expect-noinput",
		tokens:      []token{0x2f, 0x2f, 0x20, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x32, 0x30, 0x30, 0x39, 0x20, 0x54, 0x68, 0x65, 0x20, 0x47, 0x6f, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x2e, 0x20, 0x41, 0x6c, 0x6c, 0x20, 0x4080001e, 0x73, 0x20, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x2e, 0xd, 0xa, 0x2f, 0x2f, 0x20, 0x55, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x69, 0x73, 0x20, 0x67, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x61, 0x20, 0x42, 0x53, 0x44, 0x2d, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x40800036, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x62, 0x65, 0x20, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x49, 0x43, 0x45, 0x4e, 0x53, 0x45, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0xd, 0xa, 0xd, 0xa, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x4040000f, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x22, 0x6f, 0x73, 0x22, 0x4040000e, 0x66, 0x75, 0x6e, 0x63, 0x4080001b, 0x28, 0x29, 0x20, 0x7b, 0xd, 0xa, 0x9, 0x76, 0x61, 0x72, 0x20, 0x62, 0x20, 0x3d, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x28, 0x5b, 0x5d, 0x62, 0x79, 0x74, 0x65, 0x2c, 0x20, 0x36, 0x35, 0x35, 0x33, 0x35, 0x29, 0xd, 0xa, 0x9, 0x66, 0x2c, 0x20, 0x5f, 0x20, 0x3a, 0x3d, 0x20, 0x6f, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x28, 0x22, 0x68, 0x75, 0x66, 0x66, 0x6d, 0x61, 0x6e, 0x2d, 0x6e, 0x75, 0x6c, 0x6c, 0x2d, 0x6d, 0x61, 0x78, 0x2e, 0x69, 0x6e, 0x22, 0x4080002a, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x28, 0x62, 0x29, 0xd, 0xa, 0x7d, 0xd, 0xa},
	},
	{
		input:       "testdata/huffman-zero.in",
		want:        "testdata/huffman-zero.%s.expect",
		wantNoInput: "testdata/huffman-zero.%s.expect-noinput",
		tokens:      []token{0x30, ml, 0x4b800000},
	},
	{
		input:       "",
		want:        "",
		wantNoInput: "testdata/null-long-match.%s.expect-noinput",
		tokens:      []token{0x0, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, ml, 0x41400000},
	},
}

// TestWriteBlock tests if the writeBlock encoding has changed.
// To update the reference files use the "-update" flag on the test.
func TestWriteBlock(t *testing.T) {
	for _, test := range writeBlockTests {
		testBlock(t, test, "wb")
	}
}

// TestWriteBlockDynamic tests if the writeBlockDynamic encoding has changed.
// To update the reference files use the "-update" flag on the test.
func TestWriteBlockDynamic(t *testing.T) {
	for _, test := range writeBlockTests {
		testBlock(t, test, "dyn")
	}
shell
go test ./flate -run 'TestWriteBlock|TestBlockHuff|TestLargeLowEntropy' -count=1 -v
output
Chunk ID: 6d0c66
Wall time: 0.4924 seconds
Process exited with code 1
Original token count: 3714
Output:
=== RUN   TestBlockHuff
=== RUN   TestBlockHuff/testdata/huffman-null-max.in
    huffman_bit_writer_test.go:60: Testing "testdata/huffman-null-max.in"
    huffman_bit_writer_test.go:80: Output ok
    huffman_bit_writer_test.go:95: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
=== RUN   TestBlockHuff/testdata/huffman-pi.in
    huffman_bit_writer_test.go:60: Testing "testdata/huffman-pi.in"
    huffman_bit_writer_test.go:80: Output ok
    huffman_bit_writer_test.go:95: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
=== RUN   TestBlockHuff/testdata/huffman-rand-1k.in
    huffman_bit_writer_test.go:60: Testing "testdata/huffman-rand-1k.in"
    huffman_bit_writer_test.go:80: Output ok
    huffman_bit_writer_test.go:95: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
=== RUN   TestBlockHuff/testdata/huffman-rand-limit.in
    huffman_bit_writer_test.go:60: Testing "testdata/huffman-rand-limit.in"
    huffman_bit_writer_test.go:80: Output ok
    huffman_bit_writer_test.go:95: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
=== RUN   TestBlockHuff/testdata/huffman-rand-max.in
    huffman_bit_writer_test.go:60: Testing "testdata/huffman-rand-max.in"
    huffman_bit_writer_test.go:80: Output ok
    huffman_bit_writer_test.go:95: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
=== RUN   TestBlockHuff/testdata/huffman-shifts.in
    huffman_bit_writer_test.go:60: Testing "testdata/huffman-shifts.in"
    huffman_bit_writer_test.go:80: Output ok
    huffman_bit_writer_test.go:95: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
=== RUN   TestBlockHuff/testdata/huffman-text-shift.in
    huffman_bit_writer_test.go:60: Testing "testdata/huffman-text-shift.in"
    huffman_bit_writer_test.go:80: Output ok
    huffman_bit_writer_test.go:95: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
=== RUN   TestBlockHuff/testdata/huffman-text.in
    huffman_bit_writer_test.go:60: Testing "testdata/huffman-text.in"
    huffman_bit_writer_test.go:80: Output ok
    huffman_bit_writer_test.go:95: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
=== RUN   TestBlockHuff/testdata/huffman-zero.in
    huffman_bit_writer_test.go:60: Testing "testdata/huffman-zero.in"
    huffman_bit_writer_test.go:80: Output ok
    huffman_bit_writer_test.go:95: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
--- PASS: TestBlockHuff (0.00s)
    --- PASS: TestBlockHuff/testdata/huffman-null-max.in (0.00s)
    --- PASS: TestBlockHuff/testdata/huffman-pi.in (0.00s)
    --- PASS: TestBlockHuff/testdata/huffman-rand-1k.in (0.00s)
    --- PASS: TestBlockHuff/testdata/huffman-rand-limit.in (0.00s)
    --- PASS: TestBlockHuff/testdata/huffman-rand-max.in (0.00s)
    --- PASS: TestBlockHuff/testdata/huffman-shifts.in (0.00s)
    --- PASS: TestBlockHuff/testdata/huffman-text-shift.in (0.00s)
    --- PASS: TestBlockHuff/testdata/huffman-text.in (0.00s)
    --- PASS: TestBlockHuff/testdata/huffman-zero.in (0.00s)
=== RUN   TestWriteBlock
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-null-max.wb.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-null-max.wb.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-pi.wb.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-pi.wb.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-rand-1k.wb.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-rand-1k.wb.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-rand-limit.wb.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-rand-limit.wb.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-shifts.wb.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-shifts.wb.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-text-shift.wb.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-text-shift.wb.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-text.wb.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-text.wb.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-zero.wb.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-zero.wb.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/null-long-match.wb.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
--- PASS: TestWriteBlock (0.00s)
=== RUN   TestWriteBlockDynamic
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-null-max.dyn.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-null-max.dyn.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-pi.dyn.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-pi.dyn.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-rand-1k.dyn.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-rand-1k.dyn.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-rand-limit.dyn.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-rand-limit.dyn.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-shifts.dyn.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-shifts.dyn.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-text-shift.dyn.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-text-shift.dyn.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-text.dyn.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-text.dyn.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-zero.dyn.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-zero.dyn.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/null-long-match.dyn.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
--- PASS: TestWriteBlockDynamic (0.00s)
=== RUN   TestWriteBlockDynamicSync
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-null-max.sync.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-null-max.sync.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-pi.sync.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-pi.sync.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-rand-1k.sync.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-rand-1k.sync.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-rand-limit.sync.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-rand-limit.sync.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-shifts.sync.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-shifts.sync.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-text-shift.sync.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-text-shift.sync.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-text.sync.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-text.sync.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:230: Testing "testdata/huffman-zero.sync.expect"
    huffman_bit_writer_test.go:252: Output ok
    huffman_bit_writer_test.go:267: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/huffman-zero.sync.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
    huffman_bit_writer_test.go:270: Testing "testdata/null-long-match.sync.expect-noinput"
    huffman_bit_writer_test.go:291: Output ok
    huffman_bit_writer_test.go:306: Reset ok
    huffman_bit_writer_test.go:380: EOF ok
--- PASS: TestWriteBlockDynamicSync (0.00s)
=== RUN   TestLargeLowEntropyRoundTripVisible
    large_low_entropy_test.go:24: compressed len=9184 prefix=04 f8 ff ff ff ff ff ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    large_low_entropy_test.go:29: local err=flate: corrupt input before offset 10 len=0
    large_low_entropy_test.go:35: standard reader rejected stream: flate: corrupt input before offset 10
--- FAIL: TestLargeLowEntropyRoundTripVisible (0.52s)
FAIL
FAIL	[code-host]/klauspost/compress/flate	0.539s
FAIL
shell
sed -n '130,180p' flate/token.go
output
Chunk ID: acba16
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 228
Output:
type tokens struct {
	extraHist [32]uint16  // codes 256->maxnumlit
	offHist   [32]uint16  // offset codes
	litHist   [256]uint16 // codes 0->255
	nFilled   int
	n         uint16 // Must be able to contain maxStoreBlockSize
	tokens    [maxStoreBlockSize + 1]token
}

func (t *tokens) Reset() {
	if t.n == 0 {
		return
	}
	t.n = 0
	t.nFilled = 0
	for i := range t.litHist[:] {
		t.litHist[i] = 0
	}
	for i := range t.extraHist[:] {
		t.extraHist[i] = 0
	}
	for i := range t.offHist[:] {
		t.offHist[i] = 0
	}
}

func (t *tokens) Fill() {
	if t.n == 0 {
		return
	}
	for i, v := range t.litHist[:] {
		if v == 0 {
			t.litHist[i] = 1
			t.nFilled++
		}
	}
	for i, v := range t.extraHist[:literalCount-256] {
		if v == 0 {
			t.nFilled++
			t.extraHist[i] = 1
		}
	}
	for i, v := range t.offHist[:offsetCodeCount] {
		if v == 0 {
			t.offHist[i] = 1
		}
	}
}

func indexTokens(in []token) tokens {
	var t tokens
shell
sed -n '262,310p' flate/token.go
output
Chunk ID: 29ea08
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 351
Output:
// AddMatch adds a match to the tokens.
// This function is very sensitive to inlining and right on the border.
func (t *tokens) AddMatch(xlength uint32, xoffset uint32) {
	if debugDeflate {
		if xlength >= maxMatchLength+baseMatchLength {
			panic(fmt.Errorf("invalid length: %v", xlength))
		}
		if xoffset >= maxMatchOffset+baseMatchOffset {
			panic(fmt.Errorf("invalid offset: %v", xoffset))
		}
	}
	oCode := offsetCode(xoffset)
	xoffset |= oCode << 16

	t.extraHist[lengthCodes1[uint8(xlength)]]++
	t.offHist[oCode&31]++
	t.tokens[t.n] = token(matchType | xlength<<lengthShift | xoffset)
	t.n++
}

// AddMatchLong adds a match to the tokens, potentially longer than max match length.
// Length should NOT have the base subtracted, only offset should.
func (t *tokens) AddMatchLong(xlength int32, xoffset uint32) {
	if debugDeflate {
		if xoffset >= maxMatchOffset+baseMatchOffset {
			panic(fmt.Errorf("invalid offset: %v", xoffset))
		}
	}
	oc := offsetCode(xoffset)
	xoffset |= oc << 16
	for xlength > 0 {
		xl := xlength
		if xl > 258 {
			// We need to have at least baseMatchLength left over for next loop.
			if xl > 258+baseMatchLength {
				xl = 258
			} else {
				xl = 258 - baseMatchLength
			}
		}
		xlength -= xl
		xl -= baseMatchLength
		t.extraHist[lengthCodes1[uint8(xl)]]++
		t.offHist[oc&31]++
		t.tokens[t.n] = token(matchType | uint32(xl)<<lengthShift | xoffset)
		t.n++
	}
}

shell
rg -n "func offsetCode|offsetCode\(" flate/token.go flate/huffman_bit_writer.go
output
Chunk ID: fad65f
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 38
Output:
flate/token.go:273:	oCode := offsetCode(xoffset)
flate/token.go:290:	oc := offsetCode(xoffset)
flate/token.go:365:func offsetCode(off uint32) uint32 {
shell
sed -n '340,386p' flate/token.go
output
Chunk ID: 73e266
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 251
Output:
		}
		if err != nil {
			return err
		}
		toks = append(toks, token(r))
	}
	t.indexTokens(toks)
	return nil
}

// Returns the type of a token
func (t token) typ() uint32 { return uint32(t) & typeMask }

// Returns the literal of a literal token
func (t token) literal() uint8 { return uint8(t) }

// Returns the extra offset of a match token
func (t token) offset() uint32 { return uint32(t) & offsetMask }

func (t token) length() uint8 { return uint8(t >> lengthShift) }

// Convert length to code.
func lengthCode(len uint8) uint8 { return lengthCodes[len] }

// Returns the offset code corresponding to a specific offset
func offsetCode(off uint32) uint32 {
	if false {
		if off < uint32(len(offsetCodes)) {
			return offsetCodes[off&255]
		} else if off>>7 < uint32(len(offsetCodes)) {
			return offsetCodes[(off>>7)&255] + 14
		} else {
			return offsetCodes[(off>>14)&255] + 28
		}
	}
	if off < uint32(len(offsetCodes)) {
		return offsetCodes[uint8(off)]
	}
	return offsetCodes14[uint8(off>>7)]
}
The likely bad edge is in the “better match at end” lookahead: it can select a candidate at or after the current match start, producing a zero or negative DEFLATE distance after unsigned conversion. I’m constraining that candidate to prior bytes only, then I’ll remove the debug logging and broaden the generated round-trip test.
apply_patch
*** Begin Patch
*** Update File: flate/deflate.go
@@
-					if prevIndex-ch2 != prevOffset && ch2 > minIndex+checkOff {
+					if ch2 < prevIndex && prevIndex-ch2 != prevOffset && ch2 > minIndex+checkOff {
@@
-							if prevIndex-ch2 != prevOffset && ch2 > minIndex+checkOff {
+							if ch2 < prevIndex && prevIndex-ch2 != prevOffset && ch2 > minIndex+checkOff {
*** End Patch


Exit code: 0
Wall time: 0 seconds
Output:
Success. Updated the following files:
M flate/deflate.go
I’ve made the compressor reject end-check candidates that are not actually behind the current position. Now I’m cleaning up the focused repro test and expanding it to cover levels, entropy shapes, and chunked writes without touching external corpora.
apply_patch
*** Begin Patch
*** Update File: flate/large_low_entropy_test.go
@@
-import (
-	"bytes"
-	stdflate "compress/flate"
-	"io"
-	"testing"
-)
-
-func TestLargeLowEntropyRoundTripVisible(t *testing.T) {
-	input := make([]byte, 1<<20)
-
-	var compressed bytes.Buffer
-	w, err := NewWriter(&compressed, BestCompression)
-	if err != nil {
-		t.Fatalf("NewWriter: %v", err)
-	}
-	if _, err := w.Write(input); err != nil {
-		t.Fatalf("Write: %v", err)
-	}
-	if err := w.Close(); err != nil {
-		t.Fatalf("Close: %v", err)
-	}
-	t.Logf("compressed len=%d prefix=% x", compressed.Len(), compressed.Bytes()[:min(compressed.Len(), 32)])
-
-	localReader := NewReader(bytes.NewReader(compressed.Bytes()))
-	localOut, localErr := io.ReadAll(localReader)
-	_ = localReader.Close()
-	t.Logf("local err=%v len=%d", localErr, len(localOut))
-
-	stdReader := stdflate.NewReader(bytes.NewReader(compressed.Bytes()))
-	stdOut, err := io.ReadAll(stdReader)
-	_ = stdReader.Close()
-	if err != nil {
-		t.Fatalf("standard reader rejected stream: %v", err)
-	}
-	if !bytes.Equal(stdOut, input) {
-		t.Fatalf("standard reader mismatch: got %d bytes, want %d", len(stdOut), len(input))
-	}
-
-	localReader = NewReader(bytes.NewReader(compressed.Bytes()))
-	localOut, err = io.ReadAll(localReader)
-	_ = localReader.Close()
-	if err != nil {
-		t.Fatalf("local reader rejected stream: %v", err)
-	}
-	if !bytes.Equal(localOut, input) {
-		t.Fatalf("local reader mismatch: got %d bytes, want %d", len(localOut), len(input))
-	}
-}
+import (
+	"bytes"
+	stdflate "compress/flate"
+	"fmt"
+	"io"
+	"testing"
+)
+
+func TestGeneratedRoundTrips(t *testing.T) {
+	inputs := map[string][]byte{
+		"zeros":      make([]byte, 1<<20),
+		"low":        generatedLowEntropy(1 << 20),
+		"medium":     generatedMediumEntropy(1 << 20),
+		"high":       generatedHighEntropy(1 << 20),
+		"block-edge": make([]byte, (1<<15)*258+1024),
+	}
+	levels := []int{
+		NoCompression,
+		HuffmanOnly,
+		BestSpeed,
+		DefaultCompression,
+		7,
+		8,
+		BestCompression,
+	}
+	chunks := []int{0, 1, 257, 32768}
+
+	for name, input := range inputs {
+		for _, level := range levels {
+			for _, chunk := range chunks {
+				t.Run(fmt.Sprintf("%s/level=%d/chunk=%d", name, level, chunk), func(t *testing.T) {
+					got := compressForRoundTrip(t, input, level, chunk)
+					assertRoundTrip(t, "standard", stdflate.NewReader(bytes.NewReader(got)), input)
+					assertRoundTrip(t, "local", NewReader(bytes.NewReader(got)), input)
+				})
+			}
+		}
+	}
+}
+
+func compressForRoundTrip(t *testing.T, input []byte, level, chunk int) []byte {
+	t.Helper()
+
+	var compressed bytes.Buffer
+	w, err := NewWriter(&compressed, level)
+	if err != nil {
+		t.Fatalf("NewWriter: %v", err)
+	}
+	if chunk <= 0 {
+		if _, err := w.Write(input); err != nil {
+			t.Fatalf("Write: %v", err)
+		}
+	} else {
+		for len(input) > 0 {
+			n := min(chunk, len(input))
+			if _, err := w.Write(input[:n]); err != nil {
+				t.Fatalf("Write chunk: %v", err)
+			}
+			input = input[n:]
+		}
+	}
+	if err := w.Close(); err != nil {
+		t.Fatalf("Close: %v", err)
+	}
+	return compressed.Bytes()
+}
+
+func assertRoundTrip(t *testing.T, name string, r io.ReadCloser, input []byte) {
+	t.Helper()
+
+	out, err := io.ReadAll(r)
+	closeErr := r.Close()
+	if err != nil {
+		t.Fatalf("%s reader rejected stream: %v", name, err)
+	}
+	if closeErr != nil {
+		t.Fatalf("%s reader close: %v", name, closeErr)
+	}
+	if !bytes.Equal(out, input) {
+		t.Fatalf("%s reader mismatch: got %d bytes, want %d", name, len(out), len(input))
+	}
+}
+
+func generatedLowEntropy(n int) []byte {
+	b := make([]byte, n)
+	for i := range b {
+		b[i] = byte((i >> 9) & 3)
+	}
+	return b
+}
+
+func generatedMediumEntropy(n int) []byte {
+	b := make([]byte, n)
+	for i := range b {
+		b[i] = byte((i*31 + i>>3) & 63)
+	}
+	return b
+}
+
+func generatedHighEntropy(n int) []byte {
+	b := make([]byte, n)
+	var x uint32 = 1
+	for i := range b {
+		x ^= x << 13
+		x ^= x >> 17
+		x ^= x << 5
+		b[i] = byte(x)
+	}
+	return b
+}
*** End Patch


Exit code: 0
Wall time: 0 seconds
Output:
Success. Updated the following files:
M flate/large_low_entropy_test.go
shell
gofmt -w flate/deflate.go flate/large_low_entropy_test.go && go test ./flate -run 'TestGeneratedRoundTrips|TestWriteBlock|TestBlockHuff' -count=1
output
Chunk ID: dc3ed7
Wall time: 1.0037 seconds
Process running with session ID 63141
Original token count: 0
Output:
shell
go test ./flate -run TestGeneratedRoundTrips/zeros/level=9/chunk=0 -count=1 -v
output
Chunk ID: 7888d9
Wall time: 0.9728 seconds
Process exited with code 1
Original token count: 91
Output:
=== RUN   TestGeneratedRoundTrips
=== RUN   TestGeneratedRoundTrips/zeros/level=9/chunk=0
    large_low_entropy_test.go:35: standard reader rejected stream: flate: corrupt input before offset 10
--- FAIL: TestGeneratedRoundTrips (0.60s)
    --- FAIL: TestGeneratedRoundTrips/zeros/level=9/chunk=0 (0.57s)
FAIL
FAIL	[code-host]/klauspost/compress/flate	0.600s
FAIL
The first constraint did not clear the repro, so the invalid token is coming from another path or from a different distance edge. I’m turning on the built-in deflate sanity checks briefly to catch the exact match parameters at emission.
apply_patch
*** Begin Patch
*** Update File: flate/deflate.go
@@
-	debugDeflate = false
+	debugDeflate = true
 )
*** End Patch


Exit code: 0
Wall time: 0 seconds
Output:
Success. Updated the following files:
M flate/deflate.go
shell
go test ./flate -run TestGeneratedRoundTrips/zeros/level=9/chunk=0 -count=1 -v
output
Chunk ID: 49b2af
Wall time: 0.7051 seconds
Process exited with code 1
Original token count: 91
Output:
=== RUN   TestGeneratedRoundTrips
=== RUN   TestGeneratedRoundTrips/zeros/level=9/chunk=0
    large_low_entropy_test.go:35: standard reader rejected stream: flate: corrupt input before offset 10
--- FAIL: TestGeneratedRoundTrips (0.55s)
    --- FAIL: TestGeneratedRoundTrips/zeros/level=9/chunk=0 (0.54s)
FAIL
FAIL	[code-host]/klauspost/compress/flate	0.547s
FAIL
The sanity checks show the match distances are within nominal bounds, so I’m inspecting the dynamic header inputs themselves. The failing output is much larger than an all-zero DEFLATE stream should be, which points at the chosen Huffman representation rather than raw LZ distance overflow.
apply_patch
*** Begin Patch
*** Update File: flate/huffman_bit_writer.go
@@
 	numLiterals, numOffsets := w.indexTokens(tokens, fillReuse && !sync)
+	if debugDeflate {
+		fmt.Println("writeBlockDynamic", "tokens", tokens.n, "sync", sync, "lastHeader", w.lastHeader, "numLiterals", numLiterals, "numOffsets", numOffsets, "lit0", w.literalFreq[0], "eob", w.literalFreq[endBlockMarker], "off0", w.offsetFreq[0], "off29", w.offsetFreq[29])
+	}
 	extraBits := 0
*** End Patch


Exit code: 0
Wall time: 0 seconds
Output:
Success. Updated the following files:
M flate/huffman_bit_writer.go
shell
gofmt -w flate/huffman_bit_writer.go && go test ./flate -run TestGeneratedRoundTrips/zeros/level=9/chunk=0 -count=1 -v
output
Chunk ID: deec82
Wall time: 0.7110 seconds
Process exited with code 1
Original token count: 177
Output:
=== RUN   TestGeneratedRoundTrips
=== RUN   TestGeneratedRoundTrips/zeros/level=9/chunk=0
writeBlockDynamic tokens 32768 sync false lastHeader 0 numLiterals 1 numOffsets 1 lit0 32768 eob 0 off0 1 off29 0
writeBlockDynamic tokens 32768 sync false lastHeader 0 numLiterals 286 numOffsets 1 lit0 32546 eob 0 off0 222 off29 0
writeBlockDynamic tokens 3591 sync true lastHeader 0 numLiterals 286 numOffsets 1 lit0 0 eob 1 off0 3590 off29 0
    large_low_entropy_test.go:35: standard reader rejected stream: flate: corrupt input before offset 10
--- FAIL: TestGeneratedRoundTrips (0.53s)
    --- FAIL: TestGeneratedRoundTrips/zeros/level=9/chunk=0 (0.53s)
FAIL
FAIL	[code-host]/klauspost/compress/flate	0.533s
FAIL
shell
rg -n "func \(.*bitLengthRaw|func \(.*generate" flate/huffman_code.go flate/*.go
output
Chunk ID: 231274
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 140
Output:
flate/huffman_code.go:142:func (h *huffmanEncoder) bitLengthRaw(b []byte) int {
flate/huffman_code.go:339:func (h *huffmanEncoder) generate(freq []uint16, maxBits int32) {
flate/huffman_bit_writer.go:269:func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litEnc, offEnc *huffmanEncoder) {
flate/huffman_bit_writer.go:819:func (w *huffmanBitWriter) generate() {
flate/huffman_code.go:142:func (h *huffmanEncoder) bitLengthRaw(b []byte) int {
flate/huffman_code.go:339:func (h *huffmanEncoder) generate(freq []uint16, maxBits int32) {
shell
sed -n '136,156p' flate/huffman_code.go && sed -n '330,380p' flate/huffman_code.go
output
Chunk ID: 658cb6
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 454
Output:
			total += int(f) * int(h.codes[i].len())
		}
	}
	return total
}

func (h *huffmanEncoder) bitLengthRaw(b []byte) int {
	var total int
	for _, f := range b {
		total += int(h.codes[f].len())
	}
	return total
}

// canReuseBits returns the number of bits or math.MaxInt32 if the encoder cannot be reused.
func (h *huffmanEncoder) canReuseBits(freq []uint16) int {
	var total int
	for i, f := range freq {
		if f != 0 {
			code := h.codes[i]
			if code.zero() {
		}
		list = list[0 : len(list)-int(bits)]
	}
}

// Update this Huffman Code object to be the minimum code for the specified frequency count.
//
// freq  An array of frequencies, in which frequency[i] gives the frequency of literal i.
// maxBits  The maximum number of bits to use for any literal.
func (h *huffmanEncoder) generate(freq []uint16, maxBits int32) {
	list := h.freqcache[:len(freq)+1]
	codes := h.codes[:len(freq)]
	// Number of non-zero literals
	count := 0
	// Set list to be the set of all non-zero literals and their frequencies
	for i, f := range freq {
		if f != 0 {
			list[count] = literalNode{uint16(i), f}
			count++
		} else {
			codes[i] = 0
		}
	}
	list[count] = literalNode{}

	list = list[:count]
	if count <= 2 {
		// Handle the small cases here, because they are awkward for the general case code. With
		// two or fewer literals, everything has bit length 1.
		for i, node := range list {
			// "list" is in order of increasing literal value.
			h.codes[node.literal].set(uint16(i), 1)
		}
		return
	}
	sortByFreq(list)

	// Get the number of literals for each bit count
	bitCount := h.bitCounts(list, maxBits)
	// And do the assignment
	h.assignEncodingAndSize(bitCount, list)
}

// atLeastOne clamps the result between 1 and 15.
func atLeastOne(v float32) float32 {
	if v < 1 {
		return 1
	}
	if v > 15 {
		return 15
	}
The exact failure is a 16-bit histogram overflow in the high-compression literal cost model: a full 64 KiB all-zero window wraps the zero count back to 0, making literals look free and causing a malformed literal-only dynamic block. I’m applying the focused saturation fix in `deflateLazy` and removing temporary diagnostics.
apply_patch
*** Begin Patch
*** Update File: flate/deflate.go
@@
-	debugDeflate = true
+	debugDeflate = false
@@
-		for _, v := range d.window[s.index:d.windowEnd] {
-			tmp[v]++
+		for _, v := range d.window[s.index:d.windowEnd] {
+			if tmp[v] != ^uint16(0) {
+				tmp[v]++
+			}
 		}
*** End Patch


Exit code: 0
Wall time: 0 seconds
Output:
Success. Updated the following files:
M flate/deflate.go
apply_patch
*** Begin Patch
*** Update File: flate/huffman_bit_writer.go
@@
 	numLiterals, numOffsets := w.indexTokens(tokens, fillReuse && !sync)
-	if debugDeflate {
-		fmt.Println("writeBlockDynamic", "tokens", tokens.n, "sync", sync, "lastHeader", w.lastHeader, "numLiterals", numLiterals, "numOffsets", numOffsets, "lit0", w.literalFreq[0], "eob", w.literalFreq[endBlockMarker], "off0", w.offsetFreq[0], "off29", w.offsetFreq[29])
-	}
 	extraBits := 0
*** End Patch


Exit code: 0
Wall time: 0 seconds
Output:
Success. Updated the following files:
M flate/huffman_bit_writer.go
The diagnostic output is gone. I’m running the generated matrix plus the available Huffman golden checks now; this should verify the new regression case without relying on the missing upstream text corpora.
shell
gofmt -w flate/deflate.go flate/huffman_bit_writer.go flate/large_low_entropy_test.go && go test ./flate -run 'TestGeneratedRoundTrips|TestWriteBlock|TestBlockHuff' -count=1
output
Chunk ID: 9c9ed8
Wall time: 1.0038 seconds
Process running with session ID 98648
Original token count: 0
Output:
shell
go test ./flate -run TestGeneratedRoundTrips/zeros/level=9/chunk=0 -count=1 -v
output
Chunk ID: 029fe0
Wall time: 0.3459 seconds
Process exited with code 0
Original token count: 64
Output:
=== RUN   TestGeneratedRoundTrips
=== RUN   TestGeneratedRoundTrips/zeros/level=9/chunk=0
--- PASS: TestGeneratedRoundTrips (0.01s)
    --- PASS: TestGeneratedRoundTrips/zeros/level=9/chunk=0 (0.00s)
PASS
ok  	[code-host]/klauspost/compress/flate	0.008s
The direct all-zero level 9 repro now passes against the standard reader. The broader generated matrix is still running; I’m waiting for that before moving to `go build ./...`.
write_stdin
{
  "session_id": 98648,
  "chars": "",
  "yield_time_ms": 30000,
  "max_output_tokens": 24000
}

, output, 
Chunk ID: 1d5db0
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 12
Output:
ok  	[code-host]/klauspost/compress/flate	1.341s
The generated matrix and available Huffman golden checks passed. I’m running the requested full module build next, then I’ll do one final focused test pass for the regression file.
shell
go build ./...
output
Chunk ID: 1a6e62
Wall time: 0.0358 seconds
Process exited with code 0
Original token count: 0
Output:
shell
go test ./flate -run TestGeneratedRoundTrips -count=1
output
Chunk ID: 3bd0c9
Wall time: 1.0063 seconds
Process running with session ID 51261
Original token count: 0
Output:
shell
go test ./flate -run 'TestWriteBlock|TestBlockHuff' -count=1
output
Chunk ID: 8acaa8
Wall time: 0.0342 seconds
Process exited with code 0
Original token count: 12
Output:
ok  	[code-host]/klauspost/compress/flate	0.013s
`go build ./...` completed successfully, and the available Huffman golden tests are stable. I’m just waiting for the full generated round-trip matrix to finish.
write_stdin
{
  "session_id": 51261,
  "chars": "",
  "yield_time_ms": 30000,
  "max_output_tokens": 20000
}

, output, 
Chunk ID: fbf562
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 12
Output:
ok  	[code-host]/klauspost/compress/flate	1.293s
shell
nl -ba flate/deflate.go | sed -n '416,432p;492,504p;540,548p'
output
Chunk ID: a15c6f
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 399
Output:
   416			return
   417		}
   418		if d.windowEnd != s.index && d.chain > 100 {
   419			// Get literal huffman coder.
   420			if d.h == nil {
   421				d.h = newHuffmanEncoder(maxFlateBlockTokens)
   422			}
   423			var tmp [256]uint16
   424			for _, v := range d.window[s.index:d.windowEnd] {
   425				if tmp[v] != ^uint16(0) {
   426					tmp[v]++
   427				}
   428			}
   429			d.h.generate(tmp[:], 15)
   430		}
   431	
   432		s.maxInsertIndex = d.windowEnd - (minMatchLength - 1)
   492					prevIndex := s.index - 1
   493					if prevIndex+prevLength < s.maxInsertIndex {
   494						end := min(lookahead, maxMatchLength+checkOff)
   495						end += prevIndex
   496	
   497						// Hash at match end.
   498						h := hash4(d.window[prevIndex+prevLength:])
   499						ch2 := int(s.hashHead[h]) - s.hashOffset - prevLength
   500						if ch2 < prevIndex && prevIndex-ch2 != prevOffset && ch2 > minIndex+checkOff {
   501							length := matchLen(d.window[prevIndex+checkOff:end], d.window[ch2+checkOff:])
   502							// It seems like a pure length metric is best.
   503							if length > prevLength {
   504								prevLength = length
   540								if ch2 < prevIndex && prevIndex-ch2 != prevOffset && ch2 > minIndex+checkOff {
   541									length := matchLen(d.window[prevIndex+checkOff:end], d.window[ch2+checkOff:])
   542									// It seems like a pure length metric is best.
   543									if length > prevLength+checkOff {
   544										prevLength = length
   545										prevOffset = prevIndex - ch2
   546										prevIndex--
   547	
   548										// Extend back...
shell
nl -ba flate/large_low_entropy_test.go | sed -n '1,180p'
output
Chunk ID: 5113e2
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 801
Output:
     1	package flate
     2	
     3	import (
     4		"bytes"
     5		stdflate "compress/flate"
     6		"fmt"
     7		"io"
     8		"testing"
     9	)
    10	
    11	func TestGeneratedRoundTrips(t *testing.T) {
    12		inputs := map[string][]byte{
    13			"zeros":      make([]byte, 1<<20),
    14			"low":        generatedLowEntropy(1 << 20),
    15			"medium":     generatedMediumEntropy(1 << 20),
    16			"high":       generatedHighEntropy(1 << 20),
    17			"block-edge": make([]byte, (1<<15)*258+1024),
    18		}
    19		levels := []int{
    20			NoCompression,
    21			HuffmanOnly,
    22			BestSpeed,
    23			DefaultCompression,
    24			7,
    25			8,
    26			BestCompression,
    27		}
    28		chunks := []int{0, 1, 257, 32768}
    29	
    30		for name, input := range inputs {
    31			for _, level := range levels {
    32				for _, chunk := range chunks {
    33					t.Run(fmt.Sprintf("%s/level=%d/chunk=%d", name, level, chunk), func(t *testing.T) {
    34						got := compressForRoundTrip(t, input, level, chunk)
    35						assertRoundTrip(t, "standard", stdflate.NewReader(bytes.NewReader(got)), input)
    36						assertRoundTrip(t, "local", NewReader(bytes.NewReader(got)), input)
    37					})
    38				}
    39			}
    40		}
    41	}
    42	
    43	func compressForRoundTrip(t *testing.T, input []byte, level, chunk int) []byte {
    44		t.Helper()
    45	
    46		var compressed bytes.Buffer
    47		w, err := NewWriter(&compressed, level)
    48		if err != nil {
    49			t.Fatalf("NewWriter: %v", err)
    50		}
    51		if chunk <= 0 {
    52			if _, err := w.Write(input); err != nil {
    53				t.Fatalf("Write: %v", err)
    54			}
    55		} else {
    56			for len(input) > 0 {
    57				n := min(chunk, len(input))
    58				if _, err := w.Write(input[:n]); err != nil {
    59					t.Fatalf("Write chunk: %v", err)
    60				}
    61				input = input[n:]
    62			}
    63		}
    64		if err := w.Close(); err != nil {
    65			t.Fatalf("Close: %v", err)
    66		}
    67		return compressed.Bytes()
    68	}
    69	
    70	func assertRoundTrip(t *testing.T, name string, r io.ReadCloser, input []byte) {
    71		t.Helper()
    72	
    73		out, err := io.ReadAll(r)
    74		closeErr := r.Close()
    75		if err != nil {
    76			t.Fatalf("%s reader rejected stream: %v", name, err)
    77		}
    78		if closeErr != nil {
    79			t.Fatalf("%s reader close: %v", name, closeErr)
    80		}
    81		if !bytes.Equal(out, input) {
    82			t.Fatalf("%s reader mismatch: got %d bytes, want %d", name, len(out), len(input))
    83		}
    84	}
    85	
    86	func generatedLowEntropy(n int) []byte {
    87		b := make([]byte, n)
    88		for i := range b {
    89			b[i] = byte((i >> 9) & 3)
    90		}
    91		return b
    92	}
    93	
    94	func generatedMediumEntropy(n int) []byte {
    95		b := make([]byte, n)
    96		for i := range b {
    97			b[i] = byte((i*31 + i>>3) & 63)
    98		}
    99		return b
   100	}
   101	
   102	func generatedHighEntropy(n int) []byte {
   103		b := make([]byte, n)
   104		var x uint32 = 1
   105		for i := range b {
   106			x ^= x << 13
   107			x ^= x >> 17
   108			x ^= x << 5
   109			b[i] = byte(x)
   110		}
   111		return b
   112	}
shell
go test ./flate -run TestDeflateInflateString -count=1
output
Chunk ID: bdd938
Wall time: 0.0000 seconds
Process exited with code 1
Original token count: 355
Output:
--- FAIL: TestDeflateInflateString (0.00s)
    deflate_test.go:387: open ../testdata/e.txt: no such file or directory
    deflate_test.go:320: level: 0 - Size:0.00%, 2 b
    deflate_test.go:320: level: 1 - Size:0.00%, 2 b
    deflate_test.go:320: level: 2 - Size:0.00%, 2 b
    deflate_test.go:320: level: 3 - Size:0.00%, 2 b
    deflate_test.go:320: level: 4 - Size:0.00%, 2 b
    deflate_test.go:320: level: 5 - Size:0.00%, 2 b
    deflate_test.go:320: level: 6 - Size:0.00%, 2 b
    deflate_test.go:320: level: 7 - Size:0.00%, 2 b
    deflate_test.go:320: level: 8 - Size:0.00%, 2 b
    deflate_test.go:320: level: 9 - Size:0.00%, 2 b
    deflate_test.go:320: level: -2 - Size:0.00%, 2 b
    deflate_test.go:387: open ../testdata/Mark.Twain-Tom.Sawyer.txt: no such file or directory
    deflate_test.go:320: level: 0 - Size:0.00%, 2 b
    deflate_test.go:320: level: 1 - Size:0.00%, 2 b
    deflate_test.go:320: level: 2 - Size:0.00%, 2 b
    deflate_test.go:320: level: 3 - Size:0.00%, 2 b
    deflate_test.go:320: level: 4 - Size:0.00%, 2 b
    deflate_test.go:320: level: 5 - Size:0.00%, 2 b
    deflate_test.go:320: level: 6 - Size:0.00%, 2 b
    deflate_test.go:320: level: 7 - Size:0.00%, 2 b
    deflate_test.go:320: level: 8 - Size:0.00%, 2 b
    deflate_test.go:320: level: 9 - Size:0.00%, 2 b
    deflate_test.go:320: level: -2 - Size:0.00%, 2 b
FAIL
FAIL	[code-host]/klauspost/compress/flate	0.005s
FAIL
Implemented the compressor fix. Changed [flate/deflate.go](/app/flate/deflate.go:423) so the high-compression literal Huffman cost model saturates its `uint16` frequency counters instead of wrapping on 64 KiB low-entropy windows. I also guarded the end-match lookahead candidate so it only considers prior bytes, avoiding invalid future/self match choices. Added generated regression coverage in [flate/large_low_entropy_test.go](/app/flate/large_low_entropy_test.go:11) for low, medium, high entropy inputs across single and chunked writes, and levels `0`, `-2`, `1`, `-1`, `7`, `8`, `9`, checked against both the standard library DEFLATE reader and this module’s reader. Verification: - `go test ./flate -run 'TestGeneratedRoundTrips|TestWriteBlock|TestBlockHuff' -count=1` passed - `go build ./...` passed - Broad corpus-style tests still fail where expected because `../testdata/e.txt` and `../testdata/Mark.Twain-Tom.Sawyer.txt` are absent.
Final diff , what the agent changed

No file changes, the agent left the workspace untouched.

Verifier output , the proof behind the reward
tests/test.sh
============================= test session starts ==============================
platform linux -- Python 3.11.2, pytest-8.3.3, pluggy-1.6.0 -- /opt/test-venv/bin/python3
cachedir: .pytest_cache
rootdir: /tests
collecting ... collected 5 items

../tests/test_outputs.py::test_package_builds PASSED                     [ 20%]
../tests/test_outputs.py::test_flate_streams_roundtrip PASSED            [ 40%]
../tests/test_outputs.py::test_held_back_actually_ran PASSED             [ 60%]
../tests/test_outputs.py::test_existing_flate_package_tests_pass PASSED  [ 80%]
../tests/test_outputs.py::test_no_hardcoded_hidden_literals PASSED       [100%]

==================================== PASSES ====================================
=========================== short test summary info ============================
PASSED ../tests/test_outputs.py::test_package_builds
PASSED ../tests/test_outputs.py::test_flate_streams_roundtrip
PASSED ../tests/test_outputs.py::test_held_back_actually_ran
PASSED ../tests/test_outputs.py::test_existing_flate_package_tests_pass
PASSED ../tests/test_outputs.py::test_no_hardcoded_hidden_literals
============================== 5 passed in 7.35s ===============================

Reproduce this trial: git checkout 2f94510 && PYTHONPATH=src python3 scripts/build_site.py , then open trial/trial_0ba3b0dde444496f. Re-running the agent live requires EVAL_PLATFORM_ENABLE_OAUTH_SMOKE=1 and is non-deterministic.

Trial trial_0ba3b0dde444496f · verifier authoritative; classifier explanatory.