From 94528f510e431dfd9003799510ea404a3dde703e Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Sun, 23 Aug 2020 11:32:40 +0300 Subject: [PATCH] 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 Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- lib/zlib.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index 829a472e35b6a4..609c50afd52f22 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -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 { @@ -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);