Conversation
Fixes minor difference to stdlib, which doesn't do a 0 byte write.
📝 WalkthroughWalkthroughAdds example tests in flate/example_test.go demonstrating Reset reuse, dictionary-based compression, and streaming synchronization. Modifies huffmanBitWriter.flush to conditionally write buffered bytes only when present (n > 0). No exported API changes. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Caller
participant BW as huffmanBitWriter
participant W as underlying io.Writer
C->>BW: flush()
BW->>BW: finalize bits/EOB, compute n
alt n > 0
BW->>W: Write(buffer[0:n])
W-->>BW: bytes written / error
else n == 0
BW-->>BW: skip final write
end
BW-->>C: return error (if any)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
flate/example_test.go (1)
128-129: Use consistent Reader source for clarity.Mixing bytes.NewReader(b.Bytes()) and &b works, but using bytes.NewReader in both places avoids relying on bytes.Buffer read state if this example is edited later.
- zr = flate.NewReaderDict(&b, hashDict) + zr = flate.NewReaderDict(bytes.NewReader(b.Bytes()), hashDict)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
flate/example_test.go(1 hunks)flate/huffman_bit_writer.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
flate/example_test.go (1)
flate/deflate.go (1)
NewWriterDict(905-913)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
- GitHub Check: build (1.23.x, windows-latest)
- GitHub Check: build (1.25.x, ubuntu-latest)
- GitHub Check: build (1.25.x, windows-latest)
- GitHub Check: build (1.23.x, ubuntu-latest)
- GitHub Check: build (1.24.x, macos-latest)
- GitHub Check: build (1.23.x, macos-latest)
- GitHub Check: fuzz-s2 ("noasm,nounsafe")
- GitHub Check: build (1.25.x, macos-latest)
- GitHub Check: build (1.24.x, windows-latest)
- GitHub Check: fuzz-other ("noasm,nounsafe")
- GitHub Check: build (1.24.x, ubuntu-latest)
- GitHub Check: fuzz-other (nounsafe)
- GitHub Check: fuzz-s2 (nounsafe)
- GitHub Check: fuzz-zstd (nounsafe)
- GitHub Check: build-special
🔇 Additional comments (4)
flate/huffman_bit_writer.go (1)
214-216: Great: avoid zero-byte writes in flush.Conditionally writing only when n > 0 matches stdlib behavior and avoids spurious writes to underlying writers (e.g., pipes/sockets) with no downside.
flate/example_test.go (3)
22-63: Examples: Reset usage looks solid.Clear demonstration of reusing writer/reader with shared buffers and proper Close/Reset ordering.
189-193: Flush semantics align with the writer change.Per-message Flush is correct here; combined with the flush fix, there are no zero-byte writes on empty buffers.
158-246: Synchronization example reads well.Good use of io.Pipe, framing, and graceful shutdown with wg.Wait and Close/EOF handling.
This PR contains the following updates: | Package | Change | Age | Confidence | |---|---|---|---| | [github.com/klauspost/compress](https://github.com/klauspost/compress) | `v1.18.0` -> `v1.18.1` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>klauspost/compress (github.com/klauspost/compress)</summary> ### [`v1.18.1`](https://github.com/klauspost/compress/releases/tag/v1.18.1) [Compare Source](klauspost/compress@v1.18.0...v1.18.1) #### What's Changed - zstd: Fix incorrect buffer size in dictionary encodes by [@​klauspost](https://github.com/klauspost) in [#​1059](klauspost/compress#1059) - s2: check for cap, not len of buffer in EncodeBetter/Best by [@​vdarulis](https://github.com/vdarulis) in [#​1080](klauspost/compress#1080) - zstd: Add simple zstd EncodeTo/DecodeTo functions by [@​klauspost](https://github.com/klauspost) in [#​1079](klauspost/compress#1079) - zlib: Avoiding extra allocation in zlib.reader.Reset by [@​travelpolicy](https://github.com/travelpolicy) in [#​1086](klauspost/compress#1086) - gzhttp: remove redundant err check in zstdReader by [@​ryanfowler](https://github.com/ryanfowler) in [#​1090](klauspost/compress#1090) - Run modernize. Deprecate Go 1.22 by [@​klauspost](https://github.com/klauspost) in [#​1095](klauspost/compress#1095) - flate: Simplify matchlen by [@​klauspost](https://github.com/klauspost) in [#​1101](klauspost/compress#1101) - flate: Add examples by [@​klauspost](https://github.com/klauspost) in [#​1102](klauspost/compress#1102) - flate: Use exact sizes for huffman tables by [@​klauspost](https://github.com/klauspost) in [#​1103](klauspost/compress#1103) - flate: Faster load+store by [@​klauspost](https://github.com/klauspost) in [#​1104](klauspost/compress#1104) - Add notice to S2 about MinLZ by [@​klauspost](https://github.com/klauspost) in [#​1065](klauspost/compress#1065) #### New Contributors - [@​wooffie](https://github.com/wooffie) made their first contribution in [#​1069](klauspost/compress#1069) - [@​vdarulis](https://github.com/vdarulis) made their first contribution in [#​1080](klauspost/compress#1080) - [@​travelpolicy](https://github.com/travelpolicy) made their first contribution in [#​1086](klauspost/compress#1086) - [@​ryanfowler](https://github.com/ryanfowler) made their first contribution in [#​1090](klauspost/compress#1090) **Full Changelog**: <klauspost/compress@v1.18.0...v1.18.1> </details> --- ### Configuration 📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNTIuOSIsInVwZGF0ZWRJblZlciI6IjQxLjE1Mi45IiwidGFyZ2V0QnJhbmNoIjoiZm9yZ2VqbyIsImxhYmVscyI6WyJkZXBlbmRlbmN5LXVwZ3JhZGUiLCJ0ZXN0L25vdC1uZWVkZWQiXX0=--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9786 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org> Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
Fixes minor difference to stdlib, which doesn't do a 0 byte write.
Summary by CodeRabbit
Bug Fixes
Tests