![]() |
VOOZH | about |
The stringDecoder.write() method in Node.js is used to decode data from a Buffer, TypedArray, or DataView into a string. It helps correctly process character data by handling incomplete multibyte characters across multiple chunks.
write() or end() calls.Syntax:
stringDecoder.write( buffer )where,
Return Value: It returns a string which is decoded from the given buffer.
Example 1:
In this code, A StringDecoder object is created with UTF-8 encoding to decode data stored in a Buffer. The write() method converts the buffer content into a readable string and returns the decoded result.
Output:
Example 2:
In this code, The StringDecoder object is used to decode data stored in buffers with different encodings. It converts hexadecimal, Base64, and byte-based buffer data into readable UTF-8 text and symbols.
Output:
Reference: https://nodejs.org/api/string_decoder.html#string_decoder_stringdecoder_write_buffer