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

Function parseTar

packages/shell/src/extras.ts:508–539  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

506}
507
508function parseTar(bytes: Uint8Array): Array<{
509 path: string;
510 type: "file" | "directory";
511 size: number;
512 bytes: Uint8Array;
513}> {
514 const entries: Array<{
515 path: string;
516 type: "file" | "directory";
517 size: number;
518 bytes: Uint8Array;
519 }> = [];
520 let offset = 0;
521 while (offset + 512 <= bytes.byteLength) {
522 const header = bytes.subarray(offset, offset + 512);
523 if (header.every((byte) => byte === 0)) break;
524 const path = readAscii(header, 0, 100);
525 const size = readOctal(header, 124, 12);
526 const typeFlag = String.fromCharCode(header[156] || 48);
527 const type = typeFlag === "5" ? "directory" : "file";
528 offset += 512;
529 const body = bytes.subarray(offset, offset + size);
530 entries.push({
531 path,
532 type,
533 size,
534 bytes: new Uint8Array(body)
535 });
536 offset += Math.ceil(size / 512) * 512;
537 }
538 return entries;
539}
540
541function writeAscii(
542 buffer: Uint8Array,

Callers 2

listTarFunction · 0.70
extractTarFunction · 0.70

Calls 2

readAsciiFunction · 0.85
readOctalFunction · 0.85

Tested by

no test coverage detected