Read file line by line without buffering the whole file in memory.
npm install n-readlines-next
node-readlines-next is a fork of node-readlines! A package developed by Yoan Arnaudov! Original Repo hereThe author wasn't active for 2 years up to now!
I took the deliberate to Fork it! Merged one PR (One bring better performance) [check here]!
And added typescript declarations!
Also if any PR are send! I'll make sure to treat them!
filesystem module of node. Note that this is synchronous library.Install withnpm install n-readlines-next
---------------------------------------
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
node-readlines can handle files without newLineCharacter after the last line
---------------------------------------
buffer with the line data without the newLineCharacter or false if end of file is reached.---------------------------------------
---------------------------------------
javascript
var ReadLines = require('n-readlines');
var liner = new ReadLines('./textFile.txt');var line;
var lineNumber = 0;
while (line = liner.next()) {
console.log('Line ' + lineNumber + ': ' + line.toString('ascii'));
lineNumber++;
}
console.log('end of line reached');
`Typescript
For imports and types
`ts
import LineReader, { ReadLinesOptions } from 'n-readlines-next';
``ts
export class CsvReader {
private _lineReader: LineReader;
}
``