buffer.toString()

buf.toString([encoding[, start[, end]]])

Decodes and returns a string from the Buffer data using the specified character set encoding.

const buf = Buffer.allocUnsafe(26);
for (var i = 0 ; i < 26 ; i++) {
  buf[i] = i + 97; // 97 is ASCII a
}
buf.toString('ascii');
  // Returns: 'abcdefghijklmnopqrstuvwxyz'
buf.toString('ascii',0,5);
  // Returns: 'abcde'
buf.toString('utf8',0,5);
  // Returns: 'abcde'
buf.toString(undefined,0,5);
  // Returns: 'abcde', encoding defaults to 'utf8'
doc_Nodejs
2016-04-30 04:37:44
Comments
Leave a Comment

Please login to continue.