2.0.1 • Published 7 years ago

chunk-reader v2.0.1

Weekly downloads
3
License
GPLv3
Repository
github
Last release
7 years ago

Chunk Reader

Read chunks from AsyncIterator by delimiter and do some work async.

This module uses async generators. Currently this feature available in Node.js >= v10.

Install

npm install --save chunk-reader
or
yarn add chunk-reader

Usage

const createReader = require("chunk-reader")
const fsPromses = require("fs").promises
const fs = require("fs")

async function main() {
  const filePath = "./pathToFile"
  const delimiter = "\n"
  const { size: bytesTotal } = await fsPromses.stat(filePath)

  const stream = fs.createReadStream(filePath)

  const reader = createReader(stream, { delimiter })

  for await (const chunk of reader) {
    // do here some async stuff with cnunks
    console.log(
      `Progress: ${(stream.bytesRead / bytesTotal * 100).toFixed(2)}%`,
    )
  }
}

main()

createReader(asyncIterator, opts) ⇒ AsyncIterator

Create a new ChunkReader instance.

ParamTypeDescription
asyncIteratorAsyncIterator
optionsObject
options.delimiterStringChunk delimiter (optional). EOL by default;
2.0.1

7 years ago

2.0.0

7 years ago

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago