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 toutf-8
. This may be any valid label. options
Optional- A
TextDecoderOptions
dictionary with the property:fatal
- A
boolean
indicating the error mode. If true then aDOMException
will be thrown if the decoder encounters an error. Defaults tofalse
.
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
Specification | Status | Comment |
---|---|---|
Encoding The definition of 'TextDecoderStream()' in that specification. |
Living Standard | Initial definition. |
Browser compatibility
BCD tables only load in the browser