Skip to content

Instantly share code, notes, and snippets.

@s1r-J
Created June 29, 2021 15:54
Show Gist options
  • Save s1r-J/9aad1fe82ab6892c1481ade1d31aa2c4 to your computer and use it in GitHub Desktop.
Save s1r-J/9aad1fe82ab6892c1481ade1d31aa2c4 to your computer and use it in GitHub Desktop.
function ab2str(ab) {
return String.fromCharCode.apply(null, new Uint16Array(ab));
}
function str2ab(str) {
const buf = new ArrayBuffer(str.length * 2);
const bufView = new Uint16Array(buf);
for (let i = 0; i < str.length; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment