root / trunk / web / dojo / dojox / encoding / ascii85.js @ 12
History | View | Annotate | Download (1.27 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.ascii85"]){ |
||
9 | dojo._hasResource["dojox.encoding.ascii85"]=true; |
||
10 | dojo.provide("dojox.encoding.ascii85");
|
||
11 | (function(){
|
||
12 | var c=function(_1,_2,_3){ |
||
13 | var i,j,n,b=[0,0,0,0,0]; |
||
14 | for(i=0;i<_2;i+=4){ |
||
15 | n=((_1[i]*256+_1[i+1])*256+_1[i+2])*256+_1[i+3]; |
||
16 | if(!n){
|
||
17 | _3.push("z");
|
||
18 | }else{
|
||
19 | for(j=0;j<5;b[j++]=n%85+33,n=Math.floor(n/85)){ |
||
20 | } |
||
21 | } |
||
22 | _3.push(String.fromCharCode(b[4],b[3],b[2],b[1],b[0])); |
||
23 | } |
||
24 | }; |
||
25 | dojox.encoding.ascii85.encode=function(_4){ |
||
26 | var _5=[],_6=_4.length%4,_7=_4.length-_6; |
||
27 | c(_4,_7,_5); |
||
28 | if(_6){
|
||
29 | var t=_4.slice(_7);
|
||
30 | while(t.length<4){ |
||
31 | t.push(0);
|
||
32 | } |
||
33 | c(t,4,_5);
|
||
34 | var x=_5.pop();
|
||
35 | if(x=="z"){ |
||
36 | x="!!!!!";
|
||
37 | } |
||
38 | _5.push(x.substr(0,_6+1)); |
||
39 | } |
||
40 | return _5.join(""); |
||
41 | }; |
||
42 | dojox.encoding.ascii85.decode=function(_8){ |
||
43 | var n=_8.length,r=[],b=[0,0,0,0,0],i,j,t,x,y,d; |
||
44 | for(i=0;i<n;++i){ |
||
45 | if(_8.charAt(i)=="z"){ |
||
46 | r.push(0,0,0,0); |
||
47 | continue;
|
||
48 | } |
||
49 | for(j=0;j<5;++j){ |
||
50 | b[j]=_8.charCodeAt(i+j)-33;
|
||
51 | } |
||
52 | d=n-i; |
||
53 | if(d<5){ |
||
54 | for(j=d;j<4;b[++j]=0){ |
||
55 | } |
||
56 | b[d]=85;
|
||
57 | } |
||
58 | t=(((b[0]*85+b[1])*85+b[2])*85+b[3])*85+b[4]; |
||
59 | x=t&255;
|
||
60 | t>>>=8;
|
||
61 | y=t&255;
|
||
62 | t>>>=8;
|
||
63 | r.push(t>>>8,t&255,y,x); |
||
64 | for(j=d;j<5;++j,r.pop()){ |
||
65 | } |
||
66 | i+=4;
|
||
67 | } |
||
68 | return r;
|
||
69 | }; |
||
70 | })(); |
||
71 | } |