Skip to content

Instantly share code, notes, and snippets.

@bobpoekert
Created November 11, 2010 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobpoekert/673274 to your computer and use it in GitHub Desktop.
Save bobpoekert/673274 to your computer and use it in GitHub Desktop.
node tail
var tail = function(fname, onData) {
fs.open(fname, 'a+', function(err, fd) {
puts('fd:'+fd);
if (err) {
puts('error!: '+err);
setTimeout(function(){
tail(fname, onData);
}, 10);
} else {
puts('allocating buffer');
var size = 1024;
var buffer = new Buffer(size);
var reader = function() {
puts('reading '+fname);
fs.read(fd, buffer, 0, size, function(err, bytesRead) {
puts('read '+bytesRead);
callback(buffer.slice(0, bytesRead));
reader();
});
};
reader();
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment