mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 17:03:34 +00:00

PR-URL: https://github.com/nodejs/node/pull/6741 Ref: https://github.com/nodejs/node/issues/6578 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
812 B
812 B
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 = Buffer.from([0xC2, 0xA2]);
console.log(decoder.write(cent));
const euro = Buffer.from([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.