Last active
August 16, 2021 12:42
-
-
Save s1r-J/38ed191cc0ed12ea49e16fa9f9732836 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 arraybuffer2str(ab) { | |
return String.fromCharCode.apply(null, new Uint16Array(buf)); | |
} | |
function str2arraybuffer(str) { | |
let buf = new ArrayBuffer(str.length * 2); | |
let 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