blob: 0b752557e441bcb078a8f205d8a6dc166802f48d (
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
38
39
|
'use strict';
const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');
const {
Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH
} = zlib.constants;
async function getOutput(...sequenceOfFlushes) {
const zipper = zlib.createGzip({ highWaterMark: 16384 });
zipper.write('A'.repeat(17000));
for (const flush of sequenceOfFlushes) {
zipper.flush(flush);
}
const data = [];
return new Promise((resolve) => {
zipper.on('data', common.mustCall((d) => {
data.push(d);
if (data.length === 2) resolve(Buffer.concat(data));
}, 2));
});
}
(async function() {
assert.deepStrictEqual(await getOutput(Z_SYNC_FLUSH),
await getOutput(Z_SYNC_FLUSH, Z_PARTIAL_FLUSH));
assert.deepStrictEqual(await getOutput(Z_SYNC_FLUSH),
await getOutput(Z_PARTIAL_FLUSH, Z_SYNC_FLUSH));
assert.deepStrictEqual(await getOutput(Z_FINISH),
await getOutput(Z_FULL_FLUSH, Z_FINISH));
assert.deepStrictEqual(await getOutput(Z_FINISH),
await getOutput(Z_SYNC_FLUSH, Z_FINISH));
})();
|