Repository navigation
Conversation
mcollina
force-pushed
the
zlib-incremental-sync
branch
from
November 30, 2026 07:52
7a4db97 to
9544428
Compare
Add a public, incremental, synchronous API to node:zlib that lets
callers decompress (or compress) data into buffers they provide,
without the stream machinery or the thread pool.
The new *Sync classes (DeflateSync, GzipSync, GunzipSync,
BrotliCompressSync, ZstdCompressSync, and the rest) expose
process(input, output[, options]), end(output[, options]), reset(),
and close(). process() returns { bytesRead, bytesWritten, finished },
end() performs the finish flush, and reset() reuses the codec for a
new stream. They cover the zlib, brotli, and zstd algorithms.
process() and end() accept an options.offset so callers can append
output into a shared, pooled buffer instead of handing in a fresh
buffer on every call.
Handle creation is factored into shared helpers (createZlibHandle,
createBrotliHandle, createZstdHandle) so the streaming classes and the
new synchronous codecs share the same option parsing. Stream/frame
completion is exposed from the native side via a new getStreamFinished
binding, so the finished flag is accurate even when the end of a
decompressed stream is reached mid-process.
Refs: nodejs#67846
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
mcollina
force-pushed
the
zlib-incremental-sync
branch
from
November 30, 2026 08:34
9544428 to
f82a487
Compare
addaleax
reviewed
Nov 30, 2026
| // no pending output left to emit. | ||
| stream_finished_ = | ||
| BrotliEncoderIsFinished(state_.get()) && | ||
| !BrotliEncoderHasMoreOutput(state_.get()); |
Member
There was a problem hiding this comment.
This is written from the worker thread but read from the JS thread without any synchronization, I assume this would need to be at least std::atomic<bool> then
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 a public, incremental, synchronous API to
node:zlibthat lets callersdecompress (or compress) data into buffers they provide, without the stream
machinery or the thread pool.
The new
*Syncclasses (DeflateSync,GzipSync,GunzipSync,BrotliCompressSync,ZstdCompressSync, and the rest) exposeprocess(input, output[, options]),end(output[, options]),reset(), andclose().process()returns{ bytesRead, bytesWritten, finished },end()performs the finish flush, andreset()reuses the codec for a newstream. The classes cover the zlib, brotli, and zstd algorithms.
process()andend()accept anoptions.offsetso callers can append outputinto a shared, pooled buffer instead of handing in a fresh buffer on every call.
Handle creation is factored into shared helpers (
createZlibHandle,createBrotliHandle,createZstdHandle) used by both the streaming classes andthe new synchronous codecs, and stream/frame completion is exposed from the
native side via a new
getStreamFinishedbinding so thefinishedflag isaccurate even when the end of a decompressed stream is reached mid-process.
Refs: #67846