@@ -10,7 +10,7 @@ const JSONStream = require('minipass-json-stream')
10
10
const npa = require ( 'npm-package-arg' )
11
11
const qs = require ( 'querystring' )
12
12
const url = require ( 'url' )
13
- const zlib = require ( 'zlib ' )
13
+ const zlib = require ( 'minizlib ' )
14
14
15
15
module . exports = regFetch
16
16
function regFetch ( uri , opts ) {
@@ -40,18 +40,19 @@ function regFetch (uri, opts) {
40
40
} else if ( body && ! headers [ 'content-type' ] ) {
41
41
headers [ 'content-type' ] = 'application/octet-stream'
42
42
}
43
+
43
44
if ( opts . gzip ) {
44
45
headers [ 'content-encoding' ] = 'gzip'
45
46
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 ) )
48
50
body = body . pipe ( gz )
49
51
} 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 ( )
53
53
}
54
54
}
55
+
55
56
if ( opts . query ) {
56
57
let q = opts . query
57
58
if ( typeof q === 'string' ) {
0 commit comments