Utf8StreamDecoder
class exported by @mwillbanks/tuil-streaming.
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
| Member | Type | Required | Description | Related types |
|---|---|---|---|---|
id | "utf8" | Yes | The id member uses the "utf8" contract. | — |
#decoder | TextDecoder | Yes | The #decoder member uses the TextDecoder contract. | — |
write | (chunk: Uint8Array | string) => string | Yes | The write member uses the (chunk: Uint8Array | string) => string contract. | — |
flush | () => string | Yes | The flush member uses the () => string contract. | — |
reset | () => void | Yes | The 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.
Related types
Source
View the secondary source reference