Web APIs

TextDecoderStream

Try the free JavaScript compiler

Decodes incoming byte chunks with retained decoding state; exposes writable and readable streams.

Formal Syntax & Structure

javascript syntaxjavascript
new TextDecoderStream(encoding, options)

Parameters & Attributes

NameTypeDescription
encodingstringEncoding label, default UTF-8.
optionsobjectDecoder 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(""));})()
JavaScript Reference