-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zlib: switch to lazy init for zlib streams
PR-URL: #34048 Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
1 parent
eecb92c
commit 252f376
Showing
3 changed files
with
92 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
}); | ||
}); | ||
} |