Web APIs
TextDecoderStream
Decodes incoming byte chunks with retained decoding state; exposes writable and readable streams.
Formal Syntax & Structure
javascript syntaxjavascript
new TextDecoderStream(encoding, options)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| encoding | string | Encoding label, default UTF-8. |
| options | object | Decoder options. |
Return Value
TextDecoderStream
Decodes incoming byte chunks with retained decoding state; exposes writable and readable streams.
Working Example
Example Snippetjavascript
(async () => {const s=new ReadableStream({start(c){c.enqueue(new Uint8Array([195]));c.enqueue(new Uint8Array([169]));c.close();}});const out=[];await s.pipeThrough(new TextDecoderStream()).pipeTo(new WritableStream({write(v){out.push(v);}}));console.log(out.join(""));})()