// Web Streams API types are now available globally via DOM types in tsconfig export interface TextDecoderCommon { readonly encoding: string; readonly fatal: boolean; readonly ignoreBOM: boolean; } class TextDecodeTransformer implements Transformer { private decoder; constructor() { this.decoder = new TextDecoder(); } transform( chunk: ArrayBuffer | Uint8Array, controller: TransformStreamDefaultController ) { if (!(chunk instanceof ArrayBuffer || ArrayBuffer.isView(chunk))) { throw new TypeError('Input data must be a BufferSource'); } const text = this.decoder.decode(chunk, { stream: true }); if (text.length !== 0) { controller.enqueue(text); } } flush(controller: TransformStreamDefaultController) { const text = this.decoder.decode(); if (text.length !== 0) { controller.enqueue(text); } } } export class TextDecoderStreamPolyfill extends TransformStream< ArrayBuffer | Uint8Array, string > { constructor() { super(new TextDecodeTransformer()); } }