StringDecoder Node.js v4.2.6 Manual & Documentation

Node.js (1)

- About these Docs
- Synopsis
- Assertion Testing
- Buffer
- C/C++ Addons
- Child Processes
- Cluster
- Console
- Crypto
- Debugger
- DNS
- Domain
- Errors
- Events
- File System
- Globals
- HTTP
- HTTPS
- Modules
- Net
- OS
- Path
- Process
- Punycode
- Query Strings
- Readline
- REPL
- Stream
- String Decoder
- Timers
- TLS/SSL
- TTY
- UDP/Datagram
- URL
- Utilities
- V8
- VM
- ZLIB

# StringDecoder#

    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]);
    console.log(decoder.write(cent));

    const euro = new Buffer([0xE2, 0x82, 0xAC]);
    console.log(decoder.write(euro));

## Class: StringDecoder#

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

### decoder.end()#

Returns any trailing bytes that were left in the buffer.

### decoder.write(buffer)#

Returns a decoded string.