{"name":"@sec-ant/readable-stream","version":"0.7.0","keywords":["stream","web-streams","readablestream","async","asynchronous","iterator","iteration","async-iterator","polyfill","esm","from-iterable"],"author":{"name":"Ze-Zheng Wu"},"license":"MIT","_id":"@sec-ant/readable-stream@0.7.0","maintainers":[{"name":"sec-ant","email":"zezhengwu@proton.me"}],"homepage":"https://github.com/Sec-ant/readable-stream","bugs":{"url":"https://github.com/Sec-ant/readable-stream/issues","email":"zezhengwu@proton.me"},"dist":{"shasum":"424a7c2d49f98c23e47f981862d8b2bb47912fe3","tarball":"http://registry-npm.ywwl.com/@sec-ant/readable-stream/download/@sec-ant/readable-stream-0.7.0.tgz","fileCount":28,"integrity":"sha512-eeflyrQR+jQaliaTcC2R+EG+JkPZpCHbpTN8w0K5LhhXzrI0XmES9CPt6uF4u/Gc4PUafaBzq4dj5WLvQ/YnsA==","signatures":[{"sig":"MEUCIQCYReWqLDJYiOJ0z4Bf0eYCudYDWRMcx4DsCOIT6anemQIgEbd7yX0brz4FA2HKRW4zRnGn2rFwJ4afzpH3Ak+j0Lk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@sec-ant%2freadable-stream@0.7.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":18648,"size":5579,"noattachment":false,"key":"/@sec-ant/readable-stream/-/@sec-ant/readable-stream-0.7.0.tgz"},"main":"./dist/index/index.js","type":"module","types":"./dist/index/index.d.ts","module":"./dist/index/index.js","exports":{".":"./dist/index/index.js","./polyfill":"./dist/polyfill/index.js","./ponyfill":"./dist/ponyfill/index.js","./asyncIterator":"./dist/index/asyncIterator.js","./async-iterator":{"types":"./dist/types/async-iterator.d.ts"},"./fromAnyIterable":"./dist/index/fromAnyIterable.js","./polyfill/asyncIterator":"./dist/polyfill/asyncIterator.js","./ponyfill/asyncIterator":"./dist/ponyfill/asyncIterator.js","./polyfill/fromAnyIterable":"./dist/polyfill/fromAnyIterable.js","./ponyfill/fromAnyIterable":"./dist/ponyfill/fromAnyIterable.js"},"private":false,"scripts":{"copy":"copy-files-from-to","test":"vitest run","build":"vite build","check":"conc \"npm:format:prettier\" \"npm:check:biome\"","format":"conc \"npm:format:prettier\" \"npm:format:biome\"","test:ci":"vitest run","test:ui":"vitest --ui --coverage","prebuild":"pnpm -s check && pnpm -s type-check","postbuild":"tsc && pnpm -s copy","type-check":"tsc --noEmit --emitDeclarationOnly false","check:biome":"biome check --write .","format:biome":"biome format . --write","test:firefox":"vitest run --browser=firefox","update-hooks":"simple-git-hooks","test:chromium":"vitest run --browser=chromium","test:coverage":"vitest run --coverage","format:prettier":"prettier . --write","bump-biome:latest":"pnpm add -DE @biomejs/biome@latest","bump-biome:nightly":"pnpm add -DE @biomejs/biome@nightly"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:587e5759-ba10-4ce0-bcc6-f672f5ca0a7c"}},"repository":{"url":"git+https://github.com/Sec-ant/readable-stream.git","type":"git"},"description":"A tiny, zero-dependency yet spec-compliant asynchronous iterator polyfill/ponyfill for ReadableStreams.","directories":{},"_nodeVersion":"25.9.0","publishConfig":{"access":"public"},"typesVersions":{"*":{"polyfill":["./dist/polyfill/index.d.ts"],"ponyfill":["./dist/ponyfill/index.d.ts"],"asyncIterator":["./dist/index/asyncIterator.d.ts"],"async-iterator":["./dist/types/async-iterator.d.ts"],"fromAnyIterable":["./dist/index/fromAnyIterable.d.ts"],"polyfill/asyncIterator":["./dist/polyfill/asyncIterator.d.ts"],"ponyfill/asyncIterator":["./dist/ponyfill/asyncIterator.d.ts"],"polyfill/fromAnyIterable":["./dist/polyfill/fromAnyIterable.d.ts"],"ponyfill/fromAnyIterable":["./dist/ponyfill/fromAnyIterable.d.ts"]}},"_hasShrinkwrap":false,"devDependencies":{"vite":"^8.0.10","vitest":"^4.1.5","prettier":"^3.8.3","@vitest/ui":"^4.1.5","playwright":"^1.59.1","typescript":"^6.0.3","lint-staged":"^16.4.0","concurrently":"^9.2.1","@biomejs/biome":"2.4.13","@changesets/cli":"^2.31.0","@commitlint/cli":"^20.5.2","@vitest/browser":"^4.1.5","simple-git-hooks":"^2.13.1","copy-files-from-to":"^4.0.0","@vitest/coverage-istanbul":"^4.1.5","@vitest/browser-playwright":"4.1.5","@commitlint/config-conventional":"^20.5.0"},"_npmOperationalInternal":{"tmp":"tmp/readable-stream_0.7.0_1777897910241_0.7494445853165987","host":"s3://npm-registry-packages-npm-production"},"readme":"# @sec-ant/readable-stream\n\n[![npm version](https://img.shields.io/npm/v/@sec-ant/readable-stream?cacheSeconds=300)](https://www.npmjs.com/package/@sec-ant/readable-stream/v/latest) [![npm downloads](https://img.shields.io/npm/dm/@sec-ant/readable-stream?cacheSeconds=300)](https://www.npmjs.com/package/@sec-ant/readable-stream/v/latest) [![](https://img.shields.io/jsdelivr/npm/hm/@sec-ant/readable-stream?cacheSeconds=300&color=ff5627)](https://www.jsdelivr.com/package/npm/@sec-ant/readable-stream) [![bundlephobia minzipped](https://img.shields.io/bundlephobia/minzip/@sec-ant/readable-stream?cacheSeconds=300)](https://bundlephobia.com/package/@sec-ant/readable-stream@latest) [![npm license](https://img.shields.io/npm/l/@sec-ant/readable-stream?cacheSeconds=300)](https://www.npmjs.com/package/@sec-ant/readable-stream/v/latest)\n\nA tiny, zero-dependency asynchronous iterator polyfill/ponyfill for [`ReadableStream`](https://developer.mozilla.org/docs/Web/API/ReadableStream)s.\n\n## Features\n\n### Asynchronously iterate a `ReadableStream`\n\nWith this package, you can consume a `ReadableStream` as an `AsyncIterable`.\n\n- spec: https://streams.spec.whatwg.org/#rs-asynciterator\n- tests: https://github.com/Sec-ant/readable-stream/blob/main/tests/asyncIterator.spec.ts (copied from [wpt](https://github.com/web-platform-tests/wpt/blob/309231a7f3e900d04914bc4963b016efd9989a00/streams/readable-streams/async-iterator.any.js))\n\n### Convert an `AsyncIterable` or an `Iterable` into a `ReadableStream`\n\nWith this package, you can construct a `ReadableStream` from an `AsyncIterable` or an `Iterable`.\n\n- spec: https://streams.spec.whatwg.org/#rs-from\n- tests: https://github.com/Sec-ant/readable-stream/blob/main/tests/fromAnyIterable.spec.ts (copied from [wpt](https://github.com/web-platform-tests/wpt/blob/309231a7f3e900d04914bc4963b016efd9989a00/streams/readable-streams/from.any.js))\n\nThis package passes all the aforementioned tests.\n\n## Install\n\n```bash\nnpm i @sec-ant/readable-stream\n```\n\n## Usage\n\n### Ponyfill\n\nThis package can be imported as a _ponyfill_ to avoid side effects:\n\n#### `asyncIterator`\n\nPath:\n\n```\n@sec-ant/readable-stream/ponyfill/asyncIterator\n```\n\nExample:\n\n```ts\nimport {\n  asyncIterator,\n  type ReadableStreamIteratorOptions,\n} from \"@sec-ant/readable-stream/ponyfill/asyncIterator\";\n\nconst readableStream = (await fetch(\"https://www.example.org/\")).body;\n\nlet total = 0;\nfor await (const chunk of asyncIterator(readableStream)) {\n  total += chunk.length;\n}\n\nconsole.log(total);\n```\n\nCheck https://streams.spec.whatwg.org/#rs-class-definition and https://streams.spec.whatwg.org/#rs-asynciterator for further explanation on `ReadableStreamIteratorOptions`.\n\n#### `fromAnyIterable`\n\nPath:\n\n```\n@sec-ant/readable-stream/ponyfill/fromAnyIterable\n```\n\nExample:\n\n```ts\nimport { fromAnyIterable } from \"@sec-ant/readable-stream/ponyfill/fromAnyIterable\";\n\nconst readableStream = fromAnyIterable([\"a\", \"b\"]);\n```\n\n#### All-in-One\n\nPath:\n\n```\n@sec-ant/readable-stream/ponyfill\n```\n\nExample:\n\n```ts\nimport {\n  fromAnyIterable,\n  asyncIterator,\n  type ReadableStreamIteratorOptions,\n} from \"@sec-ant/readable-stream/ponyfill\";\n```\n\n### Polyfill\n\nThis package can be imported as a drop-in _polyfill_ with side effects.\n\n#### `ReadableStream.prototype[Symbol.asyncIterator]` and `ReadableStream.prototype.values`\n\nPath:\n\n```\n@sec-ant/readable-stream/polyfill/asyncIterator\n```\n\nExample:\n\n```ts\nimport \"@sec-ant/readable-stream/polyfill/asyncIterator\";\n\nconst readableStream = (await fetch(\"https://www.example.org/\")).body;\n\nlet total = 0;\nfor await (const chunk of readableStream) {\n  total += chunk.length;\n}\n\nconsole.log(total);\n```\n\n#### `ReadableStream.from`\n\nPath:\n\n```\n@sec-ant/readable-stream/polyfill/fromAnyIterable\n```\n\nExample:\n\n```js\nimport \"@sec-ant/readable-stream/polyfill/fromAnyIterable\";\n\nconst readableStream = ReadableStream.from([\"a\", \"b\"]);\n```\n\nThe `fromAnyIterable` export provides TypeScript types for iterable-to-stream conversion.\n\n#### All-in-One\n\nPath:\n\n```\n@sec-ant/readable-stream/polyfill\n```\n\nExample:\n\n```ts\nimport \"@sec-ant/readable-stream/polyfill\";\n```\n\n### Ponyfill + Polyfill\n\n#### `asyncIterator`\n\nPath:\n\n```\n@sec-ant/readable-stream/asyncIterator\n```\n\nExample:\n\n```ts\nimport {\n  asyncIterator,\n  type ReadableStreamIteratorOptions,\n} from \"@sec-ant/readable-stream/asyncIterator\";\n// also with side effects\n```\n\n#### `fromAnyIterable`\n\nPath:\n\n```\n@sec-ant/readable-stream/fromAnyIterable\n```\n\nExample:\n\n```ts\nimport { fromAnyIterable } from \"@sec-ant/readable-stream/fromAnyIterable\";\n// also with side effects\n```\n\n#### All-in-One\n\nPath:\n\n```\n@sec-ant/readable-stream\n```\n\nExample:\n\n```ts\nimport {\n  fromAnyIterable,\n  asyncIterator,\n  type ReadableStreamIteratorOptions,\n} from \"@sec-ant/readable-stream\";\n// also with side effects\n```\n\n### Types\n\nYou can also use this package to augment the `ReadableStream` type for async iteration if the runtime already supports it but the type system does not.\n\nPath:\n\n```\n@sec-ant/readable-stream/async-iterator\n```\n\nExample:\n\n```ts\n/// <reference types=\"@sec-ant/readable-stream/async-iterator\" />\n```\n\n## Development\n\nUse Node.js 24 and the pnpm version declared in `package.json`.\n\n```sh\npnpm install --frozen-lockfile\npnpm test:coverage\npnpm test:wpt\npnpm benchmark\npnpm benchmark:memory\n```\n\nBrowser tests run in Chromium, Firefox, and WebKit. WPT runs the upstream async\niteration, iterable conversion, cross-realm, and Streams IDL suites in Window and\nDedicated Worker environments. The IDL suite compares polyfill results with the\nbrowser's native baseline. The upstream revision is pinned in\n`compatibility/prepare.mjs` and configurable through `WPT_REVISION`.\n\nThe verified runtime matrix includes Chromium 156, Firefox 157, WebKit 27.2,\nSafari 27.2, Chrome 114, Firefox 115, and WebKit 17. These tests use native\n`ReadableStream` support and the package's ESNext build. WebKit entries refer to\nPlaywright engine builds.\n\nFor Safari, enable remote automation and run `safaridriver -p 4444` in a separate\nterminal. The legacy installer provides isolated macOS browser downloads.\n\n```sh\nCOMPAT_BROWSERS=safari pnpm test:wpt\nnode compatibility/install-legacy.mjs\nCOMPAT_BROWSERS=chrome-114,firefox-legacy,webkit-legacy pnpm test:wpt\n```\n\nBenchmarks compare the current implementation with the revision pinned in\n`benchmarks/prepare.mjs`. Each workload has six warmup rounds and 25 measured\nrounds with rotating implementation order. Node, Chromium, and Firefox run\nsequentially. Individual runtimes can be selected with `pnpm benchmark node` or\n`pnpm benchmark chromium firefox`.\n\nAllocation sampling measures allocated bytes across the Node workload. The\nretention check verifies collection of consumed buffers while iterators remain\nalive. Reports, upstream sources, and browser downloads are generated under\n`.vitest/`.\n\n## License\n\nMIT\n","publish_time":1777897910373,"_cnpm_publish_time":1777897910373,"dist-tags":{"latest":"0.7.1"}}