async-file-reader
v0.1.1
Published
The library allows to create a file reader object, which can be read a file asynchronously, line by line. The reader won't waste memory, because it will only read lines, when a callback ask for it. It can be used to transform data, which are ordered in li
Downloads
3
Readme
Asynchronous File Reader
File reader allows to read a file line by line. The advantage by this module is that you can write your asynchronous code in a linear way. That reduces the complexity of code. Using readFileSync could become complicated, when you should handle large files.
Another feature is, that if you do not add a callback with readLine()
the stream is posed and will not waste memory.
Usage
const main = async () => {
import {AsyncFileReader} from 'async-file-reader';
const fileReader = new AsyncFileReader('README.md');
let line: string;
try {
while ((line = await fileReader.readLine()) != null) {
// do something
}
} catch (error) {
console.log('An Error happened while reading the file.');
}
}
main()
.catch(() => /* handle error in main function */ );