# Utf8StreamDecoder

Source: /tuil/docs/reference/packages/streaming/api/utf8-stream-decoder
Locale: en

class exported by @mwillbanks/tuil-streaming.



{/* Generated by tooling/docs/generate-reference.ts. */}

## class [#class]

Public class exported by `@mwillbanks/tuil-streaming`.

```ts
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 [#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 [#parameters]

This declaration has no public members.

## Returns [#returns]

This declaration does not return a value.

## Throws [#throws]

No thrown errors are documented for this declaration.

## Related types [#related-types]

* [`StreamDecoder`](/tuil/docs/reference/packages/streaming/api/stream-decoder)

## Source [#source]

[View the secondary source reference](https://github.com/mwillbanks/tuil/blob/main/packages/streaming/src/index.ts)

## Package [#package]

[@mwillbanks/tuil-streaming](/tuil/docs/reference/packages/streaming)
