Skip to content

cemayan/async-chunk-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Async Chunk Reader

This library allows you to read large amounts of data in chunks.

Install

npm install --save async-chunk-reader

API


init(parameters : InitParameters)

input : InitParameters

  • chunk_size : String
  • input_file : String | Stream
  • encoding : String

get()

output : Async Iterator

Import

with require :

const reader = require('async-chunk-reader')

with import :

import * as reader from "async-chunk-reader"

Usage


with path :

async function main(){

    const x = await reader
        .init({
            chunk_size: 100000,
            input_file: 'input/mobile_network_201805.csv.gz'
        })
        .get()

    for await(let chunk of  x){
        console.log(chunk.length)
    }
}

main();

with stream :

async function main(){

    const x = await reader
        .init({
            input_file:  process.stdin
        })
        .get()

    for await(let chunk of  x){
        console.log(chunk.length)
    }
}

main();

with string :

async function main(){

    const x = await reader
        .init({
            input_file: "Some string"
        })
        .get()

    for await(let chunk of  x){
        console.log(chunk.length)
    }
}

main();