Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / encoding / base64.js @ 12

History | View | Annotate | Download (1.36 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.encoding.base64"]){
9
dojo._hasResource["dojox.encoding.base64"]=true;
10
dojo.provide("dojox.encoding.base64");
11
(function(){
12
var p="=";
13
var _1="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
14
var _2=dojox.encoding;
15
_2.base64.encode=function(ba){
16
var s=[],l=ba.length;
17
var rm=l%3;
18
var x=l-rm;
19
for(var i=0;i<x;){
20
var t=ba[i++]<<16|ba[i++]<<8|ba[i++];
21
s.push(_1.charAt((t>>>18)&63));
22
s.push(_1.charAt((t>>>12)&63));
23
s.push(_1.charAt((t>>>6)&63));
24
s.push(_1.charAt(t&63));
25
}
26
switch(rm){
27
case 2:
28
var t=ba[i++]<<16|ba[i++]<<8;
29
s.push(_1.charAt((t>>>18)&63));
30
s.push(_1.charAt((t>>>12)&63));
31
s.push(_1.charAt((t>>>6)&63));
32
s.push(p);
33
break;
34
case 1:
35
var t=ba[i++]<<16;
36
s.push(_1.charAt((t>>>18)&63));
37
s.push(_1.charAt((t>>>12)&63));
38
s.push(p);
39
s.push(p);
40
break;
41
}
42
return s.join("");
43
};
44
_2.base64.decode=function(_3){
45
var s=_3.split(""),_4=[];
46
var l=s.length;
47
while(s[--l]==p){
48
}
49
for(var i=0;i<l;){
50
var t=_1.indexOf(s[i++])<<18;
51
if(i<=l){
52
t|=_1.indexOf(s[i++])<<12;
53
}
54
if(i<=l){
55
t|=_1.indexOf(s[i++])<<6;
56
}
57
if(i<=l){
58
t|=_1.indexOf(s[i++]);
59
}
60
_4.push((t>>>16)&255);
61
_4.push((t>>>8)&255);
62
_4.push(t&255);
63
}
64
while(_4[_4.length-1]==0){
65
_4.pop();
66
}
67
return _4;
68
};
69
})();
70
}