Node.js v4.9.1 Documentation

String Decoder#

Stability: 2 - Stable

To use this module, do require('string_decoder'). StringDecoder decodes a buffer to a string. It is a simple interface to buffer.toString() but provides additional support for utf8.

const StringDecoder = require('string_decoder').StringDecoder;
const decoder = new StringDecoder('utf8');

const cent = new Buffer([0xC2, 0xA2]);

const euro = new Buffer([0xE2, 0x82, 0xAC]);

Class: StringDecoder#

Accepts a single argument, encoding which defaults to 'utf8'.


Returns any trailing bytes that were left in the buffer.


Returns a decoded string.