async-file-reader
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Asynchronous File Reader

Greenkeeper badge Build Status Coverage Status Known Vulnerabilities

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 */ );

Readme

Keywords

none

Package Sidebar

Install

npm i async-file-reader

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • thomas-p