fs.realpath(path[, options], callback)


通过解析 ... 和符号链接异步地计算规范路径名。

规范路径名不一定是唯一的。 硬链接和绑定挂载可以通过许多路径名暴露文件系统实体。

此函数的行为类似于 realpath(3),但有一些例外:

  1. 在不区分大小写的文件系统上不执行大小写转换。

  2. 符号链接的最大数量与平台无关,并且通常(远)高于原生 realpath(3) 实现支持的数量。

callback 有两个参数 (err, resolvedPath)。 可以使用 process.cwd 来解析相对路径。

仅支持可以转换为 UTF8 字符串的路径。

可选的 options 参数可以是指定编码的字符串,也可以是具有 encoding 属性(指定用于传给回调的路径的字符编码)的对象。 如果 encoding 设置为 'buffer',则返回的路径将作为 <Buffer> 对象传入。

如果 path 解析为套接字或管道,则该函数将返回该对象的系统相关名称。

Asynchronously computes the canonical pathname by resolving ., .., and symbolic links.

A canonical pathname is not necessarily unique. Hard links and bind mounts can expose a file system entity through many pathnames.

This function behaves like realpath(3), with some exceptions:

  1. No case conversion is performed on case-insensitive file systems.

  2. The maximum number of symbolic links is platform-independent and generally (much) higher than what the native realpath(3) implementation supports.

The callback gets two arguments (err, resolvedPath). May use process.cwd to resolve relative paths.

Only paths that can be converted to UTF8 strings are supported.

The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the path passed to the callback. If the encoding is set to 'buffer', the path returned will be passed as a <Buffer> object.

If path resolves to a socket or a pipe, the function will return a system dependent name for that object.