Skip to content

Instantly share code, notes, and snippets.

@dweinstein
Last active August 29, 2015 14:17
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 dweinstein/ff1c7696080d98777706 to your computer and use it in GitHub Desktop.
Save dweinstein/ff1c7696080d98777706 to your computer and use it in GitHub Desktop.
node iojs get last line of file using slice-file
var fs = require('fs');
var slice = require('slice-file');
function lastLine(path, cb) {
cb = cb || function(err, res) {
if(err) { throw err; }
process.stdout.write(res);
};
var ret;
slice(path).sliceReverse(-1, 1)
.on('data', function(data) {
ret = data.toString();
})
.on('end', function() {
if (!ret) {
return cb("no line?");
}
cb(null, ret);
})
.on('error', function(err) {
cb(err);
});
}
module.exports = lastLine;
@dweinstein
Copy link
Author

I ended up making an npm mod, see this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment