inflate.min.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */
  2. export function createZlib() {
  3. var objZlib = {};
  4. var l = void 0,
  5. aa = objZlib;
  6. function r(c, d) {
  7. var a = c.split("."), //a:[Zlib,Inflate]
  8. b = aa; //b:this
  9. //!(a[0] in b) && b.execScript && b.execScript("var " + a[0]);
  10. for (var e; a.length && (e = a.shift());) !a.length && d !== l ? b[e] = d : b = b[e] ? b[e] : b[e] = {}
  11. Object.assign(objZlib, b);
  12. };
  13. var t = "undefined" !== typeof Uint8Array && "undefined" !== typeof Uint16Array && "undefined" !== typeof Uint32Array && "undefined" !== typeof DataView;
  14. function v(c) {
  15. var d = c.length,
  16. a = 0,
  17. b = Number.POSITIVE_INFINITY,
  18. e, f, g, h, k, m, n, p, s, x;
  19. for (p = 0; p < d; ++p) c[p] > a && (a = c[p]), c[p] < b && (b = c[p]);
  20. e = 1 << a;
  21. f = new(t ? Uint32Array : Array)(e);
  22. g = 1;
  23. h = 0;
  24. for (k = 2; g <= a;) {
  25. for (p = 0; p < d; ++p)
  26. if (c[p] === g) {
  27. m = 0;
  28. n = h;
  29. for (s = 0; s < g; ++s) m = m << 1 | n & 1, n >>= 1;
  30. x = g << 16 | p;
  31. for (s = m; s < e; s += k) f[s] = x;
  32. ++h
  33. }++ g;
  34. h <<= 1;
  35. k <<= 1
  36. }
  37. return [f, a, b]
  38. };
  39. function w(c, d) {
  40. this.g = [];
  41. this.h = 32768;
  42. this.d = this.f = this.a = this.l = 0;
  43. this.input = t ? new Uint8Array(c) : c;
  44. this.m = !1;
  45. this.i = y;
  46. this.r = !1;
  47. if (d || !(d = {})) d.index && (this.a = d.index), d.bufferSize && (this.h = d.bufferSize), d.bufferType && (this.i = d.bufferType), d.resize && (this.r = d.resize);
  48. switch (this.i) {
  49. case A:
  50. this.b = 32768;
  51. this.c = new(t ? Uint8Array : Array)(32768 + this.h + 258);
  52. break;
  53. case y:
  54. this.b = 0;
  55. this.c = new(t ? Uint8Array : Array)(this.h);
  56. this.e = this.z;
  57. this.n = this.v;
  58. this.j = this.w;
  59. break;
  60. default:
  61. throw Error("invalid inflate mode");
  62. }
  63. }
  64. var A = 0,
  65. y = 1,
  66. B = {
  67. t: A,
  68. s: y
  69. };
  70. w.prototype.k = function () {
  71. for (; !this.m;) {
  72. var c = C(this, 3);
  73. c & 1 && (this.m = !0);
  74. c >>>= 1;
  75. switch (c) {
  76. case 0:
  77. var d = this.input,
  78. a = this.a,
  79. b = this.c,
  80. e = this.b,
  81. f = d.length,
  82. g = l,
  83. h = l,
  84. k = b.length,
  85. m = l;
  86. this.d = this.f = 0;
  87. if (a + 1 >= f) throw Error("invalid uncompressed block header: LEN");
  88. g = d[a++] | d[a++] << 8;
  89. if (a + 1 >= f) throw Error("invalid uncompressed block header: NLEN");
  90. h = d[a++] | d[a++] << 8;
  91. if (g === ~h) throw Error("invalid uncompressed block header: length verify");
  92. if (a + g > d.length) throw Error("input buffer is broken");
  93. switch (this.i) {
  94. case A:
  95. for (; e +
  96. g > b.length;) {
  97. m = k - e;
  98. g -= m;
  99. if (t) b.set(d.subarray(a, a + m), e), e += m, a += m;
  100. else
  101. for (; m--;) b[e++] = d[a++];
  102. this.b = e;
  103. b = this.e();
  104. e = this.b
  105. }
  106. break;
  107. case y:
  108. for (; e + g > b.length;) b = this.e({
  109. p: 2
  110. });
  111. break;
  112. default:
  113. throw Error("invalid inflate mode");
  114. }
  115. if (t) b.set(d.subarray(a, a + g), e), e += g, a += g;
  116. else
  117. for (; g--;) b[e++] = d[a++];
  118. this.a = a;
  119. this.b = e;
  120. this.c = b;
  121. break;
  122. case 1:
  123. this.j(ba, ca);
  124. break;
  125. case 2:
  126. for (var n = C(this, 5) + 257, p = C(this, 5) + 1, s = C(this, 4) + 4, x = new(t ? Uint8Array : Array)(D.length), S = l, T = l, U = l, u = l, M = l, F = l, z = l, q = l, V = l, q = 0; q < s; ++q) x[D[q]] =
  127. C(this, 3);
  128. if (!t) {
  129. q = s;
  130. for (s = x.length; q < s; ++q) x[D[q]] = 0
  131. }
  132. S = v(x);
  133. u = new(t ? Uint8Array : Array)(n + p);
  134. q = 0;
  135. for (V = n + p; q < V;) switch (M = E(this, S), M) {
  136. case 16:
  137. for (z = 3 + C(this, 2); z--;) u[q++] = F;
  138. break;
  139. case 17:
  140. for (z = 3 + C(this, 3); z--;) u[q++] = 0;
  141. F = 0;
  142. break;
  143. case 18:
  144. for (z = 11 + C(this, 7); z--;) u[q++] = 0;
  145. F = 0;
  146. break;
  147. default:
  148. F = u[q++] = M
  149. }
  150. T = t ? v(u.subarray(0, n)) : v(u.slice(0, n));
  151. U = t ? v(u.subarray(n)) : v(u.slice(n));
  152. this.j(T, U);
  153. break;
  154. default:
  155. throw Error("unknown BTYPE: " + c);
  156. }
  157. }
  158. return this.n()
  159. };
  160. var G = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15],
  161. D = t ? new Uint16Array(G) : G,
  162. H = [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 258, 258],
  163. I = t ? new Uint16Array(H) : H,
  164. J = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0],
  165. K = t ? new Uint8Array(J) : J,
  166. L = [1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577],
  167. da = t ? new Uint16Array(L) : L,
  168. ea = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12,
  169. 13, 13
  170. ],
  171. N = t ? new Uint8Array(ea) : ea,
  172. O = new(t ? Uint8Array : Array)(288),
  173. P, fa;
  174. P = 0;
  175. for (fa = O.length; P < fa; ++P) O[P] = 143 >= P ? 8 : 255 >= P ? 9 : 279 >= P ? 7 : 8;
  176. var ba = v(O),
  177. Q = new(t ? Uint8Array : Array)(30),
  178. R, ga;
  179. R = 0;
  180. for (ga = Q.length; R < ga; ++R) Q[R] = 5;
  181. var ca = v(Q);
  182. function C(c, d) {
  183. for (var a = c.f, b = c.d, e = c.input, f = c.a, g = e.length, h; b < d;) {
  184. if (f >= g) throw Error("input buffer is broken");
  185. a |= e[f++] << b;
  186. b += 8
  187. }
  188. h = a & (1 << d) - 1;
  189. c.f = a >>> d;
  190. c.d = b - d;
  191. c.a = f;
  192. return h
  193. }
  194. function E(c, d) {
  195. for (var a = c.f, b = c.d, e = c.input, f = c.a, g = e.length, h = d[0], k = d[1], m, n; b < k && !(f >= g);) a |= e[f++] << b, b += 8;
  196. m = h[a & (1 << k) - 1];
  197. n = m >>> 16;
  198. if (n > b) throw Error("invalid code length: " + n);
  199. c.f = a >> n;
  200. c.d = b - n;
  201. c.a = f;
  202. return m & 65535
  203. }
  204. w.prototype.j = function (c, d) {
  205. var a = this.c,
  206. b = this.b;
  207. this.o = c;
  208. for (var e = a.length - 258, f, g, h, k; 256 !== (f = E(this, c));)
  209. if (256 > f) b >= e && (this.b = b, a = this.e(), b = this.b), a[b++] = f;
  210. else {
  211. g = f - 257;
  212. k = I[g];
  213. 0 < K[g] && (k += C(this, K[g]));
  214. f = E(this, d);
  215. h = da[f];
  216. 0 < N[f] && (h += C(this, N[f]));
  217. b >= e && (this.b = b, a = this.e(), b = this.b);
  218. for (; k--;) a[b] = a[b++ - h]
  219. } for (; 8 <= this.d;) this.d -= 8, this.a--;
  220. this.b = b
  221. };
  222. w.prototype.w = function (c, d) {
  223. var a = this.c,
  224. b = this.b;
  225. this.o = c;
  226. for (var e = a.length, f, g, h, k; 256 !== (f = E(this, c));)
  227. if (256 > f) b >= e && (a = this.e(), e = a.length), a[b++] = f;
  228. else {
  229. g = f - 257;
  230. k = I[g];
  231. 0 < K[g] && (k += C(this, K[g]));
  232. f = E(this, d);
  233. h = da[f];
  234. 0 < N[f] && (h += C(this, N[f]));
  235. b + k > e && (a = this.e(), e = a.length);
  236. for (; k--;) a[b] = a[b++ - h]
  237. } for (; 8 <= this.d;) this.d -= 8, this.a--;
  238. this.b = b
  239. };
  240. w.prototype.e = function () {
  241. var c = new(t ? Uint8Array : Array)(this.b - 32768),
  242. d = this.b - 32768,
  243. a, b, e = this.c;
  244. if (t) c.set(e.subarray(32768, c.length));
  245. else {
  246. a = 0;
  247. for (b = c.length; a < b; ++a) c[a] = e[a + 32768]
  248. }
  249. this.g.push(c);
  250. this.l += c.length;
  251. if (t) e.set(e.subarray(d, d + 32768));
  252. else
  253. for (a = 0; 32768 > a; ++a) e[a] = e[d + a];
  254. this.b = 32768;
  255. return e
  256. };
  257. w.prototype.z = function (c) {
  258. var d, a = this.input.length / this.a + 1 | 0,
  259. b, e, f, g = this.input,
  260. h = this.c;
  261. c && ("number" === typeof c.p && (a = c.p), "number" === typeof c.u && (a += c.u));
  262. 2 > a ? (b = (g.length - this.a) / this.o[2], f = 258 * (b / 2) | 0, e = f < h.length ? h.length + f : h.length << 1) : e = h.length * a;
  263. t ? (d = new Uint8Array(e), d.set(h)) : d = h;
  264. return this.c = d
  265. };
  266. w.prototype.n = function () {
  267. var c = 0,
  268. d = this.c,
  269. a = this.g,
  270. b, e = new(t ? Uint8Array : Array)(this.l + (this.b - 32768)),
  271. f, g, h, k;
  272. if (0 === a.length) return t ? this.c.subarray(32768, this.b) : this.c.slice(32768, this.b);
  273. f = 0;
  274. for (g = a.length; f < g; ++f) {
  275. b = a[f];
  276. h = 0;
  277. for (k = b.length; h < k; ++h) e[c++] = b[h]
  278. }
  279. f = 32768;
  280. for (g = this.b; f < g; ++f) e[c++] = d[f];
  281. this.g = [];
  282. return this.buffer = e
  283. };
  284. w.prototype.v = function () {
  285. var c, d = this.b;
  286. t ? this.r ? (c = new Uint8Array(d), c.set(this.c.subarray(0, d))) : c = this.c.subarray(0, d) : (this.c.length > d && (this.c.length = d), c = this.c);
  287. return this.buffer = c
  288. };
  289. function W(c, d) {
  290. var a, b;
  291. this.input = c;
  292. this.a = 0;
  293. if (d || !(d = {})) d.index && (this.a = d.index), d.verify && (this.A = d.verify);
  294. a = c[this.a++];
  295. b = c[this.a++];
  296. switch (a & 15) {
  297. case ha:
  298. this.method = ha;
  299. break;
  300. default:
  301. throw Error("unsupported compression method");
  302. }
  303. if (0 !== ((a << 8) + b) % 31) throw Error("invalid fcheck flag:" + ((a << 8) + b) % 31);
  304. if (b & 32) throw Error("fdict flag is not supported");
  305. this.q = new w(c, {
  306. index: this.a,
  307. bufferSize: d.bufferSize,
  308. bufferType: d.bufferType,
  309. resize: d.resize
  310. })
  311. }
  312. W.prototype.k = function () {
  313. var c = this.input,
  314. d, a;
  315. d = this.q.k();
  316. this.a = this.q.a;
  317. if (this.A) {
  318. a = (c[this.a++] << 24 | c[this.a++] << 16 | c[this.a++] << 8 | c[this.a++]) >>> 0;
  319. var b = d;
  320. if ("string" === typeof b) {
  321. var e = b.split(""),
  322. f, g;
  323. f = 0;
  324. for (g = e.length; f < g; f++) e[f] = (e[f].charCodeAt(0) & 255) >>> 0;
  325. b = e
  326. }
  327. for (var h = 1, k = 0, m = b.length, n, p = 0; 0 < m;) {
  328. n = 1024 < m ? 1024 : m;
  329. m -= n;
  330. do h += b[p++], k += h; while (--n);
  331. h %= 65521;
  332. k %= 65521
  333. }
  334. if (a !== (k << 16 | h) >>> 0) throw Error("invalid adler-32 checksum");
  335. }
  336. return d
  337. };
  338. var ha = 8;
  339. r("Zlib.Inflate", W);
  340. r("Zlib.Inflate.prototype.decompress", W.prototype.k);
  341. var X = {
  342. ADAPTIVE: B.s,
  343. BLOCK: B.t
  344. },
  345. Y, Z, $, ia;
  346. if (Object.keys) Y = Object.keys(X);
  347. else
  348. for (Z in Y = [], $ = 0, X) Y[$++] = Z;
  349. $ = 0;
  350. for (ia = Y.length; $ < ia; ++$) Z = Y[$], r("Zlib.Inflate.BufferType." + Z, X[Z]);
  351. console.log(objZlib);
  352. return objZlib;
  353. }