From f095e38c7cc8d3c786077f656137a8b77227f1a2 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Mon, 2 Mar 2020 17:02:08 +0100 Subject: [PATCH] zlib: emits 'close' event after readable 'end' Call the close method after readable 'end' so that 'close' will be emitted afterwards. Fixes: https://github.com/nodejs/node/issues/32023 PR-URL: https://github.com/nodejs/node/pull/32050 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca --- lib/zlib.js | 2 +- test/parallel/test-zlib.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index 19405263c92896..69919990a55ca1 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -274,7 +274,7 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) { this._defaultFlushFlag = flush; this._finishFlushFlag = finishFlush; this._defaultFullFlushFlag = fullFlush; - this.once('end', _close.bind(null, this)); + this.once('end', this.close); this._info = opts && opts.info; } ObjectSetPrototypeOf(ZlibBase.prototype, Transform.prototype); diff --git a/test/parallel/test-zlib.js b/test/parallel/test-zlib.js index 509dcd2207e83e..0d21cf6cc29e58 100644 --- a/test/parallel/test-zlib.js +++ b/test/parallel/test-zlib.js @@ -171,7 +171,8 @@ zlib.createDeflateRaw({ windowBits: 8 }); .pipe(zlib.createInflateRaw({ windowBits: 8 })) .on('data', (chunk) => reinflated.push(chunk)) .on('end', common.mustCall( - () => assert(Buffer.concat(raw).equals(Buffer.concat(reinflated))))); + () => assert(Buffer.concat(raw).equals(Buffer.concat(reinflated))))) + .on('close', common.mustCall(1)); } // For each of the files, make sure that compressing and