@@ -99,7 +99,8 @@ module.exports = warner(class Parser extends EE {
9999 this . filter = typeof opt . filter === 'function' ? opt . filter : noop
100100 // Unlike gzip, brotli doesn't have any magic bytes to identify it
101101 // Users need to explicitly tell us they're extracting a brotli file
102- this . brotli = opt . brotli
102+ // Or we infer from the file extension
103+ this . brotli = opt . brotli || ( opt . file && ( opt . file . endsWith ( '.tar.br' ) || opt . file . endsWith ( '.tbr' ) ) )
103104
104105 // have to set this so that streams are ok piping into it
105106 this . writable = true
@@ -359,30 +360,15 @@ module.exports = warner(class Parser extends EE {
359360 this [ BUFFER ] = chunk
360361 return true
361362 }
362- if ( this [ UNZIP ] === null && this . brotli ) {
363- const ended = this [ ENDED ]
364- this [ ENDED ] = false
365- this [ UNZIP ] = new zlib . BrotliDecompress ( )
366- this [ UNZIP ] . on ( 'data' , chunk => this [ CONSUMECHUNK ] ( chunk ) )
367- this [ UNZIP ] . on ( 'error' , er => this . abort ( er ) )
368- this [ UNZIP ] . on ( 'end' , _ => {
369- this [ ENDED ] = true
370- this [ CONSUMECHUNK ] ( )
371- } )
372- this [ WRITING ] = true
373- const ret = this [ UNZIP ] [ ended ? 'end' : 'write' ] ( chunk )
374- this [ WRITING ] = false
375- return ret
376- }
377363 for ( let i = 0 ; this [ UNZIP ] === null && i < gzipHeader . length ; i ++ ) {
378364 if ( chunk [ i ] !== gzipHeader [ i ] ) {
379365 this [ UNZIP ] = false
380366 }
381367 }
382- if ( this [ UNZIP ] === null ) {
368+ if ( this [ UNZIP ] === null || ( this [ UNZIP ] === false && this . brotli ) ) {
383369 const ended = this [ ENDED ]
384370 this [ ENDED ] = false
385- this [ UNZIP ] = new zlib . Unzip ( )
371+ this [ UNZIP ] = this . brotli ? new zlib . BrotliDecompress ( ) : new zlib . Unzip ( )
386372 this [ UNZIP ] . on ( 'data' , chunk => this [ CONSUMECHUNK ] ( chunk ) )
387373 this [ UNZIP ] . on ( 'error' , er => this . abort ( er ) )
388374 this [ UNZIP ] . on ( 'end' , _ => {
0 commit comments