-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: koajs/compress#60 PR-URL: #14330 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |