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