# StringDecoder

The primary class exported by the string_decoder core module.

Availability
8.3.0
8.3.0
9.2.0
Extends
Object

NOTE

This is an abstract type. Any object of this structure can be used where this type is used.

# Methods

# constructor

Availability
8.3.0
8.3.0
9.2.0
constructor([encoding]) StringDecoder

Creates a new StringDecoder instance.

Parameters

Name Type Description
encoding String

The character encoding the StringDecoder will use.

Returns


# end

Availability
8.3.0
8.3.0
9.2.0
end([buffer]) String

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

Name Type Description
buffer buffer.Buffer | Uint8Array

A Buffer, or TypedArray, or DataView containing the bytes to decode.

Returns

Type
String

# write

Availability
8.3.0
8.3.0
9.2.0
write(buffer) String

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

Name Type Description
buffer buffer.Buffer | Uint8Array

A Buffer, or TypedArray, or DataView containing the bytes to decode.

Returns

Type
String