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
| Parameter | Type | Description |
|---|---|---|
| optional label | string | the encoding label. Only "utf-8" is supported. |
| optional options | object | decoder options. optional options.fatal boolean optional options.ignoreBOM boolean |
decode(input)
Decodes bytes into a string.
decode(input?: ArrayBuffer | ArrayBufferView): string;
| Name | Type | Description |
|---|---|---|
| optional input | ArrayBuffer | ArrayBufferView | the bytes to decode: an buffer.IOBuffer, typed array, or ArrayBuffer. |
| Return Value | string | the 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.