Files
node/test/parallel/test-zlib-destroy-pipe.js
T
Matteo Collina 6fce1a314e zlib: check if the stream is destroyed before push
If the stream is destroyed while the transform is still being
applied, push() should not be called, and the internal state
should be cleared.

Refs: https://github.com/koajs/compress/issues/60
PR-URL: https://github.com/nodejs/node/pull/14330
Backport-PR-URL: https://github.com/nodejs/node/pull/14396
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

 Conflicts:
	lib/zlib.js
2017-07-20 13:45:09 -04:00

22 lines
456 B
JavaScript

'use strict';
const common = require('../common');
const zlib = require('zlib');
const { Writable } = require('stream');
// verify that the zlib transform does not error in case
// it is destroyed with data still in flight
const ts = zlib.createGzip();
const ws = new Writable({
write: common.mustCall((chunk, enc, cb) => {
setImmediate(cb);
ts.destroy();
})
});
const buf = Buffer.allocUnsafe(1024 * 1024 * 20);
ts.end(buf);
ts.pipe(ws);