Comparing version 0.3.0 to 0.3.1
@@ -6,3 +6,3 @@ { | ||
"description": "tail a file in node", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
80
tail.js
@@ -42,2 +42,5 @@ // Generated by CoffeeScript 1.6.2 | ||
_this.buffer += data; | ||
if (_this.pos !== null) { | ||
_this.pos += data.length; | ||
} | ||
parts = _this.buffer.split(_this.separator); | ||
@@ -67,2 +70,8 @@ _this.buffer = parts.pop(); | ||
this.isWatching = false; | ||
fs.stat(this.filename, function(err, stats) { | ||
if (err) { | ||
_this.emit('error', err); | ||
} | ||
return _this.pos = stats.size; | ||
}); | ||
this.internalDispatcher.on('next', function() { | ||
@@ -74,8 +83,2 @@ return _this.readBlock(); | ||
Tail.prototype.unwatch = function() { | ||
fs.unwatchFile(this.filename); | ||
this.isWatching = false; | ||
return this.queue = []; | ||
}; | ||
Tail.prototype.watch = function() { | ||
@@ -88,15 +91,62 @@ var _this = this; | ||
this.isWatching = true; | ||
return fs.watchFile(this.filename, this.fsWatchOptions, function(curr, prev) { | ||
if (curr.size > prev.size) { | ||
_this.queue.push({ | ||
start: prev.size, | ||
end: curr.size | ||
}); | ||
if (_this.queue.length === 1) { | ||
return _this.internalDispatcher.emit("next"); | ||
if (fs.watch) { | ||
return this.watcher = fs.watch(this.filename, this.fsWatchOptions, function(e) { | ||
return _this.watchEvent(e); | ||
}); | ||
} else { | ||
return fs.watchFile(this.filename, this.fsWatchOptions, function(curr, prev) { | ||
return _this.watchFileEvent(curr, prev); | ||
}); | ||
} | ||
}; | ||
Tail.prototype.watchEvent = function(e) { | ||
var _this = this; | ||
if (e === 'change') { | ||
return fs.stat(this.filename, function(err, stats) { | ||
if (err) { | ||
_this.emit('error', err); | ||
} | ||
if (stats.size > _this.pos) { | ||
_this.queue.push({ | ||
start: _this.pos, | ||
end: stats.size | ||
}); | ||
if (_this.queue.length === 1) { | ||
return _this.internalDispatcher.emit("next"); | ||
} | ||
} | ||
}); | ||
} else if (e === 'rename') { | ||
this.unwatch(); | ||
return setTimeout((function() { | ||
return _this.watch(); | ||
}), 1000); | ||
} | ||
}; | ||
Tail.prototype.watchFileEvent = function(curr, prev) { | ||
if (curr.size > prev.size) { | ||
this.queue.push({ | ||
start: prev.size, | ||
end: curr.size | ||
}); | ||
if (this.queue.length === 1) { | ||
return this.internalDispatcher.emit("next"); | ||
} | ||
}); | ||
} | ||
}; | ||
Tail.prototype.unwatch = function() { | ||
if (fs.watch) { | ||
this.watcher.close(); | ||
this.pos = 0; | ||
} else { | ||
fs.unwatchFile(this.filename); | ||
} | ||
this.isWatching = false; | ||
return this.queue = []; | ||
}; | ||
return Tail; | ||
@@ -103,0 +153,0 @@ |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
5415
3
134
0
56