Read file line by line without buffering the whole file in memory.
npm install @lazy-node/readlinesfilesystem module of node. Note that this is synchronous library.Install withnpm install @lazy-node/readlines
---------------------------------------
Arguments
* filename - String path to the file you want to read from
* fd - File descriptor
* options - Object
* readChunk - Integer number of bytes to read at once. Default: 1024
* newLineCharacter - String new line character, only works with one byte characters for now. Default: \n which is 0x0a hex encoded
@lazy-node/readlines can handle files without newLineCharacter after the last line
---------------------------------------
buffer with the line data without the newLineCharacter or undefined if end of file is reached.---------------------------------------
---------------------------------------
next() calls will return false. This works only if the end is not reached.---------------------------------------
javascript
const lineByLine = require('@lazy-node/readlines');
const liner = new lineByLine('./test/fixtures/normalFile.txt');let line;
let lineNumber = 0;
while (line = liner.next()) {
console.log('Line ' + lineNumber + ': ' + line.toString());
lineNumber++;
}
console.log('end of line reached');
``