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 WebStreams #120

Open
2color opened this issue Jan 11, 2023 · 6 comments
Open

Add support for WebStreams #120

2color opened this issue Jan 11, 2023 · 6 comments
Labels
P2 Medium: Good to have, but can wait until someone steps up

Comments

@2color
Copy link

2color commented Jan 11, 2023

Background

I'm exploring verified (trustless) retrieval of CAR files (See olizilla/ipfs-get#15) in browsers.

I discovered that there's no way to instantiate a CarReader from a ReadableStream returned from the Fetch API in the browser.

This is because Readable Web Streams are not iterable by default.

Adding support for Web Streams

For us to be able to promote verified retrieval in browsers, it would be nice to have full CAR support in browsers. For this, we need a way to instantiate a CAR Reader in the browser from a Readable Web Streams.

My current work around is to use @achingbrain's browser-readablestream-to-it
library

@RangerMauve
Copy link

In my experience, one can convert ReadableStreams into async iterators with either polyfills for a built in [Symbol.asyncIterator]() method, or using the example in the mdn docs which can convert to one in code.

Is this something we can add docs in the README for, or is it absolutely necessary to be able to accept ReadableStreams as arguments?

@RangerMauve
Copy link

The spec discussion for making them async iterable can be found here: whatwg/streams#778 (comment)

I think the current best practice is to include a polyfill in your code for it since it's slowly making it's way into implementations.

@2color
Copy link
Author

2color commented Jan 27, 2023

or using the example in the mdn docs which can convert to one in code.

That converts it the other way (iterator -> stream)

Is this something we can add docs in the README for, or is it absolutely necessary to be able to accept ReadableStreams as arguments?

That's not for me to decide, but I'd add a note about this, at the very least. Accepting ReadableStreams would be a nice DX improvement, given the primacy of web APIs and their universality.

@BigLep BigLep added the P2 Medium: Good to have, but can wait until someone steps up label Feb 21, 2023
@BigLep
Copy link

BigLep commented Feb 21, 2023

2023-02-21 maintainer conversation: IPLD maintenance team is a skeleton crew right now. Is this something you would want to pick up @2color ? @rvagg is happy to review or answer questions.

@2color
Copy link
Author

2color commented Feb 22, 2023

That's understandable.

I don't have the capacity right now. But I'll revisit this if time allows.

@RangerMauve
Copy link

Might experiment with this in WebRecorder since we're working on some custom chunking to CAR use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Medium: Good to have, but can wait until someone steps up
Projects
None yet
Development

No branches or pull requests

3 participants