@@ -321,6 +321,71 @@ describe('parsePackFile', () => {
321
321
} ) ;
322
322
} ) ;
323
323
324
+ describe ( 'getPackMeta' , ( ) => {
325
+ it ( 'should correctly parse PACK header' , ( ) => {
326
+ const buffer = createSamplePackBuffer ( 5 ) ; // 5 entries
327
+ const [ meta , contentBuff ] = getPackMeta ( buffer ) ;
328
+
329
+ expect ( meta ) . to . deep . equal ( {
330
+ sig : 'PACK' ,
331
+ version : 2 ,
332
+ entries : 5 ,
333
+ } ) ;
334
+ expect ( contentBuff ) . to . be . instanceOf ( Buffer ) ;
335
+ expect ( contentBuff . length ) . to . equal ( buffer . length - 12 ) ; // Remaining buffer after header
336
+ } ) ;
337
+
338
+ it ( 'should handle buffer exactly 12 bytes long' , ( ) => {
339
+ const buffer = createSamplePackBuffer ( 1 ) . slice ( 0 , 12 ) ; // Only header
340
+ const [ meta , contentBuff ] = getPackMeta ( buffer ) ;
341
+
342
+ expect ( meta ) . to . deep . equal ( {
343
+ sig : 'PACK' ,
344
+ version : 2 ,
345
+ entries : 1 ,
346
+ } ) ;
347
+ expect ( contentBuff . length ) . to . equal ( 0 ) ; // No content left
348
+ } ) ;
349
+ } ) ;
350
+
351
+ describe ( 'unpack' , ( ) => {
352
+ let deflateStub ;
353
+
354
+ beforeEach ( ( ) => {
355
+ // Need to stub deflate for unpack tests
356
+ deflateStub = sandbox . stub ( zlib , 'deflateSync' ) ;
357
+ } ) ;
358
+
359
+ it ( 'should call zlib.inflateSync and zlib.deflateSync' , ( ) => {
360
+ const inputBuf = Buffer . from ( 'compressed data' ) ;
361
+ const inflatedBuffer = Buffer . from ( 'uncompressed data' , 'utf8' ) ;
362
+ const deflatedResult = Buffer . from ( 're-deflated' ) ; // Mock deflated buffer
363
+
364
+ zlibInflateStub . withArgs ( inputBuf ) . returns ( inflatedBuffer ) ;
365
+ deflateStub . withArgs ( inflatedBuffer ) . returns ( deflatedResult ) ;
366
+
367
+ const [ resultString , resultLength ] = unpack ( inputBuf ) ;
368
+
369
+ expect ( zlibInflateStub . calledOnceWith ( inputBuf ) ) . to . be . true ;
370
+ expect ( deflateStub . calledOnceWith ( inflatedBuffer ) ) . to . be . true ; // Check local stub
371
+ expect ( resultString ) . to . equal ( inflatedBuffer . toString ( 'utf8' ) ) ;
372
+ expect ( resultLength ) . to . equal ( deflatedResult . length ) ; // unpack returns length of the deflated buffer
373
+ } ) ;
374
+
375
+ it ( 'should return inflated string and deflated length' , ( ) => {
376
+ const inputBuf = Buffer . from ( 'dummy compressed' ) ;
377
+ const inflatedBuffer = Buffer . from ( 'real uncompressed text' , 'utf8' ) ;
378
+ const deflatedResult = Buffer . from ( 'tiny' ) ; // Different length
379
+
380
+ zlibInflateStub . withArgs ( inputBuf ) . returns ( inflatedBuffer ) ;
381
+ deflateStub . withArgs ( inflatedBuffer ) . returns ( deflatedResult ) ;
382
+
383
+ const [ content , size ] = unpack ( inputBuf ) ;
384
+
385
+ expect ( content ) . to . equal ( inflatedBuffer . toString ( 'utf8' ) ) ;
386
+ expect ( size ) . to . equal ( deflatedResult . length ) ;
387
+ } ) ;
388
+ } ) ;
324
389
325
390
describe ( 'getCommitData' , ( ) => {
326
391
it ( 'should return empty array if no type 1 contents' , ( ) => {
0 commit comments