Comparing version 0.0.2 to 0.0.3
@@ -0,0 +0,0 @@ var fs = require('fs'); |
@@ -10,5 +10,6 @@ var EventEmitter = require('events').EventEmitter, | ||
var options = options || {}; | ||
this.delimiter = options.delimiter || '\n'; | ||
this.delimiter = options.delimiter || /\r?\n/; | ||
this.dirname = dir; | ||
this.filter = this.parseFilter(options.filter || null); | ||
this.timeouts = new Hash(); | ||
} | ||
@@ -76,3 +77,3 @@ | ||
Watcher.prototype.handle = function(event, filename){ | ||
if(!filename || (this.filter && !filename.match(this.filter))){return;} | ||
if(!filename || (this.filter && filename.match(this.filter))){return;} | ||
this[event](filename); | ||
@@ -85,3 +86,5 @@ } | ||
if(err){return self.emit('error', err);} | ||
data.split(this.delimiter).forEach(function(item){ | ||
var split = data.split(self.delimiter) | ||
split.forEach(function(item){ | ||
self.emit('data', item, filename); | ||
@@ -103,3 +106,3 @@ }); | ||
if(stat && stat.isFile()){ | ||
self.fileState.put(filename, stat.size); | ||
self.fileState.put(filename, {position:stat.size, queue:[]}); | ||
self.emit('watch', filename); | ||
@@ -115,12 +118,21 @@ } | ||
Watcher.prototype.change = function(filename) { | ||
var self = this; | ||
fs.stat(self.fullPath(filename), function(err, stat){ | ||
if (!stat){return;} | ||
clearTimeout(this.timeouts.get(filename)); | ||
this.timeouts.put(filename, | ||
setTimeout(function(){ | ||
var file = filename; | ||
if(stat.size > self.fileState.get(filename)){ | ||
self.tail(filename, self.fileState.get(filename), stat.size); | ||
} | ||
self.fileState.put(filename, stat.size); | ||
}); | ||
fs.stat(self.fullPath(file), function(err, stat){ | ||
if (!stat){return;} | ||
if(stat.size > self.fileState.get(file).position){ | ||
self.tail(filename, self.fileState.get(file.position), stat.size); | ||
} | ||
self.fileState.get(file).position = stat.size; | ||
}); | ||
}, 50) | ||
); | ||
} | ||
@@ -127,0 +139,0 @@ |
{ | ||
"name": "nork-tail", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "File/Directory monitor for Node.js based on fs.watch()", | ||
@@ -10,6 +10,10 @@ "repository": { | ||
"keywords": [ | ||
"fs.watch()","tail" | ||
"fs.watch()", | ||
"tail" | ||
], | ||
"main": "lib/watcher.js", | ||
"author": "Mneme <mneme@gmail.com>", | ||
"main": "lib/watcher.js", | ||
"author": { | ||
"name": "Mneme", | ||
"email": "mneme@gmail.com" | ||
}, | ||
"devDependencies": { | ||
@@ -19,5 +23,16 @@ "mocha": "*", | ||
}, | ||
"dependencies" : { | ||
"dependencies": { | ||
"nork-hash": "~0.0.3" | ||
} | ||
}, | ||
"readme": "Work in progress.\r\n\r\nusage:\r\nvar Watcher = require('NorkWatch');\r\nvar path = require('path');\r\n\r\nvar w = Watcher('./tmp/*');\r\n\r\nw\r\n .on('error', function(err){\r\n console.log(err);\r\n })\r\n .on('data', function(data){\r\n console.log(data);\r\n })\r\n .on('unwatch', function(file){\r\n console.log('unwatching: ' + file);\r\n })\r\n .on('watch', function(file){\r\n console.log('watching: ' + file);\r\n })\r\n .start();", | ||
"readmeFilename": "README.md", | ||
"bugs": { | ||
"url": "https://github.com/mneme/norkwatch/issues" | ||
}, | ||
"_id": "nork-tail@0.0.2", | ||
"dist": { | ||
"shasum": "5ddd9b236668b8fea144b70b15e69372efb7d1ce" | ||
}, | ||
"_from": "nork-tail@~0.0.1", | ||
"_resolved": "https://registry.npmjs.org/nork-tail/-/nork-tail-0.0.2.tgz" | ||
} |
Work in progress. | ||
usage: | ||
var Watcher = require('NorkWatch'); | ||
var path = require('path'); | ||
var Tail = require('nork-tail'); | ||
var w = Watcher('./tmp/*'); | ||
Takes two arguments. path to a directory and a regexp for filtering file-names. | ||
var w = Tail('./tmp'); | ||
w | ||
@@ -10,0 +11,0 @@ .on('error', function(err){ |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
6377
9
165
1
23