Created
November 2, 2018 22:17
-
-
Save gabemeola/c32b80d9302b30b577118c39f98e00b2 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
/** | |
* Coverts a Javascript string to a | |
* unsigned 8 byte int ArrayBuffer | |
* | |
* @param {string} string - Binary String | |
* @returns {Uint8Array} | |
*/ | |
export default function stringToArrayBuffer(string) { | |
const { length } = string; | |
const buffer = new Uint8Array(length); | |
for (let i = 0; i < length; i++) { | |
// Get char code | |
buffer[i] = string.charCodeAt(i); | |
} | |
return buffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment