Skip to content

Commit

Permalink
Upgrade ReadableStream[Symbol.asyncIterator] ponyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 10, 2024
1 parent d2fafe7 commit c169fba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"concat"
],
"dependencies": {
"@sec-ant/readable-stream": "^0.3.2",
"@sec-ant/readable-stream": "^0.4.1",
"is-stream": "^4.0.1"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions source/stream.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {isReadableStream} from 'is-stream';
import {ponyfill} from './web-stream.js';
// eslint-disable-next-line n/file-extension-in-import

Check failure on line 2 in source/stream.js

View workflow job for this annotation

GitHub Actions / Node.js 21

'n/file-extension-in-import' rule is disabled but never reported.

Check failure on line 2 in source/stream.js

View workflow job for this annotation

GitHub Actions / Node.js 20

'n/file-extension-in-import' rule is disabled but never reported.

Check failure on line 2 in source/stream.js

View workflow job for this annotation

GitHub Actions / Node.js 18

'n/file-extension-in-import' rule is disabled but never reported.
import {asyncIterator} from '@sec-ant/readable-stream/ponyfill';

export const getAsyncIterable = stream => {
if (isReadableStream(stream, {checkOpen: false}) && nodeImports.on !== undefined) {
Expand All @@ -12,7 +13,7 @@ export const getAsyncIterable = stream => {

// `ReadableStream[Symbol.asyncIterator]` support is missing in multiple browsers, so we ponyfill it
if (toString.call(stream) === '[object ReadableStream]') {
return ponyfill.asyncIterator.call(stream);
return asyncIterator.call(stream);
}

throw new TypeError('The first argument must be a Readable, a ReadableStream, or an async iterable.');
Expand Down
13 changes: 0 additions & 13 deletions source/web-stream.js

This file was deleted.

12 changes: 3 additions & 9 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import {Duplex, Readable} from 'node:stream';
import {finished} from 'node:stream/promises';

// eslint-disable-next-line n/file-extension-in-import

Check failure on line 4 in test/helpers/index.js

View workflow job for this annotation

GitHub Actions / Node.js 21

'n/file-extension-in-import' rule is disabled but never reported.

Check failure on line 4 in test/helpers/index.js

View workflow job for this annotation

GitHub Actions / Node.js 20

'n/file-extension-in-import' rule is disabled but never reported.

Check failure on line 4 in test/helpers/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18

'n/file-extension-in-import' rule is disabled but never reported.
export {fromAnyIterable as readableStreamFrom} from '@sec-ant/readable-stream/ponyfill';

export const createStream = streamDef => typeof streamDef === 'function'
? Duplex.from(streamDef)
: Readable.from(streamDef);

// @todo Use ReadableStream.from() after dropping support for Node 18
export const readableStreamFrom = chunks => new ReadableStream({
start(controller) {
for (const chunk of chunks) {
controller.enqueue(chunk);
}

controller.close();
},
});

// Tests related to big buffers/strings can be slow. We run them serially and
// with a higher timeout to ensure they do not randomly fail.
Expand Down

0 comments on commit c169fba

Please sign in to comment.