事件:'change'
¥Event: 'change'
-
eventType<string> 发生的变更事件的类型¥
eventType<string> The type of change event that has occurred -
filename<string> | <Buffer> 更改的文件名(如果相关/可用)¥
filename<string> | <Buffer> The filename that changed (if relevant/available)
当监视的目录或文件中的某些内容发生更改时触发。在 fs.watch() 中查看更多详细信息。
¥Emitted when something changes in a watched directory or file.
See more details in fs.watch().
根据操作系统支持,可能不提供 filename 参数。如果提供了 filename,如果 fs.watch() 在其 encoding 选项设置为 'buffer' 的情况下被调用,它将作为 <Buffer> 提供,否则 filename 将是 UTF-8 字符串。
¥The filename argument may not be provided depending on operating system
support. If filename is provided, it will be provided as a <Buffer> if
fs.watch() is called with its encoding option set to 'buffer', otherwise
filename will be a UTF-8 string.
import { watch } from 'node:fs';
// Example when handled through fs.watch() listener
watch('./tmp', { encoding: 'buffer' }, (eventType, filename) => {
if (filename) {
console.log(filename);
// Prints: <Buffer ...>
}
});