@@ -10,7 +10,7 @@ const JSONStream = require('minipass-json-stream')
1010const npa = require ( 'npm-package-arg' )
1111const qs = require ( 'querystring' )
1212const url = require ( 'url' )
13- const zlib = require ( 'zlib ' )
13+ const zlib = require ( 'minizlib ' )
1414
1515module . exports = regFetch
1616function 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' ) {
0 commit comments