cr

chunk-reader

Read chunks from a file by delimiter and do some work async

Showing:

Popularity

Downloads/wk

3

GitHub Stars

1

Maintenance

Last Commit

3yrs ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.3KB

License

GPL-3.0-or-later

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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
[asyncIterator]AsyncIterator
[options]Object
[options.delimiter]StringChunk delimiter (optional). EOL by default;

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100