# stream-to-async-iterator

> ES async interator wrapper for node streams

Latest version **1.0.0** (published 2022-03-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-to-async-iterator
pnpm add stream-to-async-iterator
yarn add stream-to-async-iterator
bun add stream-to-async-iterator
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-03-16 |
| First published | 2017-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | BasicDays |
| Maintainers | basicdays |
| Keywords | node, stream, async-iterator, promise, esnext |

## Links

- npm: https://www.npmjs.com/package/stream-to-async-iterator
- Repository: https://github.com/basicdays/node-stream-to-async-iterator
- Homepage: https://github.com/basicdays/node-stream-to-async-iterator#readme
- Issues: https://github.com/basicdays/node-stream-to-async-iterator/issues
- npm.io page: https://npm.io/package/stream-to-async-iterator

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-03-16
- 1.0.0-beta.1 (beta) — 2018-05-30
- 0.2.0 — 2017-02-05

## README

# Stream To Async Iterator [![npm version](https://badge.fury.io/js/stream-to-async-iterator.svg)](https://www.npmjs.com/package/stream-to-async-iterator) ![build](https://github.com/basicdays/node-stream-to-async-iterator/actions/workflows/build.yml/badge.svg)

## 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:

```shell
npm install stream-to-async-iterator
```

With Yarn:

```shell
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](https://nodejs.org/dist/latest-v6.x/docs/api/stream.html#stream_types_of_streams) for more
information.

```js
#!/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

-   https://github.com/tc39/proposal-async-iteration
-   https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-async-generator-functions

---
_Source: https://npm.io/package/stream-to-async-iterator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
