Skip to content

Instantly share code, notes, and snippets.

@vukicevic
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vukicevic/24bd85175fba4a07c12d to your computer and use it in GitHub Desktop.
Save vukicevic/24bd85175fba4a07c12d to your computer and use it in GitHub Desktop.
Base64 encode/eecode byte array
/*
* 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