Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.39 KB | None | 0 0
  1. var LZString = {
  2. _f: String.fromCharCode,
  3. _keyStrBase64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  4. _keyStrUriSafe: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",
  5. _getBaseValue: function(a, b) {
  6. if (LZString._baseReverseDic || (LZString._baseReverseDic = {}), !LZString._baseReverseDic[a]) {
  7. LZString._baseReverseDic[a] = {};
  8. for (var c = 0; c < a.length; c++) LZString._baseReverseDic[a][a[c]] = c;
  9. }
  10. return LZString._baseReverseDic[a][b];
  11. },
  12. compressToBase64: function(a) {
  13. if (null == a) return "";
  14. var b = LZString._compress(a, 6, function(a) {
  15. return LZString._keyStrBase64.charAt(a);
  16. });
  17. switch (b.length % 4) {
  18. default:
  19. case 0:
  20. return b;
  21.  
  22. case 1:
  23. return b + "===";
  24.  
  25. case 2:
  26. return b + "==";
  27.  
  28. case 3:
  29. return b + "=";
  30. }
  31. },
  32. decompressFromBase64: function(a) {
  33. return null == a ? "" : "" == a ? null : LZString._decompress(a.length, 32, function(b) {
  34. return LZString._getBaseValue(LZString._keyStrBase64, a.charAt(b));
  35. });
  36. },
  37. compressToUTF16: function(a) {
  38. return null == a ? "" : LZString._compress(a, 15, function(a) {
  39. return String.fromCharCode(a + 32);
  40. }) + " ";
  41. },
  42. decompressFromUTF16: function(a) {
  43. return null == a ? "" : "" == a ? null : LZString._decompress(a.length, 16384, function(b) {
  44. return a.charCodeAt(b) - 32;
  45. });
  46. },
  47. compressToUint8Array: function(a) {
  48. for (var b = LZString.compress(a), c = new Uint8Array(2 * b.length), d = 0, e = b.length; e > d; d++) {
  49. var f = b.charCodeAt(d);
  50. c[2 * d] = f >>> 8, c[2 * d + 1] = f % 256;
  51. }
  52. return c;
  53. },
  54. decompressFromUint8Array: function(a) {
  55. if (null === a || void 0 === a) return LZString.decompress(a);
  56. for (var b = new Array(a.length / 2), c = 0, d = b.length; d > c; c++) b[c] = 256 * a[2 * c] + a[2 * c + 1];
  57. var e = [];
  58. return b.forEach(function(a) {
  59. e.push(String.fromCharCode(a));
  60. }), LZString.decompress(e.join(""));
  61. },
  62. compressToEncodedURIComponent: function(a) {
  63. return null == a ? "" : LZString._compress(a, 6, function(a) {
  64. return LZString._keyStrUriSafe.charAt(a);
  65. });
  66. },
  67. decompressFromEncodedURIComponent: function(a) {
  68. return null == a ? "" : "" == a ? null : (a = a.replace(/ /g, "+"), LZString._decompress(a.length, 32, function(b) {
  69. return LZString._getBaseValue(LZString._keyStrUriSafe, a.charAt(b));
  70. }));
  71. },
  72. compress: function(a) {
  73. return LZString._compress(a, 16, function(a) {
  74. return String.fromCharCode(a);
  75. });
  76. },
  77. _compress: function(a, b, c) {
  78. if (null == a) return "";
  79. var d, e, f, g = {}, h = {}, i = "", j = "", k = "", l = 2, m = 3, n = 2, o = [], p = 0, q = 0;
  80. LZString._f;
  81. for (f = 0; f < a.length; f += 1) if (i = a[f], Object.prototype.hasOwnProperty.call(g, i) || (g[i] = m++,
  82. h[i] = !0), j = k + i, Object.prototype.hasOwnProperty.call(g, j)) k = j; else {
  83. if (Object.prototype.hasOwnProperty.call(h, k)) {
  84. if (k.charCodeAt(0) < 256) {
  85. for (d = 0; n > d; d++) p <<= 1, q == b - 1 ? (q = 0, o.push(c(p)), p = 0) : q++;
  86. for (e = k.charCodeAt(0), d = 0; 8 > d; d++) p = p << 1 | 1 & e, q == b - 1 ? (q = 0,
  87. o.push(c(p)), p = 0) : q++, e >>= 1;
  88. } else {
  89. for (e = 1, d = 0; n > d; d++) p = p << 1 | e, q == b - 1 ? (q = 0, o.push(c(p)),
  90. p = 0) : q++, e = 0;
  91. for (e = k.charCodeAt(0), d = 0; 16 > d; d++) p = p << 1 | 1 & e, q == b - 1 ? (q = 0,
  92. o.push(c(p)), p = 0) : q++, e >>= 1;
  93. }
  94. l--, 0 == l && (l = Math.pow(2, n), n++), delete h[k];
  95. } else for (e = g[k], d = 0; n > d; d++) p = p << 1 | 1 & e, q == b - 1 ? (q = 0,
  96. o.push(c(p)), p = 0) : q++, e >>= 1;
  97. l--, 0 == l && (l = Math.pow(2, n), n++), g[j] = m++, k = String(i);
  98. }
  99. if ("" !== k) {
  100. if (Object.prototype.hasOwnProperty.call(h, k)) {
  101. if (k.charCodeAt(0) < 256) {
  102. for (d = 0; n > d; d++) p <<= 1, q == b - 1 ? (q = 0, o.push(c(p)), p = 0) : q++;
  103. for (e = k.charCodeAt(0), d = 0; 8 > d; d++) p = p << 1 | 1 & e, q == b - 1 ? (q = 0,
  104. o.push(c(p)), p = 0) : q++, e >>= 1;
  105. } else {
  106. for (e = 1, d = 0; n > d; d++) p = p << 1 | e, q == b - 1 ? (q = 0, o.push(c(p)),
  107. p = 0) : q++, e = 0;
  108. for (e = k.charCodeAt(0), d = 0; 16 > d; d++) p = p << 1 | 1 & e, q == b - 1 ? (q = 0,
  109. o.push(c(p)), p = 0) : q++, e >>= 1;
  110. }
  111. l--, 0 == l && (l = Math.pow(2, n), n++), delete h[k];
  112. } else for (e = g[k], d = 0; n > d; d++) p = p << 1 | 1 & e, q == b - 1 ? (q = 0,
  113. o.push(c(p)), p = 0) : q++, e >>= 1;
  114. l--, 0 == l && (l = Math.pow(2, n), n++);
  115. }
  116. for (e = 2, d = 0; n > d; d++) p = p << 1 | 1 & e, q == b - 1 ? (q = 0, o.push(c(p)),
  117. p = 0) : q++, e >>= 1;
  118. for (;;) {
  119. if (p <<= 1, q == b - 1) {
  120. o.push(c(p));
  121. break;
  122. }
  123. q++;
  124. }
  125. return o.join("");
  126. },
  127. decompress: function(a) {
  128. return null == a ? "" : "" == a ? null : LZString._decompress(a.length, 32768, function(b) {
  129. return a.charCodeAt(b);
  130. });
  131. },
  132. _decompress: function(a, b, c) {
  133. var d, e, f, g, h, i, j, k, l = [], m = 4, n = 4, o = 3, p = "", q = [], r = LZString._f, s = {
  134. val: c(0),
  135. position: b,
  136. index: 1
  137. };
  138. for (e = 0; 3 > e; e += 1) l[e] = e;
  139. for (g = 0, i = Math.pow(2, 2), j = 1; j != i; ) h = s.val & s.position, s.position >>= 1,
  140. 0 == s.position && (s.position = b, s.val = c(s.index++)), g |= (h > 0 ? 1 : 0) * j,
  141. j <<= 1;
  142. switch (d = g) {
  143. case 0:
  144. for (g = 0, i = Math.pow(2, 8), j = 1; j != i; ) h = s.val & s.position, s.position >>= 1,
  145. 0 == s.position && (s.position = b, s.val = c(s.index++)), g |= (h > 0 ? 1 : 0) * j,
  146. j <<= 1;
  147. k = r(g);
  148. break;
  149.  
  150. case 1:
  151. for (g = 0, i = Math.pow(2, 16), j = 1; j != i; ) h = s.val & s.position, s.position >>= 1,
  152. 0 == s.position && (s.position = b, s.val = c(s.index++)), g |= (h > 0 ? 1 : 0) * j,
  153. j <<= 1;
  154. k = r(g);
  155. break;
  156.  
  157. case 2:
  158. return "";
  159. }
  160. for (l[3] = k, f = k, q.push(k); ;) {
  161. if (s.index > a) return "";
  162. for (g = 0, i = Math.pow(2, o), j = 1; j != i; ) h = s.val & s.position, s.position >>= 1,
  163. 0 == s.position && (s.position = b, s.val = c(s.index++)), g |= (h > 0 ? 1 : 0) * j,
  164. j <<= 1;
  165. switch (k = g) {
  166. case 0:
  167. for (g = 0, i = Math.pow(2, 8), j = 1; j != i; ) h = s.val & s.position, s.position >>= 1,
  168. 0 == s.position && (s.position = b, s.val = c(s.index++)), g |= (h > 0 ? 1 : 0) * j,
  169. j <<= 1;
  170. l[n++] = r(g), k = n - 1, m--;
  171. break;
  172.  
  173. case 1:
  174. for (g = 0, i = Math.pow(2, 16), j = 1; j != i; ) h = s.val & s.position, s.position >>= 1,
  175. 0 == s.position && (s.position = b, s.val = c(s.index++)), g |= (h > 0 ? 1 : 0) * j,
  176. j <<= 1;
  177. l[n++] = r(g), k = n - 1, m--;
  178. break;
  179.  
  180. case 2:
  181. return q.join("");
  182. }
  183. if (0 == m && (m = Math.pow(2, o), o++), l[k]) p = l[k]; else {
  184. if (k !== n) return null;
  185. p = f + f[0];
  186. }
  187. q.push(p), l[n++] = f + p[0], m--, f = p, 0 == m && (m = Math.pow(2, o), o++);
  188. }
  189. }
  190. };
  191.  
  192. "undefined" != typeof module && null != module && (module.exports = LZString);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement