Skip to content

A node.js line-by-line reader that enables generator based flow-control.

License

Notifications You must be signed in to change notification settings

ericlu88/line-by-line-promise

Repository files navigation

line-by-line-promise

is a NodeJS module that reads large text files line by line, without buffering the files into memory. It is built upon line-by-line but returns Promise for every line read, enabling generator based flow-control.

Installation:

npm install line-by-line-promise

Usage

var LineReader = require('line-by-line-promise');
var file = new LineReader('big_file.txt');

// Example using co: https://github.com/tj/co
co(function* () {
    var line;
    // note that eof is defined when `readLine()` yields `null`
    while((line = yield file.readLine()) !== null) {
        console.log(line);
    }
});

// Example using bluebird: https://github.com/petkaantonov/bluebird
Promise.coroutine(function* () {
    var line;
    // note that eof is defined when `readLine()` yields `null`
    while((line = yield file.readLine()) !== null) {
        console.log(line);
    }
})();

License

MIT License. See license text in LICENSE

About

A node.js line-by-line reader that enables generator based flow-control.

Resources

License

Stars

Watchers

Forks

Packages

No packages published