node/deps/npm/node_modules/pacote/lib/util/gunzip-maybe.js
Kat Marchán c0d858f8bb
deps: upgrade npm beta to 5.0.0-beta.56
PR-URL: https://github.com/nodejs/node/pull/12936
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-05-23 19:39:43 +02:00

25 lines
572 B
JavaScript

'use strict'
const duplex = require('mississippi').duplex
const through = require('mississippi').through
const zlib = require('zlib')
function hasGzipHeader (c) {
return c[0] === 0x1F && c[1] === 0x8B && c[2] === 0x08
}
module.exports = gunzip
function gunzip () {
const stream = duplex()
const peeker = through((chunk, enc, cb) => {
const newStream = hasGzipHeader(chunk)
? zlib.createGunzip()
: through()
stream.setReadable(newStream)
stream.setWritable(newStream)
stream.write(chunk)
})
stream.setWritable(peeker)
return stream
}