(bytes: Uint8Array)
| 506 | } |
| 507 | |
| 508 | function 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 | |
| 541 | function writeAscii( |
| 542 | buffer: Uint8Array, |
no test coverage detected