-
-
Save netroy/867605 to your computer and use it in GitHub Desktop.
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
/** | |
* A `tail -f` implementation in Node.js. | |
* | |
* Original author : Bratish Goswami <bratishgoswami AT gmail DOT com> | |
* Modified by : Michel Bartz <michel.bartz AT manwin DOT com> | |
* | |
*/ | |
var sys = require("sys"), | |
fs = require('fs'), | |
f = "/path/to/file"; | |
fs.watchFile(f, function(curr, prev) { | |
if(prev.size > curr.size){ | |
// probably file is overwritten, seek on the stream will fail | |
return; | |
} | |
fs.createReadStream(f, { start: prev.size, end: curr.size}).addListener("data", function(lines) { | |
sys.log(lines); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment