From 9bd2e07e0a70647a0bd62c6c4baf5f2563159479 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 14 Mar 2016 17:11:07 -0700 Subject: [PATCH] zlib: do not emit event on *Sync() methods WIP right now, still need to do it for more methods than just gunzipSync(). Refs: https://github.com/nodejs/node/issues/1668 --- lib/zlib.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index 0028c35d7923eb..1ad83add211168 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -453,7 +453,9 @@ Zlib.prototype.flush = function(kind, callback) { } }; -Zlib.prototype.close = function(callback) { +Zlib.prototype.close = function(callback, options) { + options = options || {}; + if (callback) process.nextTick(callback); @@ -464,7 +466,9 @@ Zlib.prototype.close = function(callback) { this._handle.close(); - process.nextTick(emitCloseNT, this); + if (!options.sync) { + process.nextTick(emitCloseNT, this); + } }; function emitCloseNT(self) { @@ -535,12 +539,12 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) { } if (nread >= kMaxLength) { - this.close(); + this.close(null, {sync: true}); throw new RangeError(kRangeErrorMessage); } var buf = Buffer.concat(buffers, nread); - this.close(); + this.close(null, {sync: true}); return buf; }