(size: number, buffer: Uint8Array_)
| 593 | } |
| 594 | |
| 595 | function parsePath(size: number, buffer: Uint8Array_): void { |
| 596 | if (size <= 100) return; |
| 597 | if (size > 256) { |
| 598 | throw new RangeError( |
| 599 | `Cannot parse the path as the path length cannot exceed 256 bytes: The path length is ${size}`, |
| 600 | ); |
| 601 | } |
| 602 | |
| 603 | const sub = buffer.subarray(0, size); |
| 604 | let slashPos = Math.max(0, sub.lastIndexOf(SLASH_CODE_POINT)); |
| 605 | if (size - slashPos > 100) { |
| 606 | throw new RangeError( |
| 607 | `Cannot parse the path as the file cannot exceed 100 bytes: The filename length is ${ |
| 608 | size - slashPos |
| 609 | }`, |
| 610 | ); |
| 611 | } |
| 612 | |
| 613 | for (let pos = slashPos; pos > 0; slashPos = pos) { |
| 614 | pos = sub.lastIndexOf(SLASH_CODE_POINT, slashPos - 1); |
| 615 | if (size - pos > 100) break; |
| 616 | } |
| 617 | |
| 618 | const prefix = sub.subarray(0, slashPos); |
| 619 | if (prefix.length > 155) { |
| 620 | throw new TypeError( |
| 621 | "Cannot parse the path as the path needs to be split-able on a forward slash separator into [155, 100] bytes respectively", |
| 622 | ); |
| 623 | } |
| 624 | buffer.set(prefix, 345); |
| 625 | buffer.subarray(345 + prefix.length, 500).fill(0); |
| 626 | const name = sub.subarray(slashPos + 1); |
| 627 | buffer.set(name); |
| 628 | buffer.subarray(name.length, 100).fill(0); |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Asserts that the path provided is valid for a {@linkcode TarStream}. |
no test coverage detected