mirror of https://github.com/lukechilds/node.git
Browse Source
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: https://github.com/nodejs/node/pull/5884 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>process-exit-stdio-flushing
Anna Henningsen
9 years ago
committed by
Ben Noordhuis
3 changed files with 91 additions and 1 deletions
@ -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(); |
Loading…
Reference in new issue