Skip to content

Instantly share code, notes, and snippets.

@wang-bin
Created November 6, 2013 07:36
Show Gist options
  • Save wang-bin/7332335 to your computer and use it in GitHub Desktop.
Save wang-bin/7332335 to your computer and use it in GitHub Desktop.
js base64 to ArrayBuffer
decode64: function decodeBase64(en) {
var de = new Uint8Array(en.length); //3/4
var u = 0, q = '', x = '', c;
var map64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
for (var r=0; c=en[x++]; ~c&&(u=q%4?u*64+c:c,q++%4)?de[r++]=(255&u>>(-2*q&6)):0)
c = map64.indexOf(c);
var sub = de.subarray||de.subset||de.slice;
return sub.call(de, 0, r);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment