node/test/parallel/test-zlib-destroy.js
Robert Nagy a9401439c7 zlib: align with streams
- Ensure automatic destruction only happens after both
'end' and 'finish' has been emitted through autoDestroy.
- Ensure close() callback is always invoked.
- Ensure 'error' is only emitted once.

PR-URL: https://github.com/nodejs/node/pull/32220
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2020-03-19 10:56:45 +01:00

32 lines
634 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');
// Verify that the zlib transform does clean up
// the handle when calling destroy.
{
const ts = zlib.createGzip();
ts.destroy();
assert.strictEqual(ts._handle, null);
ts.on('close', common.mustCall(() => {
ts.close(common.mustCall());
}));
}
{
// Ensure 'error' is only emitted once.
const decompress = zlib.createGunzip(15);
decompress.on('error', common.mustCall((err) => {
decompress.close();
}));
decompress.write('something invalid');
decompress.destroy(new Error('asd'));
}