1 if(!dojo._hasResource["dojox.encoding.base64"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.encoding.base64"] = true;
3 dojo.provide("dojox.encoding.base64");
7 var tab="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
8 var dxe=dojox.encoding;
10 dxe.base64.encode=function(/* byte[] */ba){
12 // Encode an array of bytes as a base64-encoded string
13 var s=[], l=ba.length;
17 var t=ba[i++]<<16|ba[i++]<<8|ba[i++];
18 s.push(tab.charAt((t>>>18)&0x3f));
19 s.push(tab.charAt((t>>>12)&0x3f));
20 s.push(tab.charAt((t>>>6)&0x3f));
21 s.push(tab.charAt(t&0x3f));
23 // deal with trailers, based on patch from Peter Wood.
26 var t=ba[i++]<<16|ba[i++]<<8;
27 s.push(tab.charAt((t>>>18)&0x3f));
28 s.push(tab.charAt((t>>>12)&0x3f));
29 s.push(tab.charAt((t>>>6)&0x3f));
35 s.push(tab.charAt((t>>>18)&0x3f));
36 s.push(tab.charAt((t>>>12)&0x3f));
42 return s.join(""); // string
45 dxe.base64.decode=function(/* string */str){
47 // Convert a base64-encoded string to an array of bytes
48 var s=str.split(""), out=[];
50 while(s[--l]==p){ } // strip off trailing padding
52 var t=tab.indexOf(s[i++])<<18;
53 if(i<=l){ t|=tab.indexOf(s[i++])<<12 };
54 if(i<=l){ t|=tab.indexOf(s[i++])<<6 };
55 if(i<=l){ t|=tab.indexOf(s[i++]) };
56 out.push((t>>>16)&0xff);
57 out.push((t>>>8)&0xff);
60 // strip off any null bytes
61 while(out[out.length-1]==0){ out.pop(); }