/** * little arrays (>=100k characters), otherwise you'll get exceptions as RangeError : Maximum call * stack size exceeded or Out of stack space. * @returns {string} */ functionuint8arrayToStringMethod(myUint8Arr){ returnString.fromCharCode.apply(null, myUint8Arr); }
/** * Converts an array buffer to a string * * @param {Uin8} uint8arr | The buffer to convert * @param {Function} callback | The function to call when conversion is complete */ functionlargeuint8ArrToString(uint8arr, callback) { var bb = new Blob([uint8arr]); var f = new FileReader(); f.onload = function(e) { callback(e.target.result); }; f.readAsText(bb); }
// Usage example // "Hello" in Uint8Array format var myuint8Arr = newUint8Array([72, 101, 108, 108, 111, 32, 33]);