• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var duplex = require('mississippi').duplex
2var through = require('mississippi').through
3var zlib = require('zlib')
4
5function hasGzipHeader (c) {
6  return c[0] === 0x1F && c[1] === 0x8B && c[2] === 0x08
7}
8
9module.exports = gunzip
10function gunzip () {
11  var stream = duplex()
12  var peeker = through(function (chunk, enc, cb) {
13    var newStream = hasGzipHeader(chunk)
14      ? zlib.createGunzip()
15      : through()
16    stream.setReadable(newStream)
17    stream.setWritable(newStream)
18    stream.write(chunk)
19  })
20  stream.setWritable(peeker)
21  return stream
22}
23