The string_decoder module provides an API for decoding Buffer objects into
strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16
characters. It can be accessed using:
When a Buffer instance is written to the StringDecoder instance, an
internal buffer is used to ensure that the decoded string does not contain
any incomplete multibyte characters. These are held in the buffer until the
next call to stringDecoder.write() or until stringDecoder.end() is called.
In the following example, the three UTF-8 encoded bytes of the European Euro
symbol (€) are written over three separate operations:
The
string_decoder
module provides an API for decodingBuffer
objects into strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16 characters. It can be accessed using:The following example shows the basic use of the
StringDecoder
class.When a
Buffer
instance is written to theStringDecoder
instance, an internal buffer is used to ensure that the decoded string does not contain any incomplete multibyte characters. These are held in the buffer until the next call tostringDecoder.write()
or untilstringDecoder.end()
is called.In the following example, the three UTF-8 encoded bytes of the European Euro symbol (
€
) are written over three separate operations:See
source