成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

node.js - 來(lái)幫我捋一下node中fs模塊watch實(shí)現(xiàn)原理

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

問(wèn)題描述

來(lái)探索一下node中fs模塊watch實(shí)現(xiàn)原理,

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

fs如何實(shí)現(xiàn)針對(duì)文件變化做出響應(yīng)的事件通知的呢?如果說(shuō)是通過(guò)監(jiān)聽(tīng)文件大小變化,或者其他?

下面是通過(guò)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 基本都是外星語(yǔ)言了。

下面我再docker當(dāng)中掛載的數(shù)據(jù)卷監(jiān)聽(tīng)不到事件通知node.js - 來(lái)幫我捋一下node中fs模塊watch實(shí)現(xiàn)原理

問(wèn)題解答

回答1:

看一下這個(gè)吧 https://github.com/nodejs/nod...

回答2:

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

相關(guān)文章: