Read file line by line asynchronously in Promise style.
npm install read-each-line-async
var readEachLineSync = require('read-each-line-async')
readEachLineSync('test.txt', 'utf8', async function (line) {
console.log(line)
if(await LongOperation)
return false; // Stop reading
else
return true; // Continue reading
}).then(()=> {
...
})
Encoding can optionally be omitted, in which case it will default to utf8:
readEachLineSync('test.txt', function(line) {
console.log(line)
})
End-Of-Line can be specified along with encoding if necessary, otherwise it defaults to your operating system EOF:
readEachLineSync('test.txt', 'utf-8', '\n', function(line) {
console.log(line)
})
Author: FlameArt
Based on read-each-line-sync
by Geza Kovacs
Based on readLineSync
MIT