Skip to content

Thomas-P/async-file-reader

Repository files navigation

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 paused and will not waste memory.

Usage

import {AsyncFileReader} from 'async-file-reader';

const main = async () => {
    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 */ );

About

Asynchronous File Reader

Resources

License

Stars

Watchers

Forks

Packages

No packages published