Skip to content

expose Z_STREAM_END #26624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,11 @@ function processCallback() {

var availOutAfter = state[0];
var availInAfter = state[1];
var result = state[2];

const inDelta = handle.availInBefore - availInAfter;
self.bytesWritten += inDelta;
self.result = result;

var have = handle.availOutBefore - availOutAfter;
if (have > 0) {
Expand Down Expand Up @@ -545,17 +547,7 @@ function processCallback() {
self._chunkSize); // out_len
return;
}

if (availInAfter > 0) {
// If we have more input that should be written, but we also have output
// space available, that means that the compression library was not
// interested in receiving more data, and in particular that the input
// stream has ended early.
// This applies to streams where we don't check data past the end of
// what was consumed; that is, everything except Gunzip/Unzip.
self.push(null);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this is a breaking change, the test added in #26363 should fail (once the linter issue has been fixed here).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't realize this had already gone out the door. Nor did I realize that I should be trapping for the end event and not the finish event!

Thanks for the code review!



// finished with the chunk.
this.buffer = null;
this.cb();
Expand Down Expand Up @@ -632,7 +624,7 @@ function Zlib(opts, mode) {
// Ideally, we could let ZlibBase() set up _writeState. I haven't been able
// to come up with a good solution that doesn't break our internal API,
// and with it all supported npm versions at the time of writing.
this._writeState = new Uint32Array(2);
this._writeState = new Uint32Array(3);
if (!handle.init(windowBits,
level,
memLevel,
Expand Down Expand Up @@ -790,7 +782,7 @@ function Brotli(opts, mode) {
const handle = mode === BROTLI_DECODE ?
new binding.BrotliDecoder(mode) : new binding.BrotliEncoder(mode);

this._writeState = new Uint32Array(2);
this._writeState = new Uint32Array(3);
if (!handle.init(brotliInitParamsArray,
this._writeState,
processCallback)) {
Expand Down
14 changes: 9 additions & 5 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ZlibContext : public MemoryRetainer {
void DoThreadPoolWork();
void SetBuffers(char* in, uint32_t in_len, char* out, uint32_t out_len);
void SetFlush(int flush);
void GetAfterWriteOffsets(uint32_t* avail_in, uint32_t* avail_out) const;
void GetAfterWriteOffsets(uint32_t* ret, uint32_t* avail_in, uint32_t* avail_out) const;
CompressionError GetErrorInfo() const;
inline void SetMode(node_zlib_mode mode) { mode_ = mode; }
CompressionError ResetStream();
Expand Down Expand Up @@ -172,7 +172,7 @@ class BrotliContext : public MemoryRetainer {

void SetBuffers(char* in, uint32_t in_len, char* out, uint32_t out_len);
void SetFlush(int flush);
void GetAfterWriteOffsets(uint32_t* avail_in, uint32_t* avail_out) const;
void GetAfterWriteOffsets(uint32_t* ret,uint32_t* avail_in, uint32_t* avail_out) const;
inline void SetMode(node_zlib_mode mode) { mode_ = mode; }

protected:
Expand Down Expand Up @@ -359,7 +359,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
}

void UpdateWriteResult() {
ctx_.GetAfterWriteOffsets(&write_result_[1], &write_result_[0]);
ctx_.GetAfterWriteOffsets(&write_result_[2], &write_result_[1], &write_result_[0]);
}

// thread pool!
Expand Down Expand Up @@ -846,8 +846,10 @@ void ZlibContext::SetFlush(int flush) {
}


void ZlibContext::GetAfterWriteOffsets(uint32_t* avail_in,
void ZlibContext::GetAfterWriteOffsets(uint32_t* ret,
uint32_t* avail_in,
uint32_t* avail_out) const {
*ret = err_;
*avail_in = strm_.avail_in;
*avail_out = strm_.avail_out;
}
Expand Down Expand Up @@ -1063,8 +1065,10 @@ void BrotliContext::SetFlush(int flush) {
}


void BrotliContext::GetAfterWriteOffsets(uint32_t* avail_in,
void BrotliContext::GetAfterWriteOffsets(uint32_t* ret,
uint32_t* avail_in,
uint32_t* avail_out) const {
*ret = 0;
*avail_in = avail_in_;
*avail_out = avail_out_;
}
Expand Down