Mercurial > web-gnusto
diff base64.js @ 27:174a19e03273
z5 js files are now encoded using base64, which makes them much smaller.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 12 May 2008 00:45:00 -0700 |
parents | |
children | 5c35e18a9d1a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base64.js Mon May 12 00:45:00 2008 -0700 @@ -0,0 +1,27 @@ +/* Taken from: + * + * http://ecmanaut.blogspot.com/2007/11/javascript-base64-singleton.html + * + * With minor modifications to decode a b64 string to a byte array instead + * of a string. */ + +var base64_tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + +function decode_base64(data) { + var out = [], c1, c2, c3, e1, e2, e3, e4; + for (var i = 0; i < data.length; ) { + e1 = base64_tab.indexOf(data.charAt(i++)); + e2 = base64_tab.indexOf(data.charAt(i++)); + e3 = base64_tab.indexOf(data.charAt(i++)); + e4 = base64_tab.indexOf(data.charAt(i++)); + c1 = (e1 << 2) + (e2 >> 4); + c2 = ((e2 & 15) << 4) + (e3 >> 2); + c3 = ((e3 & 3) << 6) + e4; + out.push(c1); + if (e3 != 64) + out.push(c2); + if (e4 != 64) + out.push(c3); + } + return out; +}