fs.realpath(path[, options], callback)
-
callback
<Function>
通过解析 .
、..
和符号链接异步地计算规范路径名。
¥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.
该函数的行为类似于 realpath(3)
,但有一些例外:
¥This function behaves like realpath(3)
, with some exceptions:
-
在不区分大小写的文件系统上不执行大小写转换。
¥No case conversion is performed on case-insensitive file systems.
-
符号链接的最大数量与平台无关,并且通常(远)高于原生
realpath(3)
实现支持的数量。¥The maximum number of symbolic links is platform-independent and generally (much) higher than what the native
realpath(3)
implementation supports.
callback
有两个参数 (err, resolvedPath)
。可以使用 process.cwd
来解析相对路径。
¥The callback
gets two arguments (err, resolvedPath)
. May use process.cwd
to resolve relative paths.
仅支持可以转换为 UTF8 字符串的路径。
¥Only paths that can be converted to UTF8 strings are supported.
可选的 options
参数可以是指定编码的字符串,也可以是具有 encoding
属性(指定用于传给回调的路径的字符编码)的对象。如果 encoding
设置为 'buffer'
,则返回的路径将作为 <Buffer> 对象传入。
¥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.
如果 path
解析为套接字或管道,则该函数将返回该对象的系统相关名称。
¥If path
resolves to a socket or a pipe, the function will return a system
dependent name for that object.
不存在的路径会导致 ENOENT 错误。error.path
是绝对文件路径。
¥A path that does not exist results in an ENOENT error.
error.path
is the absolute file path.