Created
June 29, 2021 15:54
-
-
Save s1r-J/9aad1fe82ab6892c1481ade1d31aa2c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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