May 10, 2021 Node.js
稳定性: 3 - 稳定
The .js the Node string decoder (string_decoder) module
require('string_decoder')
Node .js a string decoder (string_decoder) to decode the cache (buffer) into strings.
This
buffer.toString()
and provides utc8 support.
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));
Accepts a parameter
encoding
the default is
utf8
Returns the decoded string.
Returns the remaining end bytes in the buffer.