Created
April 24, 2023 10:46
-
-
Save alekstar79/6b16750a9ed835553edeb56b2a7393ed to your computer and use it in GitHub Desktop.
Convert String to ArrayBuffer
This file contains 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
export function str2ab(str) | |
{ | |
let buf = new ArrayBuffer(str.length * 2) // 2 bytes for each char | |
let bufView = new Uint16Array(buf) | |
for (let i = 0, strLen = str.length; i < strLen; 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