国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

node.js - 來幫我捋一下node中fs模塊watch實現原理

瀏覽:176日期:2024-10-16 08:17:24

問題描述

來探索一下node中fs模塊watch實現原理,

const fs = require(’fs’);var fileName = ’a.txt’;fs.watch(fileName, (function () { var count = 0; return function () {count++;console.log('文件' + fileName + ' 內容剛剛改變。。第' + count + '次'); };})());console.log('watching file...');

fs如何實現針對文件變化做出響應的事件通知的呢?如果說是通過監聽文件大小變化,或者其他?

下面是通過node源碼看到的一些東西:

const FSEvent = process.binding(’fs_event_wrap’).FSEvent;function FSWatcher() { EventEmitter.call(this); var self = this; this._handle = new FSEvent(); this._handle.owner = this; this._handle.onchange = function(status, eventType, filename) { if (status < 0) { self._handle.close(); const error = !filename ? errnoException(status, ’Error watching file for changes:’) : errnoException(status, `Error watching file ${filename} for changes:`); error.filename = filename; self.emit(’error’, error); } else { self.emit(’change’, eventType, filename); } };}

后面的fs_event_wrap.cc 基本都是外星語言了。

下面我再docker當中掛載的數據卷監聽不到事件通知node.js - 來幫我捋一下node中fs模塊watch實現原理

問題解答

回答1:

看一下這個吧 https://github.com/nodejs/nod...

回答2:

快來了Boy解答一下啊,不知道踩我的,腦殼有坑?

相關文章:
主站蜘蛛池模板: 交口县| 长泰县| 佳木斯市| 巫溪县| 井研县| 新营市| 交城县| 汝州市| 连南| 莱西市| 江源县| 宣恩县| 台南县| 赣榆县| 德清县| 苏州市| 蓝山县| 峨眉山市| 化德县| 斗六市| 隆子县| 呼图壁县| 杭锦后旗| 呼伦贝尔市| 海南省| 乌鲁木齐县| 盐源县| 平湖市| 依安县| 澄城县| 南丰县| 将乐县| 巴彦淖尔市| 密山市| 获嘉县| 泰宁县| 门源| 长春市| 体育| 石楼县| 绥宁县|