# StringDecoder

> The primary class exported by the [string_decoder](https://titaniumsdk.com/docs/sdk/string_decoder.md) core module.

- Source: https://titaniumsdk.com/docs/sdk/13.4.0/StringDecoder
- Titanium SDK version: 13.4.0
- Kind: pseudo
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 8.3.0

## Methods

### constructor

- Platforms: Android, iPhone, iPad, macOS

Creates a new `StringDecoder` instance.

Parameters:

- `encoding` (String, optional): The character encoding the `StringDecoder` will use. Default: `utf8`.

Returns: StringDecoder

### end

- Platforms: Android, iPhone, iPad, macOS

Returns any remaining input stored in the internal buffer as a string. Bytes representing incomplete UTF-8 and UTF-16 characters will be replaced with substitution characters appropriate for the character encoding.

If the `buffer` argument is provided, one final call to `stringDecoder.write()` is performed before returning the remaining input. After `end()` is called, the `stringDecoder` object can be reused for new input.

Parameters:

- `buffer` (buffer.Buffer | Uint8Array, optional): A `Buffer`, or `TypedArray`, or `DataView` containing the bytes to decode. Default: `utf8`.

Returns: String

### write

- Platforms: Android, iPhone, iPad, macOS

Returns a decoded string, ensuring that any incomplete multibyte characters at the end of the `Buffer`, or `TypedArray`, or `DataView` are omitted from the returned string and stored in an internal buffer for the next call to `stringDecoder.write()` or `stringDecoder.end()`.

Parameters:

- `buffer` (buffer.Buffer | Uint8Array): A `Buffer`, or `TypedArray`, or `DataView` containing the bytes to decode.

Returns: String

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

