Skip to content

Commit

Permalink
zlib: replace usage of internal stream state with public api
Browse files Browse the repository at this point in the history
Refs: #445

PR-URL: #34884
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
lundibundi authored and richardlau committed Sep 1, 2020
1 parent 90f9348 commit 94528f5
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,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) {
if (callback)
process.nextTick(callback);
} else if (ws.ending) {
} else if (this.writableEnded) {
if (callback)
this.once('end', callback);
} else {
Expand All @@ -392,8 +390,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

0 comments on commit 94528f5

Please sign in to comment.