summaryrefslogtreecommitdiff
path: root/test/parallel/test-zlib-destroy-pipe.js
diff options
context:
space:
mode:
authorMatteo Collina <hello@matteocollina.com>2017-07-17 19:25:21 +0200
committerMatteo Collina <hello@matteocollina.com>2017-07-19 14:11:40 +0200
commitaa496f4beef402b1d666d2f0dd26283aa22b5402 (patch)
tree53a97bda7eac0eb690e738ebd8a0baa72f07d8fb /test/parallel/test-zlib-destroy-pipe.js
parent030a0285d88a03b0051ada736aabdb490f6479c9 (diff)
downloadnode-new-aa496f4beef402b1d666d2f0dd26283aa22b5402.tar.gz
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. See: https://github.com/koajs/compress/issues/60 PR-URL: https://github.com/nodejs/node/pull/14330 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-zlib-destroy-pipe.js')
-rw-r--r--test/parallel/test-zlib-destroy-pipe.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/parallel/test-zlib-destroy-pipe.js b/test/parallel/test-zlib-destroy-pipe.js
new file mode 100644
index 0000000000..38b8a5b492
--- /dev/null
+++ b/test/parallel/test-zlib-destroy-pipe.js
@@ -0,0 +1,21 @@
+'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);