Base64.js
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
function encode(s) { | |
var c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", | |
o = []; | |
for (var i = 0, n = s.length; i < n;) { | |
var c1 = s.charCodeAt(i++), | |
c2 = s.charCodeAt(i++), | |
c3 = s.charCodeAt(i++); | |
o.push(c.charAt(c1 >> 2)); | |
o.push(c.charAt(((c1 & 3) << 4) | (c2 >> 4))); | |
o.push(c.charAt(i < n + 2 ? ((c2 & 15) << 2) | (c3 >> 6) : 64)); | |
o.push(c.charAt(i < n + 1 ? c3 & 63 : 64)); | |
} | |
return o.join(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that some browsers support the built-in functions
atob
andbtoa
for decoding and encoding, respectively.