mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 22:10:53 +00:00

PR-URL: https://github.com/nodejs/node/pull/11389 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
23 lines
552 B
JavaScript
23 lines
552 B
JavaScript
var duplex = require('mississippi').duplex
|
|
var through = require('mississippi').through
|
|
var zlib = require('zlib')
|
|
|
|
function hasGzipHeader (c) {
|
|
return c[0] === 0x1F && c[1] === 0x8B && c[2] === 0x08
|
|
}
|
|
|
|
module.exports = gunzip
|
|
function gunzip () {
|
|
var stream = duplex()
|
|
var peeker = through(function (chunk, enc, cb) {
|
|
var newStream = hasGzipHeader(chunk)
|
|
? zlib.createGunzip()
|
|
: through()
|
|
stream.setReadable(newStream)
|
|
stream.setWritable(newStream)
|
|
stream.write(chunk)
|
|
})
|
|
stream.setWritable(peeker)
|
|
return stream
|
|
}
|