• url {URL | string} 要转换为路径的文件 URL 字符串或者 URL 对象。
    • 返回: {string} 完全解析的平台特定的 Node.js 文件路径。

    此方法保证百分号编码字符解码结果的正确性,同时也确保绝对路径字符串在不同平台下的有效性。

    1. new URL('file:///C:/path/').pathname; // 错误: /C:/path/
    2. fileURLToPath('file:///C:/path/'); // 正确: C:\path\ (Windows)
    3. new URL('file://nas/foo.txt').pathname; // 错误: /foo.txt
    4. fileURLToPath('file://nas/foo.txt'); // 正确: \\nas\foo.txt (Windows)
    5. new URL('file:///你好.txt').pathname; // 错误: /%E4%BD%A0%E5%A5%BD.txt
    6. fileURLToPath('file:///你好.txt'); // 正确: /你好.txt (POSIX)
    7. new URL('file:///hello world').pathname; // 错误: /hello%20world
    8. fileURLToPath('file:///hello world'); // 正确: /hello world (POSIX)