{"_id":"@sec-ant/readable-stream@0.7.1","bugs":{"url":"https://github.com/Sec-ant/readable-stream/issues","email":"zezhengwu@proton.me"},"dist":{"shasum":"757f772214a747cc8b7d143c4bcbf9cc54f189ae","tarball":"http://registry-npm.ywwl.com/@sec-ant/readable-stream/download/@sec-ant/readable-stream-0.7.1.tgz","fileCount":28,"integrity":"sha512-6TKdF2lufN3VGu7krX6wNGPsfJYzuVZCekPfcXEQxhH68IAjsP9WBJ9BUr7L+4Ijh248/Od/guUIeE9Z7elE4w==","signatures":[{"sig":"MEUCIGEEBcH0Oam+GnVFqwC575aAPrKe8sf+nVGPm1Pt1FZbAiEA7FRZGhpQwVG/lp790wsaY4bWJ2bbjYI9mkIEbJgmda4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD/AV1jEAofPJBDdRzlumh1EyMiE3u89kKGMr4m5kKcPQIgR5+7NPJcWr/fJ17uPYPwF4B1yJkMQ8bL8HOBZIFyQGY="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@sec-ant%2freadable-stream@0.7.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":21134,"size":6768,"noattachment":false,"key":"/@sec-ant/readable-stream/-/@sec-ant/readable-stream-0.7.1.tgz"},"main":"./dist/index/index.js","name":"@sec-ant/readable-stream","type":"module","types":"./dist/index/index.d.ts","author":{"name":"Ze-Zheng Wu"},"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"},"license":"MIT","private":false,"scripts":{"copy":"node --input-type=module -e \"import { cp } from 'node:fs/promises'; await cp('src/types', 'dist/types', { recursive: true })\"","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","test:wpt":"pnpm -s build && node compatibility/prepare.mjs && vitest run --config vitest.tools.config.mjs --project=wpt","benchmark":"node benchmarks/run.mjs","postbuild":"tsc && pnpm -s copy","type-check":"tsc --noEmit --emitDeclarationOnly false && tsc -p tsconfig.test.json","check:biome":"biome check --write .","test:webkit":"vitest run --project=webkit","format:biome":"biome format . --write","test:firefox":"vitest run --project=firefox","update-hooks":"simple-git-hooks","test:chromium":"vitest run --project=chromium","test:coverage":"vitest run --coverage","format:prettier":"prettier . --write","benchmark:memory":"node benchmarks/prepare.mjs && vitest run --config vitest.tools.config.mjs --project=memory","bump-biome:latest":"pnpm add -DE @biomejs/biome@latest","bump-biome:nightly":"pnpm add -DE @biomejs/biome@nightly"},"version":"0.7.1","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"587e5759-ba10-4ce0-bcc6-f672f5ca0a7c"}},"homepage":"https://github.com/Sec-ant/readable-stream","keywords":["stream","web-streams","readablestream","async","asynchronous","iterator","iteration","async-iterator","polyfill","esm","from-iterable"],"repository":{"url":"git+https://github.com/Sec-ant/readable-stream.git","type":"git"},"description":"A tiny, zero-dependency asynchronous iterator polyfill/ponyfill for ReadableStreams.","directories":{},"maintainers":[{"name":"sec-ant","email":"zezhengwu@proton.me"}],"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.3.5","vitest":"^5.0.5","prettier":"^3.9.10","@vitest/ui":"^5.0.5","playwright":"^1.64.1","typescript":"^7.0.2","@types/node":"^24.19.2","lint-staged":"^17.6.0","concurrently":"^10.0.6","@biomejs/biome":"2.6.2","@changesets/cli":"^3.0.3","@commitlint/cli":"^21.2.4","@vitest/browser":"^5.0.5","simple-git-hooks":"^2.14.0","@vitest/coverage-istanbul":"^5.0.5","@vitest/browser-playwright":"5.0.5","@commitlint/config-conventional":"^21.2.4"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/readable-stream_0.7.1_1792825463006_0.8104010804806749"},"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":1792825463106,"_cnpm_publish_time":1792825463106,"dist-tags":{"latest":"0.7.1"}}