MCPcopy Create free account
hub / github.com/cloudflare/agents / createTarHeader

Function createTarHeader

packages/shell/src/extras.ts:485–506  ·  view source on GitHub ↗
(entry: TarInputEntry)

Source from the content-addressed store, hash-verified

483}
484
485function createTarHeader(entry: TarInputEntry): Uint8Array {
486 const header = new Uint8Array(512);
487 writeAscii(header, 0, 100, entry.path);
488 writeOctal(header, 100, 8, entry.type === "directory" ? 0o755 : 0o644);
489 writeOctal(header, 108, 8, 0);
490 writeOctal(header, 116, 8, 0);
491 writeOctal(
492 header,
493 124,
494 12,
495 entry.type === "file" ? entry.bytes.byteLength : 0
496 );
497 writeOctal(header, 136, 12, Math.floor(Date.now() / 1000));
498 for (let i = 148; i < 156; i++) header[i] = 32;
499 header[156] =
500 entry.type === "directory" ? "5".charCodeAt(0) : "0".charCodeAt(0);
501 writeAscii(header, 257, 6, "ustar");
502 writeAscii(header, 263, 2, "00");
503 const checksum = header.reduce((sum, value) => sum + value, 0);
504 writeOctal(header, 148, 8, checksum);
505 return header;
506}
507
508function parseTar(bytes: Uint8Array): Array<{
509 path: string;

Callers 1

buildTarFunction · 0.85

Calls 2

writeAsciiFunction · 0.85
writeOctalFunction · 0.85

Tested by

no test coverage detected