node.js - 来帮我捋一下node中fs模块watch实现原理
问题描述
来探索一下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当中挂载的数据卷监听不到事件通知
问题解答
回答1:看一下这个吧 https://github.com/nodejs/nod...
回答2:快来了Boy解答一下啊,不知道踩我的,脑壳有坑?
相关文章:
1. nignx - docker内nginx 80端口被占用2. dockerfile - 为什么docker容器启动不了?3. javascript - weex和node,js到底是怎样一个关系呢?4. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?5. docker gitlab 如何git clone?6. golang - 用IDE看docker源码时的小问题7. javascript - 修改表单多选项时和后台同事配合的问题。8. docker安装后出现Cannot connect to the Docker daemon.9. 我在centos容器里安装docker,也就是在容器里安装容器,报错了?10. redis - 究竟是选择微信小程序自带的统计工具还是自己开发一个数据统计的代码?

网公网安备