-
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: detect gzip files when using unzip*
Detect whether a gzip file is being passed to `unzip*` by testing the first bytes for the gzip magic bytes, and setting the decompression mode to `GUNZIP` or `INFLATE` according to the result. This enables gzip-only features like multi-member support to be used together with the `unzip*` autodetection support and thereby makes `gunzip*` and `unzip*` return identical results for gzip input again. Add a simple test for checking that features specific to `zlib.gunzip`, notably support for multiple members, also work when using `zlib.unzip`. PR-URL: #5884 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
3 changed files
with
91 additions
and
1 deletion.
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
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,28 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const zlib = require('zlib'); | ||
|
||
const data = Buffer.concat([ | ||
zlib.gzipSync('abc'), | ||
zlib.gzipSync('def') | ||
]); | ||
|
||
const resultBuffers = []; | ||
|
||
const unzip = zlib.createUnzip() | ||
.on('error', (err) => { | ||
assert.ifError(err); | ||
}) | ||
.on('data', (data) => resultBuffers.push(data)) | ||
.on('finish', common.mustCall(() => { | ||
assert.deepStrictEqual(Buffer.concat(resultBuffers).toString(), 'abcdef', | ||
'result should match original string'); | ||
})); | ||
|
||
for (let i = 0; i < data.length; i++) { | ||
// Write each single byte individually. | ||
unzip.write(Buffer.from([data[i]])); | ||
} | ||
|
||
unzip.end(); |