Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gunzip-maybe.js « util « lib « pacote « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 055de2921ae791cfc14c3035f92488a0df68d441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'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
}