stream-to-async-iterator
ES async interator wrapper for node streams
Last updated 3 years ago by basicdays .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install stream-to-async-iterator 
SYNC missed versions from official npm registry.

Stream To Async Iterator npm version build

Overview

stream-to-async-iterator provides a wrapper that implements Symbol.asyncIterator. This will allow streams to be usable as async iterables that can be used in for-await-of loops.

Supports node.js 12 and up.

Installation

With NPM:

npm install stream-to-async-iterator

With Yarn:

yarn add stream-to-async-iterator

The included examples use async/await syntax for for-of loops. This assumes you are in an environment that natively supports this new syntax, or that you use a tool such as Babel. In addition, for async iterators to work properly, the Symbol.asyncIterator symbol must be defined. Core-js can help with that.

Usage

Import the StreamToAsyncIterator class and pass the stream to its constructor. The iterator instance can be directly used in for-of contexts.

If the stream is in object mode, each iteration will produce the next object. See the node documentation for more information.

#!/usr/bin/env node
"use strict";
const { Readable } = require("stream");
const S2A = require("../").default;

(async function () {
    const readStream = Readable.from([1, 2, 3]);
    for await (const chunk of new S2A(readStream)) {
        console.dir({ chunk });
    }
})();

Outputs:

{ chunk: 1 }
{ chunk: 2 }
{ chunk: 3 }

References

Current Tags

  • 1.0.0-beta.1                                ...           beta (6 years ago)
  • 1.0.0                                ...           latest (3 years ago)

3 Versions

  • 1.0.0                                ...           3 years ago
  • 1.0.0-beta.1                                ...           6 years ago
  • 0.2.0                                ...           8 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE