|
8 | 8 | //
|
9 | 9 | // LZ-based compression algorithm, version 1.4.4
|
10 | 10 |
|
11 |
| -// If other compressions are needed, uncomment and add tests from https://github.com/pieroxy/lz-string/blob/master/tests/lz-string-spec.js |
| 11 | +// If other compressions are needed pull from https://github.com/pieroxy/lz-string (bring tests across also) |
12 | 12 |
|
13 | 13 | // Note also the esm port of lz-string for utf-8 only by @immutabl3/lz-string
|
14 | 14 |
|
15 | 15 | const f = String.fromCharCode
|
16 |
| -// const keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; |
17 | 16 | const keyStrUriSafe = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$'
|
18 | 17 | const baseReverseDic = {}
|
19 | 18 |
|
@@ -45,70 +44,6 @@ function getBaseValue(alphabet: string, character: string) {
|
45 | 44 | return baseReverseDic[alphabet][character]
|
46 | 45 | }
|
47 | 46 |
|
48 |
| -// export function compressToBase64(input) { |
49 |
| -// if (input == null) return ""; |
50 |
| -// var res = _compress(input, 6, function (a) { return keyStrBase64.charAt(a); }); |
51 |
| -// switch (res.length % 4) { // To produce valid Base64 |
52 |
| -// default: // When could this happen ? |
53 |
| -// case 0: return res; |
54 |
| -// case 1: return res + "==="; |
55 |
| -// case 2: return res + "=="; |
56 |
| -// case 3: return res + "="; |
57 |
| -// } |
58 |
| -// } |
59 |
| - |
60 |
| -// export function decompressFromBase64(input) { |
61 |
| -// if (input == null) return ""; |
62 |
| -// if (input == "") return null; |
63 |
| -// return _decompress(input.length, 32, function (index) { return getBaseValue(keyStrBase64, input.charAt(index)); }); |
64 |
| -// } |
65 |
| - |
66 |
| -// export function compressToUTF16(input) { |
67 |
| -// if (input == null) return ""; |
68 |
| -// return _compress(input, 15, function (a) { return f(a + 32); }) + " "; |
69 |
| -// } |
70 |
| - |
71 |
| -// export function decompressFromUTF16(compressed) { |
72 |
| -// if (compressed == null) return ""; |
73 |
| -// if (compressed == "") return null; |
74 |
| -// return _decompress(compressed.length, 16384, function (index) { return compressed.charCodeAt(index) - 32; }); |
75 |
| -// } |
76 |
| - |
77 |
| -// compress into uint8array (UCS-2 big endian format) |
78 |
| -// export function compressToUint8Array(uncompressed) { |
79 |
| -// var compressed = compress(uncompressed); |
80 |
| -// var buf = new Uint8Array(compressed.length * 2); // 2 bytes per character |
81 |
| - |
82 |
| -// for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) { |
83 |
| -// var current_value = compressed.charCodeAt(i); |
84 |
| -// buf[i * 2] = current_value >>> 8; |
85 |
| -// buf[i * 2 + 1] = current_value % 256; |
86 |
| -// } |
87 |
| -// return buf; |
88 |
| -// } |
89 |
| - |
90 |
| -// decompress from uint8array (UCS-2 big endian format) |
91 |
| -// export function decompressFromUint8Array(compressed) { |
92 |
| -// if (compressed === null || compressed === undefined) { |
93 |
| -// return decompress(compressed); |
94 |
| -// } else { |
95 |
| -// var buf = new Array(compressed.length / 2); // 2 bytes per character |
96 |
| -// for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) { |
97 |
| -// buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1]; |
98 |
| -// } |
99 |
| - |
100 |
| -// var result = []; |
101 |
| -// buf.forEach(function (c) { |
102 |
| -// result.push(f(c)); |
103 |
| -// }); |
104 |
| -// return decompress(result.join('')); |
105 |
| -// } |
106 |
| -// } |
107 |
| - |
108 |
| -// function compress(uncompressed) { |
109 |
| -// return _compress(uncompressed, 16, function (a) { return f(a); }); |
110 |
| -// } |
111 |
| - |
112 | 47 | function _compress(uncompressed: string, bitsPerChar: number, getCharFromInt: (index: number) => any) {
|
113 | 48 | if (uncompressed == null)
|
114 | 49 | return ''
|
@@ -341,12 +276,6 @@ function _compress(uncompressed: string, bitsPerChar: number, getCharFromInt: (i
|
341 | 276 | return context_data.join('')
|
342 | 277 | }
|
343 | 278 |
|
344 |
| -// function decompress(compressed) { |
345 |
| -// if (compressed == null) return ""; |
346 |
| -// if (compressed == "") return null; |
347 |
| -// return _decompress(compressed.length, 32768, function (index) { return compressed.charCodeAt(index); }); |
348 |
| -// } |
349 |
| - |
350 | 279 | function _decompress(length: number, resetValue: number, getNextValue: (index: number) => any) {
|
351 | 280 | const dictionary = []
|
352 | 281 | const result = []
|
|
0 commit comments