Skip to content
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

zlib: replace usage of internal stream state with public api #34884

Closed
Closed
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
9 changes: 3 additions & 6 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,15 @@ const kFlushBuffers = [];
}

ZlibBase.prototype.flush = function(kind, callback) {
const ws = this._writableState;

if (typeof kind === 'function' || (kind === undefined && !callback)) {
callback = kind;
kind = this._defaultFullFlushFlag;
}

if (ws.ended) {
if (this.writableFinished) {
Copy link
Member Author

Choose a reason for hiding this comment

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

IIUC this is slightly off since the .finished will only be set on nextTick but I guess that's okay?
/cc @ronag

Copy link
Member

Choose a reason for hiding this comment

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

propabbly fine

if (callback)
process.nextTick(callback);
} else if (ws.ending) {
} else if (this.writableEnded) {
if (callback)
this.once('end', callback);
} else {
Expand All @@ -397,8 +395,7 @@ ZlibBase.prototype._transform = function(chunk, encoding, cb) {
}

// For the last chunk, also apply `_finishFlushFlag`.
const ws = this._writableState;
if ((ws.ending || ws.ended) && ws.length === chunk.byteLength) {
if (this.writableEnded && this.writableLength === chunk.byteLength) {
flushFlag = maxFlush(flushFlag, this._finishFlushFlag);
}
processChunk(this, chunk, flushFlag, cb);
Expand Down