Skip to content

Commit

Permalink
fix: use minizlib instead of core zlib
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Oct 4, 2019
1 parent 5cfe30b commit e64702e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const JSONStream = require('minipass-json-stream')
const npa = require('npm-package-arg')
const qs = require('querystring')
const url = require('url')
const zlib = require('zlib')
const zlib = require('minizlib')

module.exports = regFetch
function regFetch (uri, opts) {
Expand Down Expand Up @@ -40,18 +40,19 @@ function regFetch (uri, opts) {
} else if (body && !headers['content-type']) {
headers['content-type'] = 'application/octet-stream'
}

if (opts.gzip) {
headers['content-encoding'] = 'gzip'
if (bodyIsStream) {
const gz = zlib.createGzip()
body.on('error', err => gz.emit('error', err))
const gz = new zlib.Gzip()
body.on('error', /* istanbul ignore next: unlikely and hard to test */
err => gz.emit('error', err))
body = body.pipe(gz)
} else {
body = new Promise((resolve, reject) => {
zlib.gzip(body, (err, gz) => err ? reject(err) : resolve(gz))
})
body = new zlib.Gzip().end(body).concat()
}
}

if (opts.query) {
let q = opts.query
if (typeof q === 'string') {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"minipass": "^3.0.0",
"minipass-fetch": "^1.1.2",
"minipass-json-stream": "^1.0.1",
"minizlib": "^2.0.0",
"npm-package-arg": "^6.1.0",
"safe-buffer": "^5.2.0"
},
Expand Down

0 comments on commit e64702e

Please # to comment.