@@ -375,6 +375,13 @@ t.test('if gzip is truthy, make it an object', t => {
375375 t . end ( )
376376} )
377377
378+ t . test ( 'if brotli is truthy, make it an object' , t => {
379+ const opt = { brotli : true }
380+ new Pack ( opt )
381+ t . type ( opt . brotli , 'object' )
382+ t . end ( )
383+ } )
384+
378385t . test ( 'gzip, also a very deep path' , t => {
379386 const out = [ ]
380387
@@ -454,6 +461,85 @@ t.test('gzip, also a very deep path', t => {
454461 } )
455462} )
456463
464+ t . test ( 'brotli, also a very deep path' , t => {
465+ const out = [ ]
466+
467+ new Pack ( {
468+ cwd : files ,
469+ brotli : { flush : 1 } ,
470+ } )
471+ . add ( 'dir' )
472+ . add ( 'long-path' )
473+ . on ( 'data' , c => out . push ( c ) )
474+ . end ( )
475+ . on ( 'end' , _ => {
476+ const zipped = Buffer . concat ( out )
477+ const data = zlib . brotliDecompressSync ( zipped )
478+ const entries = [ ]
479+ for ( var i = 0 ; i < data . length ; i += 512 ) {
480+ const slice = data . slice ( i , i + 512 )
481+ const h = new Header ( slice )
482+ if ( h . nullBlock ) {
483+ entries . push ( 'null block' )
484+ } else if ( h . cksumValid ) {
485+ entries . push ( [ h . type , h . path ] )
486+ } else if ( entries [ entries . length - 1 ] [ 0 ] === 'File' ) {
487+ entries [ entries . length - 1 ] . push ( slice . toString ( ) . replace ( / \0 .* $ / , '' ) )
488+ }
489+ }
490+
491+ const expect = [
492+ [ 'Directory' , 'dir/' ] ,
493+ [ 'Directory' , 'long-path/' ] ,
494+ [ 'File' , 'dir/x' ] ,
495+ [ 'Directory' , 'long-path/r/' ] ,
496+ [ 'Directory' , 'long-path/r/e/' ] ,
497+ [ 'Directory' , 'long-path/r/e/a/' ] ,
498+ [ 'Directory' , 'long-path/r/e/a/l/' ] ,
499+ [ 'Directory' , 'long-path/r/e/a/l/l/' ] ,
500+ [ 'Directory' , 'long-path/r/e/a/l/l/y/' ] ,
501+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/' ] ,
502+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/' ] ,
503+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/' ] ,
504+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/' ] ,
505+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/' ] ,
506+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/' ] ,
507+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/' ] ,
508+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/' ] ,
509+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/' ] ,
510+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/' ] ,
511+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/' ] ,
512+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/' ] ,
513+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/' ] ,
514+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/' ] ,
515+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/' ] ,
516+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/' ] ,
517+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/' ] ,
518+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/a.txt' , 'short\n' ] ,
519+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' , '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111' ] ,
520+ [ 'ExtendedHeader' , 'PaxHeader/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' ] ,
521+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' , '2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222' ] ,
522+ [ 'ExtendedHeader' , 'PaxHeader/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccc' ] ,
523+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccccccccccccc' , 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' ] ,
524+ [ 'ExtendedHeader' , 'PaxHeader/Ω.txt' ] ,
525+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/Ω.txt' , 'Ω' ] ,
526+ 'null block' ,
527+ 'null block' ,
528+ ]
529+
530+ let ok = true
531+ entries . forEach ( ( entry , i ) => {
532+ ok = ok &&
533+ t . equal ( entry [ 0 ] , expect [ i ] [ 0 ] ) &&
534+ t . equal ( entry [ 1 ] , expect [ i ] [ 1 ] ) &&
535+ ( ! entry [ 2 ] || t . equal ( entry [ 2 ] , expect [ i ] [ 2 ] ) )
536+ } )
537+
538+ // t.match(entries, expect)
539+ t . end ( )
540+ } )
541+ } )
542+
457543t . test ( 'very deep gzip path, sync' , t => {
458544 const pack = new PackSync ( {
459545 cwd : files ,
@@ -533,6 +619,85 @@ t.test('very deep gzip path, sync', t => {
533619 t . end ( )
534620} )
535621
622+ t . test ( 'very deep brotli path, sync' , t => {
623+ const pack = new PackSync ( {
624+ cwd : files ,
625+ brotli : true ,
626+ } ) . add ( 'dir' )
627+ . add ( 'long-path' )
628+ . end ( )
629+
630+ // these do nothing!
631+ pack . pause ( )
632+ pack . resume ( )
633+
634+ const zipped = pack . read ( )
635+ t . type ( zipped , Buffer )
636+ const data = zlib . brotliDecompressSync ( zipped )
637+ const entries = [ ]
638+ for ( var i = 0 ; i < data . length ; i += 512 ) {
639+ const slice = data . slice ( i , i + 512 )
640+ const h = new Header ( slice )
641+ if ( h . nullBlock ) {
642+ entries . push ( 'null block' )
643+ } else if ( h . cksumValid ) {
644+ entries . push ( [ h . type , h . path ] )
645+ } else if ( entries [ entries . length - 1 ] [ 0 ] === 'File' ) {
646+ entries [ entries . length - 1 ] . push ( slice . toString ( ) . replace ( / \0 .* $ / , '' ) )
647+ }
648+ }
649+
650+ const expect = [
651+ [ 'Directory' , 'dir/' ] ,
652+ [ 'File' , 'dir/x' ] ,
653+ [ 'Directory' , 'long-path/' ] ,
654+ [ 'Directory' , 'long-path/r/' ] ,
655+ [ 'Directory' , 'long-path/r/e/' ] ,
656+ [ 'Directory' , 'long-path/r/e/a/' ] ,
657+ [ 'Directory' , 'long-path/r/e/a/l/' ] ,
658+ [ 'Directory' , 'long-path/r/e/a/l/l/' ] ,
659+ [ 'Directory' , 'long-path/r/e/a/l/l/y/' ] ,
660+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/' ] ,
661+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/' ] ,
662+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/' ] ,
663+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/' ] ,
664+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/' ] ,
665+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/' ] ,
666+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/' ] ,
667+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/' ] ,
668+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/' ] ,
669+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/' ] ,
670+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/' ] ,
671+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/' ] ,
672+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/' ] ,
673+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/' ] ,
674+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/' ] ,
675+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/' ] ,
676+ [ 'Directory' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/' ] ,
677+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/a.txt' , 'short\n' ] ,
678+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' , '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111' ] ,
679+ [ 'ExtendedHeader' , 'PaxHeader/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' ] ,
680+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' , '2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222' ] ,
681+ [ 'ExtendedHeader' , 'PaxHeader/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccc' ] ,
682+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccccccccccccc' , 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' ] ,
683+ [ 'ExtendedHeader' , 'PaxHeader/Ω.txt' ] ,
684+ [ 'File' , 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/Ω.txt' , 'Ω' ] ,
685+ 'null block' ,
686+ 'null block' ,
687+ ]
688+
689+ let ok = true
690+ entries . forEach ( ( entry , i ) => {
691+ ok = ok &&
692+ t . equal ( entry [ 0 ] , expect [ i ] [ 0 ] ) &&
693+ t . equal ( entry [ 1 ] , expect [ i ] [ 1 ] ) &&
694+ ( ! entry [ 2 ] || t . equal ( entry [ 2 ] , expect [ i ] [ 2 ] ) )
695+ } )
696+
697+ // t.match(entries, expect)
698+ t . end ( )
699+ } )
700+
536701t . test ( 'write after end' , t => {
537702 const p = new Pack ( )
538703 p . end ( )
0 commit comments