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