Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ReadableStream #82

Merged
merged 5 commits into from
Aug 9, 2023
Merged

Add support for ReadableStream #82

merged 5 commits into from
Aug 9, 2023

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Aug 9, 2023

This adds support for web/Node.js ReadableStreams.

This also adds support for any async iterable as input, since this is the common denominator between Node.js streams and web ReadableStream (which we just consume with a for await loop).

@ehmicky ehmicky marked this pull request as draft August 9, 2023 20:43
@ehmicky ehmicky marked this pull request as ready for review August 9, 2023 20:53
```js
const {body: readableStream} = await fetch('https://example.com');
console.log(await getStream(readableStream));
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this to the TS docs too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 80ac07e. 👍

index.d.ts Outdated
@@ -6,6 +6,9 @@ export class MaxBufferError extends Error {
constructor();
}

type StreamItem = string | Buffer | ArrayBuffer | ArrayBufferView;
type AnyStream = Readable | ReadableStream<StreamItem> | AsyncIterable<StreamItem>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would export this, in case the user needs to refer to the input without passing it directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6990861. 👍

@sindresorhus sindresorhus merged commit 8a5274b into sindresorhus:main Aug 9, 2023
3 checks passed
@ehmicky ehmicky deleted the add-readable-stream branch August 9, 2023 22:17
This was referenced Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants