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 16, 2024
1 parent 26c7e41 commit 903d3a2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 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
4 changes: 2 additions & 2 deletions source/stream.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {isReadableStream} from 'is-stream';
import {ponyfill} from './web-stream.js';
import {asyncIterator} from '@sec-ant/readable-stream/ponyfill';

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

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

// @todo Use ReadableStream.from() after dropping support for Node 18
export {fromAnyIterable as readableStreamFrom} from '@sec-ant/readable-stream/ponyfill';

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

// @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.
export const BIG_TEST_DURATION = '2m';
Expand Down

0 comments on commit 903d3a2

Please sign in to comment.