-
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.
Report end-of-stream when decompressing when we detect it, and do not wait until the writable side of a zlib stream is closed as well. Refs: #26332 PR-URL: #26363 Refs: #26332 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
2 changed files
with
43 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,33 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const zlib = require('zlib'); | ||
const assert = require('assert'); | ||
|
||
const input = '0123456789'.repeat(4); | ||
|
||
for (const [ compress, decompressor ] of [ | ||
[ zlib.deflateRawSync, zlib.createInflateRaw ], | ||
[ zlib.deflateSync, zlib.createInflate ], | ||
[ zlib.brotliCompressSync, zlib.createBrotliDecompress ] | ||
]) { | ||
const compressed = compress(input); | ||
const trailingData = Buffer.from('not valid compressed data'); | ||
|
||
for (const variant of [ | ||
(stream) => { stream.end(compressed); }, | ||
(stream) => { stream.write(compressed); stream.write(trailingData); }, | ||
(stream) => { stream.write(compressed); stream.end(trailingData); }, | ||
(stream) => { stream.write(Buffer.concat([compressed, trailingData])); }, | ||
(stream) => { stream.end(Buffer.concat([compressed, trailingData])); } | ||
]) { | ||
let output = ''; | ||
const stream = decompressor(); | ||
stream.setEncoding('utf8'); | ||
stream.on('data', (chunk) => output += chunk); | ||
stream.on('end', common.mustCall(() => { | ||
assert.strictEqual(output, input); | ||
assert.strictEqual(stream.bytesWritten, compressed.length); | ||
})); | ||
variant(stream); | ||
} | ||
} |