tuil
ReferencePackages@mwillbanks/tuil-streamingAPI

Utf8StreamDecoder

class exported by @mwillbanks/tuil-streaming.

View rawEdit

class

Public class exported by @mwillbanks/tuil-streaming.

export class Utf8StreamDecoder implements StreamDecoder {
  readonly id = "utf8";
  readonly #decoder = new TextDecoder("utf-8", { fatal: false });

  write(chunk: Uint8Array | string): string {
    return typeof chunk === "string"
      ? chunk
      : this.#decoder.decode(chunk, { stream: true });
  }

  flush(): string {
    return this.#decoder.decode();
  }

  reset(): void {
    // TextDecoder has no reset primitive; flushing establishes a new stream.
    this.#decoder.decode();
  }
}

Members

MemberTypeRequiredDescriptionRelated types
id"utf8"YesThe id member uses the "utf8" contract.
#decoderTextDecoderYesThe #decoder member uses the TextDecoder contract.
write(chunk: Uint8Array | string) => stringYesThe write member uses the (chunk: Uint8Array | string) => string contract.
flush() => stringYesThe flush member uses the () => string contract.
reset() => voidYesThe reset member uses the () => void contract.

Parameters

This declaration has no public members.

Returns

This declaration does not return a value.

Throws

No thrown errors are documented for this declaration.

Source

View the secondary source reference

Package

@mwillbanks/tuil-streaming

On this page