stream-to-async-it

0.0.1 • Public • Published

stream-it

Forked from https://github.com/basicdays/node-stream-to-async-iterator and published temporarily until v0.2.1 of that module is published.

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 4 and up.

Installation

$ npm install stream-to-async-iterator

The examples provides 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 or babel-polyfill can both 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';
require('core-js/es7/symbol');
const fs = require('fs');
const S2A = require('stream-to-async-iterator');
 
 
(async function() {
    const readStream = fs.createReadStream(__filename);
    for await (const chunk of new S2A(readStream)) {
        console.log(chunk);
    }
})();

References

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    5
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    5

Package Sidebar

Install

npm i stream-to-async-it

Weekly Downloads

5

Version

0.0.1

License

MIT

Unpacked Size

53.9 kB

Total Files

32

Last publish

Collaborators

  • achingbrain