2 Copyright (c) 2013, Specialisterne.
3 http://specialisterne.com/dk/
6 Jacob Christian Munch-Andersen
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 // For information and latest version see: https://github.com/Jacob-Christian-Munch-Andersen/Easy-Deflate
32 function UTF8encode(str
){
36 for(a
=0;a
<str
.length
;a
++){
42 out
.push((c
>> 6)+192);
43 out
.push((c
& 63)+128);
46 if(c
>=0xD800 && c
<0xDC00){
52 if(c2
>=0xDC00 && c2
<0xE000){
53 c
=65536+(c
-0xD800)*1024+c2
-0xDC00;
54 out
.push((c
>> 18)+240);
55 out
.push(((c
>> 12) & 63)+128);
56 out
.push(((c
>> 6) & 63)+128);
57 out
.push((c
& 63)+128);
63 else if(c
>=0xDC00 && c
<0xE000){
67 out
.push((c
>> 12)+224);
68 out
.push(((c
>> 6) & 63)+128);
69 out
.push((c
& 63)+128);
76 return new Uint8Array(out
);
78 function UTF8decodeA(arrarr
){
87 for(a
=0;a
<arrarr
.length
;a
++){
89 for(b
=0;b
<arr
.length
;b
++){
93 intermediate
=intermediate
*64+c
-128;
96 if(intermediate
>=minvalue
){
97 if(intermediate
>=65536){
98 if(intermediate
>0x10FFFF){
101 upper
=(intermediate
-65536)>>10;
102 lower
=intermediate
%1024;
103 result
+=String
.fromCharCode(upper
+0xD800,lower
+0xDC00);
106 result
+=String
.fromCharCode(intermediate
);
119 result
+=String
.fromCharCode(c
);
121 else if(c
>191 && c
<248){
148 function deflate(str
){
154 var zipper
=new zip
.Deflater(9);
155 for(a
=0;a
<str
.length
;a
+=readlen
){
156 d
=UTF8encode(str
.substr(a
,readlen
));
157 if(d
===null){ //This error may be due to a 4 byte charachter being split, retry with a string that is 1 longer to fix it.
158 d
=UTF8encode(str
.substr(a
,readlen
+1));
173 for(a
=0;a
<resulta
.length
;a
++){
174 for(c
=0;c
<resulta
[a
].length
;c
++){
175 results
+=String
.fromCharCode(resulta
[a
][c
]);
178 return "rawdeflate,"+btoa(results
);
180 function inflate(dfl
){
181 var unzipper
=new zip
.Inflater();
186 if(dfl
.slice(0,11)!="rawdeflate,"){
190 dfls
=atob(dfl
.slice(11));
196 for(a
=0;a
<dfls
.length
;a
+=50000){
197 b
=new Uint8Array(Math
.min(50000,dfls
.length
-a
));
198 for(c
=0;c
<b
.length
;c
++){
199 b
[c
]=dfls
.charCodeAt(c
+a
);
201 d
=unzipper
.append(b
);
206 return UTF8decodeA(resulta
);
213 window
.EasyDeflate
= {