url.fileURLToPathBuffer(url[, options])
url<URL> | <string> 要转换为路径的文件 URL 字符串或 URL 对象。options<Object>windows<boolean> | <undefined>true如果path应该作为 Windows 文件路径返回,false用于 POSIX,undefined用于系统默认。 默认值:undefined。
- 返回:<Buffer> 作为 <Buffer> 的完全解析的特定平台的 Node.js 文件路径。
类似 url.fileURLToPath(...),只是它返回的是 Buffer 而不是路径的字符串表示。 当输入的 URL 包含不是有效 UTF-8 / Unicode 序列的百分号编码部分时,这种转换非常有用。
🌐 Like url.fileURLToPath(...) except that instead of returning a string
representation of the path, a Buffer is returned. This conversion is
helpful when the input URL contains percent-encoded segments that are
not valid UTF-8 / Unicode sequences.
安全注意事项:
此函数具有与 url.fileURLToPath() 相同的安全考虑。它会解码百分比编码的字符,包括编码的点段(将 %2e 解码为 .,将 %2e%2e 解码为 ..),并规范化路径。**应用不能仅依赖此函数来防止目录遍历攻击。**在将返回的缓冲区值用于文件系统操作之前,务必对其进行显式路径验证。
🌐 This function has the same security considerations as url.fileURLToPath().
It decodes percent-encoded characters, including encoded dot-segments
(%2e as . and %2e%2e as ..), and normalizes the path. Applications
must not rely on this function alone to prevent directory traversal attacks.
Always perform explicit path validation on the returned buffer value before
using it for file system operations.