MCPcopy Create free account
hub / github.com/denoland/std / parsePath

Function parsePath

tar/tar_stream.ts:595–629  ·  view source on GitHub ↗
(size: number, buffer: Uint8Array_)

Source from the content-addressed store, hash-verified

593}
594
595function 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}.

Callers 2

#parsePathIntoMethod · 0.85
assertValidPathFunction · 0.85

Calls 2

maxMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected