Skip to content

Commit e64702e

Browse files
committed
fix: use minizlib instead of core zlib
1 parent 5cfe30b commit e64702e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const JSONStream = require('minipass-json-stream')
1010
const npa = require('npm-package-arg')
1111
const qs = require('querystring')
1212
const url = require('url')
13-
const zlib = require('zlib')
13+
const zlib = require('minizlib')
1414

1515
module.exports = regFetch
1616
function regFetch (uri, opts) {
@@ -40,18 +40,19 @@ function regFetch (uri, opts) {
4040
} else if (body && !headers['content-type']) {
4141
headers['content-type'] = 'application/octet-stream'
4242
}
43+
4344
if (opts.gzip) {
4445
headers['content-encoding'] = 'gzip'
4546
if (bodyIsStream) {
46-
const gz = zlib.createGzip()
47-
body.on('error', err => gz.emit('error', err))
47+
const gz = new zlib.Gzip()
48+
body.on('error', /* istanbul ignore next: unlikely and hard to test */
49+
err => gz.emit('error', err))
4850
body = body.pipe(gz)
4951
} else {
50-
body = new Promise((resolve, reject) => {
51-
zlib.gzip(body, (err, gz) => err ? reject(err) : resolve(gz))
52-
})
52+
body = new zlib.Gzip().end(body).concat()
5353
}
5454
}
55+
5556
if (opts.query) {
5657
let q = opts.query
5758
if (typeof q === 'string') {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"minipass": "^3.0.0",
3737
"minipass-fetch": "^1.1.2",
3838
"minipass-json-stream": "^1.0.1",
39+
"minizlib": "^2.0.0",
3940
"npm-package-arg": "^6.1.0",
4041
"safe-buffer": "^5.2.0"
4142
},

0 commit comments

Comments
 (0)