MCPcopy Index your code
hub / github.com/nodejs/node / getPathBufferFromURLPosix

Function getPathBufferFromURLPosix

lib/internal/url.js:1600–1620  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

1598}
1599
1600function getPathBufferFromURLPosix(url) {
1601 if (url.hostname !== '') {
1602 throw new ERR_INVALID_FILE_URL_HOST(platform);
1603 }
1604 const pathname = url.pathname;
1605
1606 // In the getPathFromURLPosix variant, we scan the input for forward slash
1607 // (/) characters, specifically looking for the ASCII/UTF8 and forbidding
1608 // its use. This is a bit tricky because these may conflict with non-UTF8
1609 // encodings. Passing in an encoding option does not help since our Buffer
1610 // encoding only knows about certain specific text encodings and a single
1611 // file path might actually contain segments that use multiple encodings.
1612 // It's tricky! So, for this variation where we are producing a buffer, we
1613 // won't scan for the slashes at all, and instead will decode the bytes
1614 // literally into the returned Buffer. We're going to do the best we can and
1615 // just interpret the input url as a sequence of bytes.
1616 const u8 = percentDecode(Buffer.from(pathname, 'utf8'));
1617 return Buffer.from(TypedArrayPrototypeGetBuffer(u8),
1618 TypedArrayPrototypeGetByteOffset(u8),
1619 TypedArrayPrototypeGetByteLength(u8));
1620}
1621
1622function fileURLToPath(path, options = kEmptyObject) {
1623 const windows = options?.windows;

Callers 1

fileURLToPathBufferFunction · 0.85

Calls 2

percentDecodeFunction · 0.70
fromMethod · 0.45

Tested by

no test coverage detected