MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / buildValidPackfile

Function buildValidPackfile

services/app-builder/src/git/git-clone-service.test.ts:45–67  ·  view source on GitHub ↗
(blobContent: string)

Source from the content-addressed store, hash-verified

43const zeroOid = '0'.repeat(40);
44
45function buildValidPackfile(blobContent: string): { packBytes: Uint8Array; blobOid: string } {
46 const content = Buffer.from(blobContent);
47 const gitObjectHeader = Buffer.from(`blob ${content.length}\0`);
48 const blobOid = createHash('sha1')
49 .update(Buffer.concat([gitObjectHeader, content]))
50 .digest('hex');
51
52 const header = Buffer.alloc(12);
53 header.write('PACK', 0);
54 header.writeUInt32BE(2, 4);
55 header.writeUInt32BE(1, 8);
56
57 if (content.length > 15)
58 throw new Error('buildValidPackfile: content too long for simple header');
59 const objHeader = Buffer.from([(3 << 4) | content.length]);
60
61 const deflated = deflateSync(content);
62 const packBody = Buffer.concat([header, objHeader, deflated]);
63 const checksum = createHash('sha1').update(packBody).digest();
64 const packBytes = new Uint8Array(Buffer.concat([packBody, checksum]));
65
66 return { packBytes, blobOid };
67}
68
69// ---------------------------------------------------------------------------
70// Push helper: uses GitReceivePackService to populate a MemFS with real objects

Callers 1

Calls 2

writeMethod · 0.80
updateMethod · 0.65

Tested by

no test coverage detected