root / trunk / web / dojo / dojox / encoding / easy64.js
History | View | Annotate | Download (1.1 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.easy64"]){ |
||
9 | dojo._hasResource["dojox.encoding.easy64"]=true; |
||
10 | dojo.provide("dojox.encoding.easy64");
|
||
11 | (function(){
|
||
12 | var c=function(_1,_2,_3){ |
||
13 | for(var i=0;i<_2;i+=3){ |
||
14 | _3.push(String.fromCharCode((_1[i]>>>2)+33),String.fromCharCode(((_1[i]&3)<<4)+(_1[i+1]>>>4)+33),String.fromCharCode(((_1[i+1]&15)<<2)+(_1[i+2]>>>6)+33),String.fromCharCode((_1[i+2]&63)+33)); |
||
15 | } |
||
16 | }; |
||
17 | dojox.encoding.easy64.encode=function(_4){ |
||
18 | var _5=[],_6=_4.length%3,_7=_4.length-_6; |
||
19 | c(_4,_7,_5); |
||
20 | if(_6){
|
||
21 | var t=_4.slice(_7);
|
||
22 | while(t.length<3){ |
||
23 | t.push(0);
|
||
24 | } |
||
25 | c(t,3,_5);
|
||
26 | for(var i=3;i>_6;_5.pop(),--i){ |
||
27 | } |
||
28 | } |
||
29 | return _5.join(""); |
||
30 | }; |
||
31 | dojox.encoding.easy64.decode=function(_8){ |
||
32 | var n=_8.length,r=[],b=[0,0,0,0],i,j,d; |
||
33 | for(i=0;i<n;i+=4){ |
||
34 | for(j=0;j<4;++j){ |
||
35 | b[j]=_8.charCodeAt(i+j)-33;
|
||
36 | } |
||
37 | d=n-i; |
||
38 | for(j=d;j<4;b[++j]=0){ |
||
39 | } |
||
40 | r.push((b[0]<<2)+(b[1]>>>4),((b[1]&15)<<4)+(b[2]>>>2),((b[2]&3)<<6)+b[3]); |
||
41 | for(j=d;j<4;++j,r.pop()){ |
||
42 | } |
||
43 | } |
||
44 | return r;
|
||
45 | }; |
||
46 | })(); |
||
47 | } |