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

Loosen brand checks on ReadableStream methods #101

Merged
merged 3 commits into from
Nov 17, 2021

Conversation

MattiasBuelens
Copy link
Owner

@MattiasBuelens MattiasBuelens commented Oct 29, 2021

In #96, #98 and #99, we made pipeTo(), pipeThrough(), tee() and [Symbol.asyncIterator]() use only the public API rather than relying on internal abstract operations.

This PR brings it all together by loosening the brand checks on these methods. You'll now be able to call readable.pipeTo(writable) with any writable that "looks like" a WritableStream, i.e. anything that has a sufficiently compliant getWriter() method. This includes native WritableStreams, or even WritableStreams constructed by a different polyfill. 😁

In theory, you could also call these on anything that "looks like" a ReadableStream, although it's currently still a bit awkward:

import { ReadableStream, WritableStream } from 'web-streams-polyfill';
const nativeReadable = new Response("Hello world!").body;
const destination = new WritableStream({ /* ... */ });
const pipePromise = ReadableStream.prototype.pipeTo.call(nativeReadable, destination);

@MattiasBuelens MattiasBuelens added this to the v4.0.0 milestone Oct 29, 2021
@MattiasBuelens MattiasBuelens self-assigned this Oct 29, 2021
@jimmywarting
Copy link

const pipePromise = ReadableStream.prototype.pipeTo.call(nativeReadable, destination);

Well, that's some hacky shit :P
would be better if something was extended or patched based on the native (builtin)

@MattiasBuelens
Copy link
Owner Author

would be better if something was extended or patched based on the native (builtin)

Yes, I'll get to that. This isn't a final solution yet. 😉

@MattiasBuelens MattiasBuelens merged commit e10fb3c into next Nov 17, 2021
@MattiasBuelens MattiasBuelens deleted the loosen-brand-checks branch November 17, 2021 15:15
MattiasBuelens added a commit that referenced this pull request Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants