@@ -44,15 +44,24 @@ const HEADERS: Record<string, Buffer> = {
4444 ".mov" : Buffer . concat ( [ Buffer . from ( [ 0 , 0 , 0 , 20 ] ) , Buffer . from ( "ftypqt " ) ] ) ,
4545 ".png" : Buffer . from ( [ 0x89 , 0x50 , 0x4e , 0x47 , 13 , 10 , 26 , 10 ] ) ,
4646 ".mp3" : Buffer . from ( "ID3\u0004\u0000" ) ,
47+ ".webm" : Buffer . from ( [ 0x1a , 0x45 , 0xdf , 0xa3 ] ) ,
4748} ;
4849
50+ function honest ( path : string ) : Buffer {
51+ const header = HEADERS [ extname ( path ) . toLowerCase ( ) ] ?? Buffer . alloc ( 0 ) ;
52+ return Buffer . concat ( [ header , HEAVY . subarray ( header . length ) ] ) ;
53+ }
54+
4955function project ( files : Record < string , string | Buffer > ) : string {
5056 const dir = mkdtempSync ( join ( tmpdir ( ) , "hf-offload-test-" ) ) ;
5157 dirs . push ( dir ) ;
5258 for ( const [ path , content ] of Object . entries ( files ) ) {
5359 mkdirSync ( dirname ( join ( dir , path ) ) , { recursive : true } ) ;
5460 const header = content === HEAVY ? HEADERS [ extname ( path ) . toLowerCase ( ) ] : undefined ;
55- writeFileSync ( join ( dir , path ) , header ? Buffer . concat ( [ header , content . subarray ( header . length ) ] ) : content ) ;
61+ writeFileSync (
62+ join ( dir , path ) ,
63+ header ? Buffer . concat ( [ header , content . subarray ( header . length ) ] ) : content ,
64+ ) ;
5665 }
5766 return dir ;
5867}
@@ -357,7 +366,10 @@ describe("offloadHeavyMedia", () => {
357366 } ) ;
358367
359368 expect ( report [ 0 ] ) . toMatchObject ( { path : "song.mp3" , action : "reencode" } ) ;
360- expect ( upload . mock . calls [ 0 ] ! [ 0 ] ) . toMatchObject ( { filename : "song.wav" , contentType : "audio/wav" } ) ;
369+ expect ( upload . mock . calls [ 0 ] ! [ 0 ] ) . toMatchObject ( {
370+ filename : "song.wav" ,
371+ contentType : "audio/wav" ,
372+ } ) ;
361373 } ) ;
362374
363375 it ( "only takes bytes as-is when they are the container the extension names" , ( ) => {
@@ -468,7 +480,7 @@ describe("offloadHeavyMedia", () => {
468480 } ) ;
469481 const gifPrep = vi . fn < GifPrep > ( async ( input , options ) => {
470482 const outputPath = join ( options . outputDir , "hfgif-v1-abc.webm" ) ;
471- writeFileSync ( outputPath , HEAVY ) ;
483+ writeFileSync ( outputPath , honest ( outputPath ) ) ;
472484 return {
473485 html : input . replace (
474486 `<img src="media/loop.gif" data-loop="true" data-duration="4" />` ,
@@ -515,7 +527,7 @@ describe("offloadHeavyMedia", () => {
515527 const gifPrep = vi . fn < GifPrep > ( async ( input , options ) => {
516528 prepared = readFileSync ( options . sourceAssets ! . get ( "logo.gif" ) ! ) ;
517529 const outputPath = join ( options . outputDir , "hfgif-v1-abc.webm" ) ;
518- writeFileSync ( outputPath , HEAVY ) ;
530+ writeFileSync ( outputPath , honest ( outputPath ) ) ;
519531 return {
520532 html : input . replace (
521533 `<img src="logo.gif" />` ,
0 commit comments