Node.js Buffer toString() convert buffer to string by various encoding

Description

Node.js Buffer toString() convert buffer to string by various encoding

var buffer = new Buffer.alloc(26);
for (var i = 0; i < 26; i++) {
    buffer[i] = i + 97//from w  w  w . ja  v  a 2s.com
}
console.log(buffer.toString('ascii'));
console.log(buffer.toString('ascii', 0, 5));
console.log(buffer.toString('utf8'));
console.log(buffer.toString(undefined,0,5));



PreviousNext

Related