Created
November 11, 2010 21:57
-
-
Save bobpoekert/673274 to your computer and use it in GitHub Desktop.
node tail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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