Repository navigation
Add dictionary support to Zstd and Brotli compressor input streams - #821
Open
arturobernalg wants to merge 1 commit into
Open
arturobernalg wants to merge 1 commit into
arturobernalg wants to merge 1 commit into
Conversation
Add ZstdCompressorInputStream.Builder.setDict(byte[]) and BrotliCompressorInputStream.Builder.setDict(byte[]) to decompress input compressed with a dictionary, for example Compression Dictionary Transport (RFC 9842) payloads.
arturobernalg
force-pushed
the
compression-dictionaries
branch
from
October 7, 2026 10:28
74fcf2c to
f22d656
Compare
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The Zstandard path-based builder leaks its internally opened input stream because close propagation is disabled.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds dictionary-based decompression support to Brotli and Zstandard input streams.
Changes:
- Adds builders with
setDict(byte[]). - Adds dictionary decompression and missing-dictionary tests.
- Adds fixtures, release notes, and binary resource handling.
| File | Description |
|---|---|
.gitattributes |
Marks dictionary fixtures as binary. |
src/changes/changes.xml |
Documents both new APIs. |
BrotliCompressorInputStream.java |
Adds dictionary-aware builder. |
ZstdCompressorInputStream.java |
Adds dictionary-aware builder. |
BrotliCompressorInputStreamTest.java |
Tests Brotli dictionary decoding. |
ZstdCompressorInputStreamTest.java |
Tests Zstandard dictionary decoding. |
brotli.dictionary.dict |
Provides the test dictionary. |
brotli.dictionary.uncompressed |
Provides expected decompressed data. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @SuppressWarnings("resource") // Caller closes | ||
| private ZstdCompressorInputStream(final Builder builder) throws IOException { | ||
| this.decIS = new ZstdInputStream( | ||
| countingStream = BoundedInputStream.builder().setInputStream(builder.getInputStream()).setPropagateClose(false).get()); |
Member
|
@arturobernalg |
garydgregory
reviewed
Oct 7, 2026
garydgregory
left a comment
Member
There was a problem hiding this comment.
I added 2 questions about the byte array setters.
| * @return {@code this} instance. | ||
| */ | ||
| public Builder setDict(final byte[] dict) { | ||
| this.dict = dict; |
Member
There was a problem hiding this comment.
Should the builder track a defensive copy?
| * @see <a href="https://facebook.github.io/zstd/zstd_manual.html#Chapter14">Zstd manual Chapter14</a> | ||
| */ | ||
| public Builder setDict(final byte[] dict) { | ||
| this.dict = dict; |
Member
There was a problem hiding this comment.
Should the builder track a defensive copy?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Add ZstdCompressorInputStream.Builder.setDict(byte[]) and BrotliCompressorInputStream.Builder.setDict(byte[]) to decompress input compressed with a dictionary, for example Compression Dictionary Transport (RFC 9842) payloads.
Motivation: Compression Dictionary Transport (RFC 9842) support in Apache HttpClient, see apache/httpcomponents-client#881
Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.