可用性
¥Availability
此功能取决于底层操作系统是否提供了一种通知文件系统更改的方法。
¥This feature depends on the underlying operating system providing a way to be notified of filesystem changes.
-
在 Linux 系统上,这使用
inotify(7)
。¥On Linux systems, this uses
inotify(7)
. -
在 BSD 系统上,这使用
kqueue(2)
。¥On BSD systems, this uses
kqueue(2)
. -
在 macOS 上,这对文件使用
kqueue(2)
,对目录使用FSEvents
。¥On macOS, this uses
kqueue(2)
for files andFSEvents
for directories. -
在 SunOS 系统(包括 Solaris 和 SmartOS)上,这使用
event ports
。¥On SunOS systems (including Solaris and SmartOS), this uses
event ports
. -
在 Windows 系统上,此功能取决于
ReadDirectoryChangesW
。¥On Windows systems, this feature depends on
ReadDirectoryChangesW
. -
在 AIX 系统上,此功能依赖于必须启用的
AHAFS
。¥On AIX systems, this feature depends on
AHAFS
, which must be enabled. -
在 IBM i 系统上,不支持此功能。
¥On IBM i systems, this feature is not supported.
如果底层功能由于某种原因不可用,则 fs.watch()
将无法运行并可能抛出异常。例如,使用虚拟化软件(例如 Vagrant 或 Docker)时,在网络文件系统(NFS、SMB 等)或主机文件系统上监视文件或目录可能不可靠,在某些情况下甚至是不可能的。
¥If the underlying functionality is not available for some reason, then
fs.watch()
will not be able to function and may throw an exception.
For example, watching files or directories can be unreliable, and in some
cases impossible, on network file systems (NFS, SMB, etc) or host file systems
when using virtualization software such as Vagrant or Docker.
仍然可以使用 fs.watchFile()
,它使用 stat 轮询,但这种方法较慢且不太可靠。
¥It is still possible to use fs.watchFile()
, which uses stat polling, but
this method is slower and less reliable.