Last active
August 29, 2015 14:00
-
-
Save vukicevic/24bd85175fba4a07c12d to your computer and use it in GitHub Desktop.
Base64 encode/eecode byte array
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
/* | |
* Input: Base64 encoded string | |
* Output: Raw byte-array | |
*/ | |
function decodeStringToArray(s) { | |
return Array.prototype.map.call(atob(s), function(c) { return c.charCodeAt() }); | |
} | |
/* | |
* Input: Raw byte-array | |
* Output: Base64 encoded string | |
*/ | |
function encodeArrayToString(a) { | |
return btoa(String.fromCharCode.apply(null, a)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment