Example for polyfilling TextDecoderStream in previous browsers
Krithika3 opened this issue · 3 comments
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
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(/* ... */);
Thanks @MattiasBuelens :) I will try it out. Appreciate your help
@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)