polyfill icon indicating copy to clipboard operation
polyfill copied to clipboard

typedarray.js not work fine

Open malacca opened this issue 6 years ago • 0 comments

i try this function
https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String

function ab2str(buf) {
  return String.fromCharCode.apply(null, new Uint16Array(buf));
}
function str2ab(str) {
  var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
  var bufView = new Uint16Array(buf);
  for (var i=0, strLen=str.length; i < strLen; i++) {
    bufView[i] = str.charCodeAt(i);
  }
  return buf;
}

when use str2ab, the return [ArrayBuffer] is not right

malacca avatar Jun 15 '18 09:06 malacca