# stream-to-it

> Convert Node.js streams to streaming iterables

Latest version **1.0.1** (published 2024-04-09) · Apache-2.0 OR MIT license · 0 weekly downloads

## Install

```sh
npm install stream-to-it
pnpm add stream-to-it
yarn add stream-to-it
bun add stream-to-it
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2024-04-09 |
| First published | 2019-08-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 OR MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 37.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 19 |
| Author | Alan Shaw |
| Maintainers | alanshaw |
| Keywords | async, iterable, iterator, readablestream, stream |

## Links

- npm: https://www.npmjs.com/package/stream-to-it
- Repository: https://github.com/alanshaw/stream-to-it
- Homepage: https://github.com/alanshaw/stream-to-it#readme
- Issues: https://github.com/alanshaw/stream-to-it/issues
- npm.io page: https://npm.io/package/stream-to-it

## Dependencies (1)

- [it-stream-types](https://npm.io/package/it-stream-types.md) ^2.0.1

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2024-04-09
- 1.0.0 — 2024-04-08
- 0.2.4 — 2021-07-03
- 0.2.3 — 2021-04-16
- 0.2.2 — 2020-07-15
- 0.2.1 — 2020-07-13
- 0.2.0 — 2019-12-04
- 0.1.1 — 2019-08-25
- 0.1.0 — 2019-08-19

## README

# stream-to-it

[![codecov](https://img.shields.io/codecov/c/github/alanshaw/stream-to-it.svg?style=flat-square)](https://codecov.io/gh/alanshaw/stream-to-it)
[![CI](https://img.shields.io/github/actions/workflow/status/alanshaw/stream-to-it/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/alanshaw/stream-to-it/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)

> Convert Node.js streams to streaming iterables

# About

<!--

!IMPORTANT!

Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.

To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts

To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.

-->

Seamlessly use Node.js streams with `it-pipe` and friends.

## Example - Convert readable stream to source iterable

```TypeScript
import fs from 'node:fs'
import * as toIterable from 'stream-to-it'

const readable = fs.createReadStream('/path/to/file')
// Node.js streams are already async iterable so this is just s => s
const source = toIterable.source<Buffer>(readable)

for await (const chunk of source) {
  console.log(chunk.toString())
}
```

Also works with browser [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream):

```TypeScript
import * as toIterable from 'stream-to-it'

const res = await fetch('http://example.org/file.jpg')

if (res.body == null) {
  throw new Error('Body was not set')
}

for await (const chunk of toIterable.source(res.body)) {
  console.log(chunk.toString())
}
```

## Example - Convert writable stream to sink iterable

```TypeScript
import fs from 'node:fs'
import { pipe } from 'it-pipe'
import * as toIterable from 'stream-to-it'

const source = [Buffer.from('Hello '), Buffer.from('World!')]
const sink = toIterable.sink(fs.createWriteStream('/path/to/file'))

await pipe(source, sink)
```

## Example - Convert transform stream to transform iterable

```TypeScript
import fs from 'node:fs'
import { Transform } from 'node:stream'
import { pipe } from 'it-pipe'
import * as toIterable from 'stream-to-it'

const output = await pipe(
  [true, false, true, true],
  toIterable.transform(new Transform({ // Inverter transform :)
    transform (chunk, enc, cb) {
      cb(null, !chunk)
    }
  })),
  // Collect and return the chunks
  async source => {
    const chunks = []
    for await (const chunk of source) chunks.push(chunk)
    return chunks
  }
)

console.log(output) // [ false, true, false, false ]
```

## Related

- [`it-to-stream`](https://www.npmjs.com/package/it-to-stream) Convert streaming iterables to Node.js streams
- [`it-pipe`](https://www.npmjs.com/package/it-pipe) Utility to "pipe" async iterables together

# Install

```console
$ npm i stream-to-it
```

# API Docs

- <https://alanshaw.github.io/stream-to-it>

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

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