# node:stream

> How Elide supports Node's `stream`, `stream/promises` and `stream/consumers`, with `stream/web` as the WHATWG stream globals and a `stream/iter` extension.

`node:stream`, `node:stream/promises`, and `node:stream/consumers` match
[Node's streams](https://nodejs.org/api/stream.html).

## Example

```js
// stream.mjs
import { Readable, Transform, Writable } from "node:stream";
import { pipeline } from "node:stream/promises";

const upper = new Transform({
  transform(chunk, _encoding, done) {
    done(null, chunk.toString().toUpperCase());
  },
});
const lines = [];
const sink = new Writable({
  write(chunk, _encoding, done) {
    lines.push(chunk.toString());
    done();
  },
});

await pipeline(Readable.from(["alpha", "beta", "gamma"]), upper, sink);
console.log(lines.join(" "));
```

`elide run stream.mjs` prints:

```text
ALPHA BETA GAMMA
```

## Differences from Node

- `node:stream/web` classes are the same objects as the [WHATWG stream](https://elide.help/docs/api-whatwg-streams) globals.
- `node:stream/iter` is an Elide extension with iterator conversion helpers.

## Samples

- [Streams and async iteration](https://elide.help/docs/code-samples#streams-and-async-iteration)
- [Transform stream pipeline](https://elide.help/docs/code-samples#transform-stream-pipeline)

<!-- api-reference:start 00c6c2800d9b -->
## Reference

**Status:** Partial · 215 of 238 suite tests pass (90.3%) · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `Readable` | class | Full | `readable`, `readableEnded`, `readableFlowing`, `readableHighWaterMark`, `readableLength`, `readableObjectMode`, `readableEncoding`, `destroyed`, `read()`, `setEncoding()`, `pause()`, `resume()`, `isPaused()`, `unpipe()`, `unshift()`, `wrap()`, `push()`, `destroy()`, `pipe()`, `toArray()`, `forEach()`, `some()`, `every()`, `find()`, `reduce()`, `map()`, `filter()`, `flatMap()`, `drop()`, `take()` |
| `Writable` | class | Full | `writable`, `writableEnded`, `writableFinished`, `writableHighWaterMark`, `writableLength`, `writableObjectMode`, `writableCorked`, `destroyed`, `write()`, `end()`, `cork()`, `uncork()`, `destroy()`, `setDefaultEncoding()` |
| `Duplex` | class | Full | `writable`, `writableEnded`, `writableFinished`, `writableHighWaterMark`, `writableLength`, `writableObjectMode`, `writableCorked`, `write()`, `end()`, `cork()`, `uncork()`, `setDefaultEncoding()` |
| `Transform` | class | Full |  |
| `PassThrough` | class | Full |  |
| `Readable` | property | Full | The Readable stream class |
| `Writable` | property | Full | The Writable stream class |
| `Duplex` | property | Full | The Duplex stream class |
| `Transform` | property | Full | The Transform stream class |
| `PassThrough` | property | Full | The PassThrough stream class |
| `pipeline` | property | Full | Promise-based pipeline() utility for composing stream pipelines with error propagation |
| `finished` | property | Full | Promise-based finished() utility that resolves/rejects when a stream completes or errors |
| `compose` | property | Full | Composes streams into a single Duplex; pipes them and returns a Duplex that writes to the head and reads… |

### Not implemented

`stream/web.ReadableStreamTee`.

**Tests:** [node-api `node:streams`](https://github.com/elide-dev/testsuite/blob/main/reports/1.6.0%2B6e718933f/4cbcae6c33a8/node-api/node-api.md): 215 pass, 22 fail, 1 error, 9 skipped. Failing: `test-stream-auto-destroy.js`, `test-stream-compose.js`, `test-stream-consumers.js`, `test-stream-destroy.js`, `test-stream-duplex-from.js`, `test-stream-duplex.js`, `test-stream-iter-disabled.js`, `test-stream-iter-readable-interop-disabled.js`, and 15 more.
<!-- api-reference:end -->
