Created
February 6, 2012 07:37
-
-
Save shinout/1750489 to your computer and use it in GitHub Desktop.
fs.watchFile() -> fs.read()
This file contains hidden or 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 fs = require('fs'); | |
var filename = process.argv[2]; | |
fs.open(filename, 'r', function(err, fd) { | |
fs.watchFile(filename, function(cstat, pstat) { | |
var delta = cstat.size - pstat.size; | |
if (delta <= 0) return; | |
fs.read(fd, new Buffer(delta), 0, delta, pstat.size, function(err, bytes, buffer) { | |
console.log("err", err, "delta", delta, "bytes", bytes, "buffer", buffer.toString()); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want this to load data already in the file you will need to modify it:
This is pretty rough code though, please be sure to handle errors. The file may be removed, truncated, etc.