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

Example for polyfilling TextDecoderStream in previous browsers #116

Open
Krithika3 opened this issue May 11, 2022 · 3 comments
Open

Example for polyfilling TextDecoderStream in previous browsers #116

Krithika3 opened this issue May 11, 2022 · 3 comments
Labels

Comments

@Krithika3
Copy link

Hi I was looking to see if we could get an example to polyfill web-streams TextDecoderStream for browsers like firefox as listed here:
https://developer.mozilla.org/en-US/docs/Web/API/TransformStream

It would be great if I could find an example for the same

@MattiasBuelens
Copy link
Owner

There's a polyfill for TextEncoderStream and TextDecoderStream in the demos of the Streams standard. You can first load web-streams-polyfill to define TransformStream, and then load the encoding stream polyfill.

Even better: the encoding streams polyfill is available as an npm package over at @stardazed/streams-text-encoding. It should be compatible with web-streams-polyfill, so you can do something like:

import 'web-streams-polyfill';
import { TextDecoderStream } from '@stardazed/streams-text-encoding';

readable.pipeThrough(new TextDecoderStream()).pipeTo(/* ... */);

@Krithika3
Copy link
Author

Thanks @MattiasBuelens :) I will try it out. Appreciate your help

@octet-stream
Copy link

@MattiasBuelens I think it would be nice to have both of these polyfills included too, could be useful in some other runtimes, like Bun, which is still has no TextEncoderStream and TextDecoderStream. Here's the issue I am referring: oven-sh/bun#5648 and here's my proposal for implementation (basically same Node.js' implementation, but TS flavored) in comments: oven-sh/bun#5648 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants