zoukankan      html  css  js  c++  java
  • nodejs fs module

    fs.watchFile(filename[, options], listener)#
    Added in: v0.1.31
    filename <String> | <Buffer>
    options <Object>
    persistent <Boolean>
    interval <Integer>
    listener <Function>
    Watch for changes on filename. The callback listener will be called each time the file is accessed.
    
    The options argument may be omitted. If provided, it should be an object. The options object may contain a boolean named persistent that indicates whether the process should continue to run as long as files are being watched. The options object may specify an interval property indicating how often the target should be polled in milliseconds. The default is { persistent: true, interval: 5007 }.
    
    The listener gets two arguments the current stat object and the previous stat object:
    
    fs.watchFile('message.text', (curr, prev) => {
      console.log(`the current mtime is: ${curr.mtime}`);
      console.log(`the previous mtime was: ${prev.mtime}`);
    });
    These stat objects are instances of fs.Stat.
    
    If you want to be notified when the file was modified, not just accessed, you need to compare curr.mtime and prev.mtime.
    
    Note: when an fs.watchFile operation results in an ENOENT error, it will invoke the listener once, with all the fields zeroed (or, for dates, the Unix Epoch). In Windows, blksize and blocks fields will be undefined, instead of zero. If the file is created later on, the listener will be called again, with the latest stat objects. This is a change in functionality since v0.10.
    
    Note: fs.watch() is more efficient than fs.watchFile and fs.unwatchFile. fs.watch should be used instead of fs.watchFile and fs.unwatchFile when possible.
    
    
  • 相关阅读:
    scrapy 知乎用户信息爬虫
    快读模板&&快出模板
    洛谷P7078 贪吃蛇
    CSP2020-S1总结
    洛谷P1736 创意吃鱼法
    luogu P3004 [USACO10DEC]宝箱Treasure Chest
    Markdown与LaTeX
    洛谷P2197 【模板】nim游戏
    洛谷CF1360H Binary Median
    洛谷P1063 能量项链
  • 原文地址:https://www.cnblogs.com/mayidudu/p/5872396.html
Copyright © 2011-2022 走看看