diff --git a/lib/zlib.js b/lib/zlib.js index 2def716e9b676c..a7bb32a4eb1397 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -152,7 +152,6 @@ function flushCallback(level, strategy, callback) { // true or false if there is anything in the queue when // you call the .write() method. function Zlib(opts, mode) { - Transform.call(this, opts); var chunkSize = Z_DEFAULT_CHUNK; var flush = Z_NO_FLUSH; var finishFlush = Z_FINISH; @@ -257,6 +256,7 @@ function Zlib(opts, mode) { opts.writableObjectMode = false; } } + Transform.call(this, opts); this.bytesRead = 0; this._handle = new binding.Zlib(mode); this._handle.jsref = this; // Used by processCallback() and zlibOnError() diff --git a/test/parallel/test-zlib-object-write.js b/test/parallel/test-zlib-object-write.js new file mode 100644 index 00000000000000..98f34b38bed850 --- /dev/null +++ b/test/parallel/test-zlib-object-write.js @@ -0,0 +1,11 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const { Gunzip } = require('zlib'); + +const gunzip = new Gunzip({ objectMode: true }); +assert.throws( + () => gunzip.write({}), + TypeError +);