(blobContent: string)
| 43 | const zeroOid = '0'.repeat(40); |
| 44 | |
| 45 | function 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 |
no test coverage detected