Options
All
  • Public
  • Public/Protected
  • All
Menu

A class that can decode UTF-8 text in a streaming fashion.

example
const decoder = new TextDecoder();
let chunk;
let result = "";
while (chunk = await getNextChunk()) {
  result += decoder.decode(chunk, { stream: true });
}
result += decoder.decode();

Hierarchy

  • TextDecoder

Index

Constructors

Accessors

Methods

Constructors

constructor

  • new TextDecoder(encoding?: string, options?: TextDecoderOptions): TextDecoder
  • Constructs a new TextDecoder.

    Parameters

    • Optional encoding: string
    • options: TextDecoderOptions = ...

    Returns TextDecoder

Accessors

encoding

  • get encoding(): string
  • Returns 'utf-8'.

    Returns string

fatal

  • get fatal(): boolean
  • Whether the decoder will throw an exception on an invalid character.

    If false, invalid bytes are replaced by a UTF-8 replacement character.

    Returns boolean

Methods

decode

  • decode(buffer?: ArrayBufferView | ArrayBuffer, options?: DecodeOptions): any
  • Decodes a buffer of UTF-8 encoded data.

    Parameters

    • Optional buffer: ArrayBufferView | ArrayBuffer

      The data to decode. If null is passed, represents the last chunk.

    • options: DecodeOptions = ...

      Decoding options, whether to decode in a streaming fashion.

    Returns any

Generated using TypeDoc