zlib: replace usage of internal stream state with public api

Refs: https://github.com/nodejs/node/issues/445

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Denys Otrishko 2020-08-23 11:32:40 +03:00 committed by Node.js GitHub Bot
parent dbc5c172cc
commit 7fca0df180
1 changed files with 3 additions and 6 deletions

View File

@ -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) {
if (callback)
process.nextTick(callback);
} else if (ws.ending) {
} else if (this.writableEnded) {
if (callback)
this.once('end', callback);
} else {
@ -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);