class TextDecoder

Supported only in the v8 engine. Introduced in Max v9.2.0.

Decodes UTF-8 bytes into a JavaScript string.

Only UTF-8 is supported.

Example

const text = new TextDecoder().decode(new TextEncoder().encode("hello"));
post(text, "\n"); // hello

Index

Constructors

Properties

Methods

new TextDecoder(label, options)

new TextDecoder(
  label?: string,
  options?: { fatal?: boolean; ignoreBOM?: boolean },
);

Constructs a new instance of the TextDecoder class

ParameterTypeDescription
optional labelstringthe encoding label. Only "utf-8" is supported.
optional optionsobjectdecoder options.
optional options.fatal boolean
optional options.ignoreBOM boolean

decode(input)

Decodes bytes into a string.

decode(input?: ArrayBuffer | ArrayBufferView): string;
NameTypeDescription
optional inputArrayBuffer | ArrayBufferViewthe bytes to decode: an buffer.IOBuffer, typed array, or ArrayBuffer.
Return Valuestringthe decoded string

encoding string read-only

The decoder's encoding, "utf-8".

fatal boolean read-only

Whether decoding errors throw rather than emitting a replacement character.

ignoreBOM boolean read-only

Whether a leading byte-order mark is preserved rather than stripped.