@@ -99,7 +99,8 @@ module.exports = warner(class Parser extends EE {
99
99
this . filter = typeof opt . filter === 'function' ? opt . filter : noop
100
100
// Unlike gzip, brotli doesn't have any magic bytes to identify it
101
101
// 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' ) ) )
103
104
104
105
// have to set this so that streams are ok piping into it
105
106
this . writable = true
@@ -359,30 +360,15 @@ module.exports = warner(class Parser extends EE {
359
360
this [ BUFFER ] = chunk
360
361
return true
361
362
}
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
- }
377
363
for ( let i = 0 ; this [ UNZIP ] === null && i < gzipHeader . length ; i ++ ) {
378
364
if ( chunk [ i ] !== gzipHeader [ i ] ) {
379
365
this [ UNZIP ] = false
380
366
}
381
367
}
382
- if ( this [ UNZIP ] === null ) {
368
+ if ( this [ UNZIP ] === null || ( this [ UNZIP ] === false && this . brotli ) ) {
383
369
const ended = this [ ENDED ]
384
370
this [ ENDED ] = false
385
- this [ UNZIP ] = new zlib . Unzip ( )
371
+ this [ UNZIP ] = this . brotli ? new zlib . BrotliDecompress ( ) : new zlib . Unzip ( )
386
372
this [ UNZIP ] . on ( 'data' , chunk => this [ CONSUMECHUNK ] ( chunk ) )
387
373
this [ UNZIP ] . on ( 'error' , er => this . abort ( er ) )
388
374
this [ UNZIP ] . on ( 'end' , _ => {
0 commit comments