TextDecoderStream()

The TextDecoderStream() constructor creates a new TextDecoderStream object which is used to convert a stream of text in a binary encoding into strings.

Syntax

var TextDecoderStream = new TextDecoderStream(label,options);

Parameters

label

A DOMString defaulting to utf-8. This may be any valid label.

optionsOptional

A TextDecoderOptions dictionary with the property:

fatal

A boolean value indicating the error mode. If true then a DOMException will be thrown if the decoder encounters an error. Defaults to false.

Examples

The following example demonstrates how to decode binary data retrieved from a fetch() call. The data will be interpreted as UTF-8, as no label has been passed.

const response = await fetch("https://example.com");
const stream = response.body.pipeThrough(new TextDecoderStream());

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
TextDecoderStream
71
79
No
No
58
14.1
71
71
No
50
14.5
10.0

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/TextDecoderStream/TextDecoderStream