Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

typedarray.js not work fine #148

Open
malacca opened this issue Jun 15, 2018 · 0 comments
Open

typedarray.js not work fine #148

malacca opened this issue Jun 15, 2018 · 0 comments

Comments

@malacca
Copy link

malacca commented Jun 15, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant