2012-04-20 08:32:58 +02:00
|
|
|
# StringDecoder
|
|
|
|
|
2015-02-25 01:15:26 +01:00
|
|
|
Stability: 2 - Stable
|
2012-04-20 08:32:58 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
var StringDecoder = require('string_decoder').StringDecoder;
|
|
|
|
var decoder = new StringDecoder('utf8');
|
|
|
|
|
|
|
|
var cent = new Buffer([0xC2, 0xA2]);
|
|
|
|
console.log(decoder.write(cent));
|
|
|
|
|
|
|
|
var euro = new Buffer([0xE2, 0x82, 0xAC]);
|
|
|
|
console.log(decoder.write(euro));
|
|
|
|
|
|
|
|
## Class: StringDecoder
|
|
|
|
|
|
|
|
Accepts a single argument, `encoding` which defaults to `utf8`.
|
|
|
|
|
2012-10-12 00:53:11 +02:00
|
|
|
### decoder.write(buffer)
|
2012-04-20 08:32:58 +02:00
|
|
|
|
2012-10-12 00:53:11 +02:00
|
|
|
Returns a decoded string.
|
|
|
|
|
|
|
|
### decoder.end()
|
|
|
|
|
|
|
|
Returns any trailing bytes that were left in the buffer.
|