1 | /** |
||
2 | * ZLIB packer |
||
3 | * @see http://localhost/src/ZLIB.php |
||
4 | * @requires pako `npm i pako @types/pako` |
||
5 | */ |
||
6 | class ZLIB { |
||
7 | /** |
||
8 | * Base64 decode from php |
||
9 | * @param {Uint8Array} arr |
||
10 | */ |
||
11 | static atos(arr) { |
||
12 | for (var i = 0, l = arr.length, s = '', c; c = arr[i++];) |
||
13 | s += String.fromCharCode( |
||
14 | c > 0xdf && c < 0xf0 && i < l - 1 ? |
||
15 | (c & 0xf) << 12 | (arr[i++] & 0x3f) << 6 | arr[i++] & 0x3f : |
||
16 | c > 0x7f && i < l ? |
||
17 | (c & 0x1f) << 6 | arr[i++] & 0x3f : |
||
18 | c |
||
19 | ); |
||
20 | return s; |
||
21 | } |
||
22 | |||
23 | static decompress(str) { |
||
24 | var dec = this.atos(pako.ungzip(base64_decode(str))); |
||
25 | console.log({ |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
26 | 'ZLIB.decompress': { |
||
27 | target: str, |
||
28 | result: dec |
||
29 | } |
||
30 | }); |
||
31 | return dec; |
||
32 | } |
||
33 | |||
34 | static compress(str) { |
||
35 | var enc = pako.gzip(str, { |
||
36 | to: 'string' |
||
37 | }); |
||
38 | enc = base64_encode(enc); |
||
39 | console.log({ |
||
0 ignored issues
–
show
|
|||
40 | 'ZLIB.compress': { |
||
41 | target: str, |
||
42 | result: enc |
||
43 | } |
||
44 | }); |
||
45 | return enc; |
||
46 | } |
||
47 | } |