1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const zlib = require('zlib'); 5 6// Tests that zlib streams support .reset() and .params() 7// before the first write. That is important to ensure that 8// lazy init of zlib native library handles these cases. 9 10for (const fn of [ 11 (z, cb) => { 12 z.reset(); 13 cb(); 14 }, 15 (z, cb) => z.params(0, zlib.constants.Z_DEFAULT_STRATEGY, cb), 16]) { 17 const deflate = zlib.createDeflate(); 18 const inflate = zlib.createInflate(); 19 20 deflate.pipe(inflate); 21 22 const output = []; 23 inflate 24 .on('error', (err) => { 25 assert.ifError(err); 26 }) 27 .on('data', (chunk) => output.push(chunk)) 28 .on('end', common.mustCall( 29 () => assert.deepStrictEqual(Buffer.concat(output).toString(), 'abc'))); 30 31 fn(deflate, () => { 32 fn(inflate, () => { 33 deflate.write('abc'); 34 deflate.end(); 35 }); 36 }); 37} 38