Turns a buffer object into a string. - Node.js Data Type

Node.js examples for Data Type:Uint8Array

Description

Turns a buffer object into a string.

Demo Code

/**//from  w  ww. j av  a2 s.com
 * turns a buffer object into a string. 
 * 
 * @param buffer
 * @returns {String}
 */
String.fromBuffer = function(buffer){
  var string = "";
  
  var ibuff = new Uint8Array(buffer);
  for(var i = 0; i < ibuff.length; i++){
    string += String.fromCharCode(ibuff[i]);
  }
  
  return string;
};

Related Tutorials