# @yume-chan/stream-extra

> Extensions to Web Streams API

Latest version **2.6.1** (published 2026-06-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @yume-chan/stream-extra
pnpm add @yume-chan/stream-extra
yarn add @yume-chan/stream-extra
bun add @yume-chan/stream-extra
```

## Health

**Score 65/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.6.1 |
| Published | 2026-06-04 |
| First published | 2022-10-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 298.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | Simon Chan |
| Maintainers | yume-chan |
| Keywords | stream, web-streams-api |

## Links

- npm: https://www.npmjs.com/package/@yume-chan/stream-extra
- Repository: https://github.com/yume-chan/ya-webadb
- Homepage: https://github.com/yume-chan/ya-webadb/tree/main/packages/stream-extra#readme
- Issues: https://github.com/yume-chan/ya-webadb/issues
- npm.io page: https://npm.io/package/@yume-chan/stream-extra

## Dependencies (2)

- [@yume-chan/async](https://npm.io/package/@yume-chan/async.md) ^4.1.3
- [@yume-chan/struct](https://npm.io/package/@yume-chan/struct.md) ^2.3.2

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

- 2.6.1 (latest) — 2026-06-04
- 3.0.0-beta.4 (beta) — 2026-10-09
- 3.0.0-beta.3 — 2026-09-17
- 3.0.0-beta.2 — 2026-08-11
- 3.0.0-beta.1 — 2026-08-01
- 3.0.0-beta.0 — 2026-07-28
- 2.5.3 — 2026-03-25
- 2.1.0 — 2025-06-17
- 2.0.1 — 2025-04-04
- 2.0.0 — 2025-04-04
- 1.0.0 — 2024-12-02
- 0.0.0-next-20241130050937 — 2024-11-30
- 0.0.0-next-20241129144018 — 2024-11-29
- 0.0.0-next-20240917062356 — 2024-09-17
- 0.0.0-20240714132542 — 2024-07-14
- … 8 more at https://npm.io/package/@yume-chan/stream-extra/versions

## README

# @yume-chan/stream-extra

Some useful extensions for working with binary streams. Conforms to the [Web Streams API](https://streams.spec.whatwg.org/).

## Find an implementation

If all of `ReadableStream`, `WritableStream` and `TransformStream` fields are available on `globalThis`, they will be used. Otherwise, the [web-streams-polyfill](https://github.com/MattiasBuelens/web-streams-polyfill) package will be used.

Google Chrome 89 and Mozilla Firefox 102 provide full support for Web Streams API natively.

In Node.js, it's not possible to load the `stream/web` module while keeping the compatibility with both Web and bundlers:

-   Webpack has poor support with Top Level Await, for example, Hot Module Replacement doesn't work when any module is using TLA.
-   Web doesn't have the `module` module, thus requires a shim in import map.

Assigning `ReadableStream`, `WritableStream` and `TransformStream` from `stream/web` module to `globalThis`, before loading this library, will still work. Other custom polyfill can also be loaded this way.

## Compatibility issue with `ReadableStream#pipeTo` and `ReadableStream#pipeThrough`

The [Web Streams API spec](https://streams.spec.whatwg.org/#readable-stream-pipe-to) specifies that `ReadableStream#pipeTo` must check the argument to be an instance of `WritableStream`, so it can optimize the performance by calling internal methods directly.

Native implementations will perform this check, so `new globalThis.ReadableStream().pipeTo(new Polyfill.WritableStream())` will throw an error.

The `WrapReadableStream` class can be used to bypass this check:

```ts
import { WrapReadableStream } from "@yume-chan/stream-extra";
import { WritableStream as PolyfillWritableStream } from "web-streams-polyfill";

const nativeReadable = new globalThis.ReadableStream();
const wrappedReadable = new WrapReadableStream(new globalThis.ReadableStream());

nativeReadable.pipeTo(new PolyfillWritableStream()); // Error
wrappedReadable.pipeTo(new PolyfillWritableStream()); // OK
```

web-streams-polyfill package's `ReadableStream#pipeTo` only uses public methods, so it can be used with any `WritableStream` implementation.

## `BufferedReadableStream`

Allowing reading specified amount of data by buffering incoming data.

It's not a Web Streams API `ReadableStream`, because `ReadableStream` doesn't allow hinting the desired read size (except using BYOB readable, but causes extra allocations for small reads).

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