11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst zlib = require('zlib');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// Tests that zlib streams support .reset() and .params()
71cb0ef41Sopenharmony_ci// before the first write. That is important to ensure that
81cb0ef41Sopenharmony_ci// lazy init of zlib native library handles these cases.
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cifor (const fn of [
111cb0ef41Sopenharmony_ci  (z, cb) => {
121cb0ef41Sopenharmony_ci    z.reset();
131cb0ef41Sopenharmony_ci    cb();
141cb0ef41Sopenharmony_ci  },
151cb0ef41Sopenharmony_ci  (z, cb) => z.params(0, zlib.constants.Z_DEFAULT_STRATEGY, cb),
161cb0ef41Sopenharmony_ci]) {
171cb0ef41Sopenharmony_ci  const deflate = zlib.createDeflate();
181cb0ef41Sopenharmony_ci  const inflate = zlib.createInflate();
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  deflate.pipe(inflate);
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  const output = [];
231cb0ef41Sopenharmony_ci  inflate
241cb0ef41Sopenharmony_ci    .on('error', (err) => {
251cb0ef41Sopenharmony_ci      assert.ifError(err);
261cb0ef41Sopenharmony_ci    })
271cb0ef41Sopenharmony_ci    .on('data', (chunk) => output.push(chunk))
281cb0ef41Sopenharmony_ci    .on('end', common.mustCall(
291cb0ef41Sopenharmony_ci      () => assert.strictEqual(Buffer.concat(output).toString(), 'abc')));
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  fn(deflate, () => {
321cb0ef41Sopenharmony_ci    fn(inflate, () => {
331cb0ef41Sopenharmony_ci      deflate.write('abc');
341cb0ef41Sopenharmony_ci      deflate.end();
351cb0ef41Sopenharmony_ci    });
361cb0ef41Sopenharmony_ci  });
371cb0ef41Sopenharmony_ci}
38