2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.encoding.ascii85"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.encoding.ascii85"] = true;
|
|
|
3 |
dojo.provide("dojox.encoding.ascii85");
|
|
|
4 |
|
|
|
5 |
(function(){
|
|
|
6 |
var c = function(input, length, result){
|
|
|
7 |
var i, j, n, b = [0, 0, 0, 0, 0];
|
|
|
8 |
for(i = 0; i < length; i += 4){
|
|
|
9 |
n = ((input[i] * 256 + input[i+1]) * 256 + input[i+2]) * 256 + input[i+3];
|
|
|
10 |
if(!n){
|
|
|
11 |
result.push("z");
|
|
|
12 |
}else{
|
|
|
13 |
for(j = 0; j < 5; b[j++] = n % 85 + 33, n = Math.floor(n / 85));
|
|
|
14 |
}
|
|
|
15 |
result.push(String.fromCharCode(b[4], b[3], b[2], b[1], b[0]));
|
|
|
16 |
}
|
|
|
17 |
};
|
|
|
18 |
|
|
|
19 |
dojox.encoding.ascii85.encode = function(input){
|
|
|
20 |
// summary: encodes input data in ascii85 string
|
|
|
21 |
// input: Array: an array of numbers (0-255) to encode
|
|
|
22 |
var result = [], reminder = input.length % 4, length = input.length - reminder;
|
|
|
23 |
c(input, length, result);
|
|
|
24 |
if(reminder){
|
|
|
25 |
var t = input.slice(length);
|
|
|
26 |
while(t.length < 4){ t.push(0); }
|
|
|
27 |
c(t, 4, result);
|
|
|
28 |
var x = result.pop();
|
|
|
29 |
if(x == "z"){ x = "!!!!!"; }
|
|
|
30 |
result.push(x.substr(0, reminder + 1));
|
|
|
31 |
}
|
|
|
32 |
return result.join(""); // String
|
|
|
33 |
};
|
|
|
34 |
|
|
|
35 |
dojox.encoding.ascii85.decode = function(input){
|
|
|
36 |
// summary: decodes the input string back to array of numbers
|
|
|
37 |
// input: String: the input string to decode
|
|
|
38 |
var n = input.length, r = [], b = [0, 0, 0, 0, 0], i, j, t, x, y, d;
|
|
|
39 |
for(i = 0; i < n; ++i){
|
|
|
40 |
if(input.charAt(i) == "z"){
|
|
|
41 |
r.push(0, 0, 0, 0);
|
|
|
42 |
continue;
|
|
|
43 |
}
|
|
|
44 |
for(j = 0; j < 5; ++j){ b[j] = input.charCodeAt(i + j) - 33; }
|
|
|
45 |
d = n - i;
|
|
|
46 |
if(d < 5){
|
|
|
47 |
for(j = d; j < 4; b[++j] = 0);
|
|
|
48 |
b[d] = 85;
|
|
|
49 |
}
|
|
|
50 |
t = (((b[0] * 85 + b[1]) * 85 + b[2]) * 85 + b[3]) * 85 + b[4];
|
|
|
51 |
x = t & 255;
|
|
|
52 |
t >>>= 8;
|
|
|
53 |
y = t & 255;
|
|
|
54 |
t >>>= 8;
|
|
|
55 |
r.push(t >>> 8, t & 255, y, x);
|
|
|
56 |
for(j = d; j < 5; ++j, r.pop());
|
|
|
57 |
i += 4;
|
|
|
58 |
}
|
|
|
59 |
return r;
|
|
|
60 |
};
|
|
|
61 |
})();
|
|
|
62 |
|
|
|
63 |
}
|