Skip to content

⬅ 🤜 Lazy, line-by-line, file read async iterator for node.js

License

Notifications You must be signed in to change notification settings

rafaelkallis/lines-async-iterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lines-async-iterator

Build Status npm version GitHub version

Line by line async iterator for node.js

  • Uses ESNext async iteration
  • Use with --harmony-async-iterator flag
  • Can use with IxJS
  • Supports custom promises
  • Typescript definitions included

Usage

Installation

npm install --save lines-async-iterator
# or
yarn add lines-async-iterator

Example 1 (Basic)

const lines = require("lines-async-iterator");

async function printLines() {
    for await(const line of lines("file.txt")){
        console.log(line);
    }
}

printLines();

Example 2 (Custom promise)

const lines = require("lines-async-iterator");
const { promisify } = require("bluebird");

async function printLines() {
    for await(const line of lines("file.txt", promisify)){
        console.log(line);
    }
}

printLines();

Example 3 (IxJS)

const lines = require("lines-async-iterator");
const Ix = require("ix");

async function printEqualLines() {
    const iterator = Ix.AsyncIterator
        .zip(lines("1.txt"), lines("2.txt"))
        .map(([line_1, line_2]) => [
            line_1.toLowerCase(),
            line_2.toLowerCase(),
        ])
        .filter(([line_1, line_2]) => line_1 === line_2);
        
    console.log("These lines are the same:");

    for await(const ([line_1, line_2]) of iterator){
        console.log(`${line_1} === ${line_2}`);
    }
}

printEqualLines();

About

⬅ 🤜 Lazy, line-by-line, file read async iterator for node.js

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published