1. 首页
  2. 移动开发
  3. 其他
  4. node tail native实时读取新行功能,类似'tailf'

node tail native实时读取新行功能,类似'tailf'

上传者: 2024-12-26 17:55:35上传 ZIP文件 6.85KB 热度 4次

node.js 的本机模块。实时读取新行,如同 'tail -f'。安装:

npm install tailnative

或者通过 git clone 克隆项目:

git clone git://github.com/whitesheep/node-tail-native.git

cd node-tail-native

node-gyp configure build

使用:

Tailnative,从 0.3 版本开始,支持 line separator

new Tail(filename, \"r \");

事件触发:

数据 function(data){}

结束 function(){}

错误 function(error){}

示例代码:

var Tail = require(\"tailnative\");

var lineseparator = \" \";

var tail = new Tail(__dirname + \"/logfile.log\");

tail.on(\"data\", function(data) {

console.log(data);

});

tail.on(\"end\", function() {

console.log(\"File reading finished.\");

});

tail.on(\"error\", function(error) {

console.error(\"Error: \" + error);

});

下载地址
用户评论