UrgentcareCLI 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (308) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +60 -25
  4. data/Notes +1 -1
  5. data/README.md +5 -5
  6. data/Rakefile +2 -0
  7. data/UrgentCare.gemspec +3 -3
  8. data/background.jpg +0 -0
  9. data/lib/UrgentCare.rb +3 -0
  10. data/lib/UrgentCare/CLI.rb +6 -2
  11. data/lib/UrgentCare/version.rb +1 -1
  12. data/lib/Urgentcare/Scraper.rb +65 -23
  13. data/node_modules/.bin/rimraf +1 -0
  14. data/node_modules/.package-lock.json +250 -0
  15. data/node_modules/balanced-match/.github/FUNDING.yml +2 -0
  16. data/node_modules/balanced-match/LICENSE.md +21 -0
  17. data/node_modules/balanced-match/README.md +97 -0
  18. data/node_modules/balanced-match/index.js +62 -0
  19. data/node_modules/balanced-match/package.json +48 -0
  20. data/node_modules/brace-expansion/LICENSE +21 -0
  21. data/node_modules/brace-expansion/README.md +129 -0
  22. data/node_modules/brace-expansion/index.js +201 -0
  23. data/node_modules/brace-expansion/package.json +47 -0
  24. data/node_modules/concat-map/.travis.yml +4 -0
  25. data/node_modules/concat-map/LICENSE +18 -0
  26. data/node_modules/concat-map/README.markdown +62 -0
  27. data/node_modules/concat-map/example/map.js +6 -0
  28. data/node_modules/concat-map/index.js +13 -0
  29. data/node_modules/concat-map/package.json +43 -0
  30. data/node_modules/concat-map/test/map.js +39 -0
  31. data/node_modules/core-util-is/LICENSE +19 -0
  32. data/node_modules/core-util-is/README.md +3 -0
  33. data/node_modules/core-util-is/float.patch +604 -0
  34. data/node_modules/core-util-is/lib/util.js +107 -0
  35. data/node_modules/core-util-is/package.json +32 -0
  36. data/node_modules/core-util-is/test.js +68 -0
  37. data/node_modules/fs.realpath/LICENSE +43 -0
  38. data/node_modules/fs.realpath/README.md +33 -0
  39. data/node_modules/fs.realpath/index.js +66 -0
  40. data/node_modules/fs.realpath/old.js +303 -0
  41. data/node_modules/fs.realpath/package.json +26 -0
  42. data/node_modules/glob/LICENSE +21 -0
  43. data/node_modules/glob/README.md +375 -0
  44. data/node_modules/glob/changelog.md +67 -0
  45. data/node_modules/glob/common.js +234 -0
  46. data/node_modules/glob/glob.js +788 -0
  47. data/node_modules/glob/package.json +51 -0
  48. data/node_modules/glob/sync.js +484 -0
  49. data/node_modules/immediate/LICENSE.txt +20 -0
  50. data/node_modules/immediate/README.md +93 -0
  51. data/node_modules/immediate/dist/immediate.js +75 -0
  52. data/node_modules/immediate/dist/immediate.min.js +1 -0
  53. data/node_modules/immediate/lib/browser.js +69 -0
  54. data/node_modules/immediate/lib/index.js +73 -0
  55. data/node_modules/immediate/package.json +42 -0
  56. data/node_modules/inflight/LICENSE +15 -0
  57. data/node_modules/inflight/README.md +37 -0
  58. data/node_modules/inflight/inflight.js +54 -0
  59. data/node_modules/inflight/package.json +29 -0
  60. data/node_modules/inherits/LICENSE +16 -0
  61. data/node_modules/inherits/README.md +42 -0
  62. data/node_modules/inherits/inherits.js +9 -0
  63. data/node_modules/inherits/inherits_browser.js +27 -0
  64. data/node_modules/inherits/package.json +29 -0
  65. data/node_modules/isarray/.npmignore +1 -0
  66. data/node_modules/isarray/.travis.yml +4 -0
  67. data/node_modules/isarray/Makefile +6 -0
  68. data/node_modules/isarray/README.md +60 -0
  69. data/node_modules/isarray/component.json +19 -0
  70. data/node_modules/isarray/index.js +5 -0
  71. data/node_modules/isarray/package.json +45 -0
  72. data/node_modules/isarray/test.js +20 -0
  73. data/node_modules/jszip/.codeclimate.yml +16 -0
  74. data/node_modules/jszip/.editorconfig +8 -0
  75. data/node_modules/jszip/.jshintignore +1 -0
  76. data/node_modules/jszip/.jshintrc +21 -0
  77. data/node_modules/jszip/.travis.yml +17 -0
  78. data/node_modules/jszip/CHANGES.md +163 -0
  79. data/node_modules/jszip/LICENSE.markdown +651 -0
  80. data/node_modules/jszip/README.markdown +35 -0
  81. data/node_modules/jszip/dist/jszip.js +30 -0
  82. data/node_modules/jszip/dist/jszip.min.js +13 -0
  83. data/node_modules/jszip/index.d.ts +270 -0
  84. data/node_modules/jszip/lib/base64.js +106 -0
  85. data/node_modules/jszip/lib/compressedObject.js +74 -0
  86. data/node_modules/jszip/lib/compressions.js +14 -0
  87. data/node_modules/jszip/lib/crc32.js +77 -0
  88. data/node_modules/jszip/lib/defaults.js +11 -0
  89. data/node_modules/jszip/lib/external.js +19 -0
  90. data/node_modules/jszip/lib/flate.js +85 -0
  91. data/node_modules/jszip/lib/generate/ZipFileWorker.js +540 -0
  92. data/node_modules/jszip/lib/generate/index.js +57 -0
  93. data/node_modules/jszip/lib/index.js +52 -0
  94. data/node_modules/jszip/lib/license_header.js +11 -0
  95. data/node_modules/jszip/lib/load.js +81 -0
  96. data/node_modules/jszip/lib/nodejs/NodejsStreamInputAdapter.js +74 -0
  97. data/node_modules/jszip/lib/nodejs/NodejsStreamOutputAdapter.js +42 -0
  98. data/node_modules/jszip/lib/nodejsUtils.js +57 -0
  99. data/node_modules/jszip/lib/object.js +389 -0
  100. data/node_modules/jszip/lib/readable-stream-browser.js +9 -0
  101. data/node_modules/jszip/lib/reader/ArrayReader.js +57 -0
  102. data/node_modules/jszip/lib/reader/DataReader.js +116 -0
  103. data/node_modules/jszip/lib/reader/NodeBufferReader.js +19 -0
  104. data/node_modules/jszip/lib/reader/StringReader.js +38 -0
  105. data/node_modules/jszip/lib/reader/Uint8ArrayReader.js +22 -0
  106. data/node_modules/jszip/lib/reader/readerFor.js +28 -0
  107. data/node_modules/jszip/lib/signature.js +7 -0
  108. data/node_modules/jszip/lib/stream/ConvertWorker.js +26 -0
  109. data/node_modules/jszip/lib/stream/Crc32Probe.js +24 -0
  110. data/node_modules/jszip/lib/stream/DataLengthProbe.js +29 -0
  111. data/node_modules/jszip/lib/stream/DataWorker.js +116 -0
  112. data/node_modules/jszip/lib/stream/GenericWorker.js +263 -0
  113. data/node_modules/jszip/lib/stream/StreamHelper.js +212 -0
  114. data/node_modules/jszip/lib/support.js +38 -0
  115. data/node_modules/jszip/lib/utf8.js +275 -0
  116. data/node_modules/jszip/lib/utils.js +476 -0
  117. data/node_modules/jszip/lib/zipEntries.js +262 -0
  118. data/node_modules/jszip/lib/zipEntry.js +294 -0
  119. data/node_modules/jszip/lib/zipObject.js +133 -0
  120. data/node_modules/jszip/package.json +63 -0
  121. data/node_modules/jszip/vendor/FileSaver.js +247 -0
  122. data/node_modules/lie/README.md +62 -0
  123. data/node_modules/lie/dist/lie.js +350 -0
  124. data/node_modules/lie/dist/lie.min.js +1 -0
  125. data/node_modules/lie/dist/lie.polyfill.js +358 -0
  126. data/node_modules/lie/dist/lie.polyfill.min.js +1 -0
  127. data/node_modules/lie/lib/browser.js +273 -0
  128. data/node_modules/lie/lib/index.js +298 -0
  129. data/node_modules/lie/license.md +7 -0
  130. data/node_modules/lie/lie.d.ts +244 -0
  131. data/node_modules/lie/package.json +69 -0
  132. data/node_modules/lie/polyfill.js +4 -0
  133. data/node_modules/minimatch/LICENSE +15 -0
  134. data/node_modules/minimatch/README.md +209 -0
  135. data/node_modules/minimatch/minimatch.js +923 -0
  136. data/node_modules/minimatch/package.json +30 -0
  137. data/node_modules/once/LICENSE +15 -0
  138. data/node_modules/once/README.md +79 -0
  139. data/node_modules/once/once.js +42 -0
  140. data/node_modules/once/package.json +33 -0
  141. data/node_modules/pako/CHANGELOG.md +164 -0
  142. data/node_modules/pako/LICENSE +21 -0
  143. data/node_modules/pako/README.md +191 -0
  144. data/node_modules/pako/dist/pako.js +6818 -0
  145. data/node_modules/pako/dist/pako.min.js +1 -0
  146. data/node_modules/pako/dist/pako_deflate.js +3997 -0
  147. data/node_modules/pako/dist/pako_deflate.min.js +1 -0
  148. data/node_modules/pako/dist/pako_inflate.js +3300 -0
  149. data/node_modules/pako/dist/pako_inflate.min.js +1 -0
  150. data/node_modules/pako/index.js +14 -0
  151. data/node_modules/pako/lib/deflate.js +400 -0
  152. data/node_modules/pako/lib/inflate.js +423 -0
  153. data/node_modules/pako/lib/utils/common.js +105 -0
  154. data/node_modules/pako/lib/utils/strings.js +187 -0
  155. data/node_modules/pako/lib/zlib/README +59 -0
  156. data/node_modules/pako/lib/zlib/adler32.js +51 -0
  157. data/node_modules/pako/lib/zlib/constants.js +68 -0
  158. data/node_modules/pako/lib/zlib/crc32.js +59 -0
  159. data/node_modules/pako/lib/zlib/deflate.js +1874 -0
  160. data/node_modules/pako/lib/zlib/gzheader.js +58 -0
  161. data/node_modules/pako/lib/zlib/inffast.js +345 -0
  162. data/node_modules/pako/lib/zlib/inflate.js +1556 -0
  163. data/node_modules/pako/lib/zlib/inftrees.js +343 -0
  164. data/node_modules/pako/lib/zlib/messages.js +32 -0
  165. data/node_modules/pako/lib/zlib/trees.js +1222 -0
  166. data/node_modules/pako/lib/zlib/zstream.js +47 -0
  167. data/node_modules/pako/package.json +44 -0
  168. data/node_modules/path-is-absolute/index.js +20 -0
  169. data/node_modules/path-is-absolute/license +21 -0
  170. data/node_modules/path-is-absolute/package.json +43 -0
  171. data/node_modules/path-is-absolute/readme.md +59 -0
  172. data/node_modules/process-nextick-args/index.js +45 -0
  173. data/node_modules/process-nextick-args/license.md +19 -0
  174. data/node_modules/process-nextick-args/package.json +25 -0
  175. data/node_modules/process-nextick-args/readme.md +18 -0
  176. data/node_modules/readable-stream/.travis.yml +34 -0
  177. data/node_modules/readable-stream/CONTRIBUTING.md +38 -0
  178. data/node_modules/readable-stream/GOVERNANCE.md +136 -0
  179. data/node_modules/readable-stream/LICENSE +47 -0
  180. data/node_modules/readable-stream/README.md +58 -0
  181. data/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +60 -0
  182. data/node_modules/readable-stream/duplex-browser.js +1 -0
  183. data/node_modules/readable-stream/duplex.js +1 -0
  184. data/node_modules/readable-stream/lib/_stream_duplex.js +131 -0
  185. data/node_modules/readable-stream/lib/_stream_passthrough.js +47 -0
  186. data/node_modules/readable-stream/lib/_stream_readable.js +1019 -0
  187. data/node_modules/readable-stream/lib/_stream_transform.js +214 -0
  188. data/node_modules/readable-stream/lib/_stream_writable.js +687 -0
  189. data/node_modules/readable-stream/lib/internal/streams/BufferList.js +79 -0
  190. data/node_modules/readable-stream/lib/internal/streams/destroy.js +74 -0
  191. data/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
  192. data/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
  193. data/node_modules/readable-stream/package.json +52 -0
  194. data/node_modules/readable-stream/passthrough.js +1 -0
  195. data/node_modules/readable-stream/readable-browser.js +7 -0
  196. data/node_modules/readable-stream/readable.js +19 -0
  197. data/node_modules/readable-stream/transform.js +1 -0
  198. data/node_modules/readable-stream/writable-browser.js +1 -0
  199. data/node_modules/readable-stream/writable.js +8 -0
  200. data/node_modules/rimraf/LICENSE +15 -0
  201. data/node_modules/rimraf/README.md +101 -0
  202. data/node_modules/rimraf/bin.js +50 -0
  203. data/node_modules/rimraf/package.json +29 -0
  204. data/node_modules/rimraf/rimraf.js +372 -0
  205. data/node_modules/safe-buffer/LICENSE +21 -0
  206. data/node_modules/safe-buffer/README.md +584 -0
  207. data/node_modules/safe-buffer/index.d.ts +187 -0
  208. data/node_modules/safe-buffer/index.js +62 -0
  209. data/node_modules/safe-buffer/package.json +37 -0
  210. data/node_modules/selenium-webdriver/CHANGES.md +1114 -0
  211. data/node_modules/selenium-webdriver/LICENSE +202 -0
  212. data/node_modules/selenium-webdriver/NOTICE +2 -0
  213. data/node_modules/selenium-webdriver/README.md +229 -0
  214. data/node_modules/selenium-webdriver/chrome.js +295 -0
  215. data/node_modules/selenium-webdriver/chromium.js +829 -0
  216. data/node_modules/selenium-webdriver/devtools/CDPConnection.js +35 -0
  217. data/node_modules/selenium-webdriver/edge.js +224 -0
  218. data/node_modules/selenium-webdriver/example/chrome_android.js +45 -0
  219. data/node_modules/selenium-webdriver/example/chrome_mobile_emulation.js +46 -0
  220. data/node_modules/selenium-webdriver/example/firefox_channels.js +84 -0
  221. data/node_modules/selenium-webdriver/example/google_search.js +50 -0
  222. data/node_modules/selenium-webdriver/example/google_search_test.js +70 -0
  223. data/node_modules/selenium-webdriver/example/headless.js +63 -0
  224. data/node_modules/selenium-webdriver/example/logging.js +64 -0
  225. data/node_modules/selenium-webdriver/firefox.js +789 -0
  226. data/node_modules/selenium-webdriver/http/index.js +324 -0
  227. data/node_modules/selenium-webdriver/http/util.js +172 -0
  228. data/node_modules/selenium-webdriver/ie.js +503 -0
  229. data/node_modules/selenium-webdriver/index.js +825 -0
  230. data/node_modules/selenium-webdriver/io/exec.js +162 -0
  231. data/node_modules/selenium-webdriver/io/index.js +348 -0
  232. data/node_modules/selenium-webdriver/io/zip.js +223 -0
  233. data/node_modules/selenium-webdriver/lib/atoms/find-elements.js +123 -0
  234. data/node_modules/selenium-webdriver/lib/atoms/get-attribute.js +101 -0
  235. data/node_modules/selenium-webdriver/lib/atoms/is-displayed.js +101 -0
  236. data/node_modules/selenium-webdriver/lib/atoms/mutation-listener.js +55 -0
  237. data/node_modules/selenium-webdriver/lib/by.js +415 -0
  238. data/node_modules/selenium-webdriver/lib/capabilities.js +553 -0
  239. data/node_modules/selenium-webdriver/lib/command.js +206 -0
  240. data/node_modules/selenium-webdriver/lib/error.js +605 -0
  241. data/node_modules/selenium-webdriver/lib/http.js +704 -0
  242. data/node_modules/selenium-webdriver/lib/input.js +946 -0
  243. data/node_modules/selenium-webdriver/lib/logging.js +661 -0
  244. data/node_modules/selenium-webdriver/lib/promise.js +285 -0
  245. data/node_modules/selenium-webdriver/lib/proxy.js +212 -0
  246. data/node_modules/selenium-webdriver/lib/session.js +77 -0
  247. data/node_modules/selenium-webdriver/lib/symbols.js +37 -0
  248. data/node_modules/selenium-webdriver/lib/until.js +429 -0
  249. data/node_modules/selenium-webdriver/lib/webdriver.js +2919 -0
  250. data/node_modules/selenium-webdriver/net/index.js +107 -0
  251. data/node_modules/selenium-webdriver/net/portprober.js +75 -0
  252. data/node_modules/selenium-webdriver/opera.js +406 -0
  253. data/node_modules/selenium-webdriver/package.json +54 -0
  254. data/node_modules/selenium-webdriver/proxy.js +32 -0
  255. data/node_modules/selenium-webdriver/remote/index.js +624 -0
  256. data/node_modules/selenium-webdriver/safari.js +168 -0
  257. data/node_modules/selenium-webdriver/testing/index.js +504 -0
  258. data/node_modules/set-immediate-shim/index.js +7 -0
  259. data/node_modules/set-immediate-shim/package.json +34 -0
  260. data/node_modules/set-immediate-shim/readme.md +31 -0
  261. data/node_modules/string_decoder/.travis.yml +50 -0
  262. data/node_modules/string_decoder/LICENSE +48 -0
  263. data/node_modules/string_decoder/README.md +47 -0
  264. data/node_modules/string_decoder/lib/string_decoder.js +296 -0
  265. data/node_modules/string_decoder/package.json +31 -0
  266. data/node_modules/tmp/CHANGELOG.md +288 -0
  267. data/node_modules/tmp/LICENSE +21 -0
  268. data/node_modules/tmp/README.md +365 -0
  269. data/node_modules/tmp/lib/tmp.js +780 -0
  270. data/node_modules/tmp/node_modules/.bin/rimraf +1 -0
  271. data/node_modules/tmp/node_modules/rimraf/CHANGELOG.md +65 -0
  272. data/node_modules/tmp/node_modules/rimraf/LICENSE +15 -0
  273. data/node_modules/tmp/node_modules/rimraf/README.md +101 -0
  274. data/node_modules/tmp/node_modules/rimraf/bin.js +68 -0
  275. data/node_modules/tmp/node_modules/rimraf/package.json +32 -0
  276. data/node_modules/tmp/node_modules/rimraf/rimraf.js +360 -0
  277. data/node_modules/tmp/package.json +58 -0
  278. data/node_modules/util-deprecate/History.md +16 -0
  279. data/node_modules/util-deprecate/LICENSE +24 -0
  280. data/node_modules/util-deprecate/README.md +53 -0
  281. data/node_modules/util-deprecate/browser.js +67 -0
  282. data/node_modules/util-deprecate/node.js +6 -0
  283. data/node_modules/util-deprecate/package.json +27 -0
  284. data/node_modules/wrappy/LICENSE +15 -0
  285. data/node_modules/wrappy/README.md +36 -0
  286. data/node_modules/wrappy/package.json +29 -0
  287. data/node_modules/wrappy/wrappy.js +33 -0
  288. data/node_modules/ws/LICENSE +21 -0
  289. data/node_modules/ws/README.md +496 -0
  290. data/node_modules/ws/browser.js +8 -0
  291. data/node_modules/ws/index.js +10 -0
  292. data/node_modules/ws/lib/buffer-util.js +129 -0
  293. data/node_modules/ws/lib/constants.js +10 -0
  294. data/node_modules/ws/lib/event-target.js +184 -0
  295. data/node_modules/ws/lib/extension.js +223 -0
  296. data/node_modules/ws/lib/limiter.js +55 -0
  297. data/node_modules/ws/lib/permessage-deflate.js +517 -0
  298. data/node_modules/ws/lib/receiver.js +507 -0
  299. data/node_modules/ws/lib/sender.js +405 -0
  300. data/node_modules/ws/lib/stream.js +165 -0
  301. data/node_modules/ws/lib/validation.js +104 -0
  302. data/node_modules/ws/lib/websocket-server.js +418 -0
  303. data/node_modules/ws/lib/websocket.js +942 -0
  304. data/node_modules/ws/package.json +56 -0
  305. data/package-lock.json +458 -0
  306. data/package.json +5 -0
  307. data/selenium.log +1 -0
  308. metadata +314 -19
@@ -0,0 +1 @@
1
+ !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).pako=t()}}(function(){return function r(s,o,l){function h(e,t){if(!o[e]){if(!s[e]){var a="function"==typeof require&&require;if(!t&&a)return a(e,!0);if(d)return d(e,!0);var i=new Error("Cannot find module '"+e+"'");throw i.code="MODULE_NOT_FOUND",i}var n=o[e]={exports:{}};s[e][0].call(n.exports,function(t){return h(s[e][1][t]||t)},n,n.exports,r,s,o,l)}return o[e].exports}for(var d="function"==typeof require&&require,t=0;t<l.length;t++)h(l[t]);return h}({1:[function(t,e,a){"use strict";var s=t("./zlib/deflate"),o=t("./utils/common"),l=t("./utils/strings"),n=t("./zlib/messages"),r=t("./zlib/zstream"),h=Object.prototype.toString,d=0,f=-1,_=0,u=8;function c(t){if(!(this instanceof c))return new c(t);this.options=o.assign({level:f,method:u,chunkSize:16384,windowBits:15,memLevel:8,strategy:_,to:""},t||{});var e=this.options;e.raw&&0<e.windowBits?e.windowBits=-e.windowBits:e.gzip&&0<e.windowBits&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new r,this.strm.avail_out=0;var a=s.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==d)throw new Error(n[a]);if(e.header&&s.deflateSetHeader(this.strm,e.header),e.dictionary){var i;if(i="string"==typeof e.dictionary?l.string2buf(e.dictionary):"[object ArrayBuffer]"===h.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,(a=s.deflateSetDictionary(this.strm,i))!==d)throw new Error(n[a]);this._dict_set=!0}}function i(t,e){var a=new c(e);if(a.push(t,!0),a.err)throw a.msg||n[a.err];return a.result}c.prototype.push=function(t,e){var a,i,n=this.strm,r=this.options.chunkSize;if(this.ended)return!1;i=e===~~e?e:!0===e?4:0,"string"==typeof t?n.input=l.string2buf(t):"[object ArrayBuffer]"===h.call(t)?n.input=new Uint8Array(t):n.input=t,n.next_in=0,n.avail_in=n.input.length;do{if(0===n.avail_out&&(n.output=new o.Buf8(r),n.next_out=0,n.avail_out=r),1!==(a=s.deflate(n,i))&&a!==d)return this.onEnd(a),!(this.ended=!0);0!==n.avail_out&&(0!==n.avail_in||4!==i&&2!==i)||("string"===this.options.to?this.onData(l.buf2binstring(o.shrinkBuf(n.output,n.next_out))):this.onData(o.shrinkBuf(n.output,n.next_out)))}while((0<n.avail_in||0===n.avail_out)&&1!==a);return 4===i?(a=s.deflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===d):2!==i||(this.onEnd(d),!(n.avail_out=0))},c.prototype.onData=function(t){this.chunks.push(t)},c.prototype.onEnd=function(t){t===d&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Deflate=c,a.deflate=i,a.deflateRaw=function(t,e){return(e=e||{}).raw=!0,i(t,e)},a.gzip=function(t,e){return(e=e||{}).gzip=!0,i(t,e)}},{"./utils/common":3,"./utils/strings":4,"./zlib/deflate":8,"./zlib/messages":13,"./zlib/zstream":15}],2:[function(t,e,a){"use strict";var f=t("./zlib/inflate"),_=t("./utils/common"),u=t("./utils/strings"),c=t("./zlib/constants"),i=t("./zlib/messages"),n=t("./zlib/zstream"),r=t("./zlib/gzheader"),b=Object.prototype.toString;function s(t){if(!(this instanceof s))return new s(t);this.options=_.assign({chunkSize:16384,windowBits:0,to:""},t||{});var e=this.options;e.raw&&0<=e.windowBits&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(0<=e.windowBits&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),15<e.windowBits&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new n,this.strm.avail_out=0;var a=f.inflateInit2(this.strm,e.windowBits);if(a!==c.Z_OK)throw new Error(i[a]);if(this.header=new r,f.inflateGetHeader(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=u.string2buf(e.dictionary):"[object ArrayBuffer]"===b.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(a=f.inflateSetDictionary(this.strm,e.dictionary))!==c.Z_OK))throw new Error(i[a])}function o(t,e){var a=new s(e);if(a.push(t,!0),a.err)throw a.msg||i[a.err];return a.result}s.prototype.push=function(t,e){var a,i,n,r,s,o=this.strm,l=this.options.chunkSize,h=this.options.dictionary,d=!1;if(this.ended)return!1;i=e===~~e?e:!0===e?c.Z_FINISH:c.Z_NO_FLUSH,"string"==typeof t?o.input=u.binstring2buf(t):"[object ArrayBuffer]"===b.call(t)?o.input=new Uint8Array(t):o.input=t,o.next_in=0,o.avail_in=o.input.length;do{if(0===o.avail_out&&(o.output=new _.Buf8(l),o.next_out=0,o.avail_out=l),(a=f.inflate(o,c.Z_NO_FLUSH))===c.Z_NEED_DICT&&h&&(a=f.inflateSetDictionary(this.strm,h)),a===c.Z_BUF_ERROR&&!0===d&&(a=c.Z_OK,d=!1),a!==c.Z_STREAM_END&&a!==c.Z_OK)return this.onEnd(a),!(this.ended=!0);o.next_out&&(0!==o.avail_out&&a!==c.Z_STREAM_END&&(0!==o.avail_in||i!==c.Z_FINISH&&i!==c.Z_SYNC_FLUSH)||("string"===this.options.to?(n=u.utf8border(o.output,o.next_out),r=o.next_out-n,s=u.buf2string(o.output,n),o.next_out=r,o.avail_out=l-r,r&&_.arraySet(o.output,o.output,n,r,0),this.onData(s)):this.onData(_.shrinkBuf(o.output,o.next_out)))),0===o.avail_in&&0===o.avail_out&&(d=!0)}while((0<o.avail_in||0===o.avail_out)&&a!==c.Z_STREAM_END);return a===c.Z_STREAM_END&&(i=c.Z_FINISH),i===c.Z_FINISH?(a=f.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===c.Z_OK):i!==c.Z_SYNC_FLUSH||(this.onEnd(c.Z_OK),!(o.avail_out=0))},s.prototype.onData=function(t){this.chunks.push(t)},s.prototype.onEnd=function(t){t===c.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=_.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Inflate=s,a.inflate=o,a.inflateRaw=function(t,e){return(e=e||{}).raw=!0,o(t,e)},a.ungzip=o},{"./utils/common":3,"./utils/strings":4,"./zlib/constants":6,"./zlib/gzheader":9,"./zlib/inflate":11,"./zlib/messages":13,"./zlib/zstream":15}],3:[function(t,e,a){"use strict";var i="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;a.assign=function(t){for(var e,a,i=Array.prototype.slice.call(arguments,1);i.length;){var n=i.shift();if(n){if("object"!=typeof n)throw new TypeError(n+"must be non-object");for(var r in n)e=n,a=r,Object.prototype.hasOwnProperty.call(e,a)&&(t[r]=n[r])}}return t},a.shrinkBuf=function(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)};var n={arraySet:function(t,e,a,i,n){if(e.subarray&&t.subarray)t.set(e.subarray(a,a+i),n);else for(var r=0;r<i;r++)t[n+r]=e[a+r]},flattenChunks:function(t){var e,a,i,n,r,s;for(e=i=0,a=t.length;e<a;e++)i+=t[e].length;for(s=new Uint8Array(i),e=n=0,a=t.length;e<a;e++)r=t[e],s.set(r,n),n+=r.length;return s}},r={arraySet:function(t,e,a,i,n){for(var r=0;r<i;r++)t[n+r]=e[a+r]},flattenChunks:function(t){return[].concat.apply([],t)}};a.setTyped=function(t){t?(a.Buf8=Uint8Array,a.Buf16=Uint16Array,a.Buf32=Int32Array,a.assign(a,n)):(a.Buf8=Array,a.Buf16=Array,a.Buf32=Array,a.assign(a,r))},a.setTyped(i)},{}],4:[function(t,e,a){"use strict";var l=t("./common"),n=!0,r=!0;try{String.fromCharCode.apply(null,[0])}catch(t){n=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){r=!1}for(var h=new l.Buf8(256),i=0;i<256;i++)h[i]=252<=i?6:248<=i?5:240<=i?4:224<=i?3:192<=i?2:1;function d(t,e){if(e<65534&&(t.subarray&&r||!t.subarray&&n))return String.fromCharCode.apply(null,l.shrinkBuf(t,e));for(var a="",i=0;i<e;i++)a+=String.fromCharCode(t[i]);return a}h[254]=h[254]=1,a.string2buf=function(t){var e,a,i,n,r,s=t.length,o=0;for(n=0;n<s;n++)55296==(64512&(a=t.charCodeAt(n)))&&n+1<s&&56320==(64512&(i=t.charCodeAt(n+1)))&&(a=65536+(a-55296<<10)+(i-56320),n++),o+=a<128?1:a<2048?2:a<65536?3:4;for(e=new l.Buf8(o),n=r=0;r<o;n++)55296==(64512&(a=t.charCodeAt(n)))&&n+1<s&&56320==(64512&(i=t.charCodeAt(n+1)))&&(a=65536+(a-55296<<10)+(i-56320),n++),a<128?e[r++]=a:(a<2048?e[r++]=192|a>>>6:(a<65536?e[r++]=224|a>>>12:(e[r++]=240|a>>>18,e[r++]=128|a>>>12&63),e[r++]=128|a>>>6&63),e[r++]=128|63&a);return e},a.buf2binstring=function(t){return d(t,t.length)},a.binstring2buf=function(t){for(var e=new l.Buf8(t.length),a=0,i=e.length;a<i;a++)e[a]=t.charCodeAt(a);return e},a.buf2string=function(t,e){var a,i,n,r,s=e||t.length,o=new Array(2*s);for(a=i=0;a<s;)if((n=t[a++])<128)o[i++]=n;else if(4<(r=h[n]))o[i++]=65533,a+=r-1;else{for(n&=2===r?31:3===r?15:7;1<r&&a<s;)n=n<<6|63&t[a++],r--;1<r?o[i++]=65533:n<65536?o[i++]=n:(n-=65536,o[i++]=55296|n>>10&1023,o[i++]=56320|1023&n)}return d(o,i)},a.utf8border=function(t,e){var a;for((e=e||t.length)>t.length&&(e=t.length),a=e-1;0<=a&&128==(192&t[a]);)a--;return a<0?e:0===a?e:a+h[t[a]]>e?a:e}},{"./common":3}],5:[function(t,e,a){"use strict";e.exports=function(t,e,a,i){for(var n=65535&t|0,r=t>>>16&65535|0,s=0;0!==a;){for(a-=s=2e3<a?2e3:a;r=r+(n=n+e[i++]|0)|0,--s;);n%=65521,r%=65521}return n|r<<16|0}},{}],6:[function(t,e,a){"use strict";e.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],7:[function(t,e,a){"use strict";var o=function(){for(var t,e=[],a=0;a<256;a++){t=a;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e}();e.exports=function(t,e,a,i){var n=o,r=i+a;t^=-1;for(var s=i;s<r;s++)t=t>>>8^n[255&(t^e[s])];return-1^t}},{}],8:[function(t,e,a){"use strict";var l,_=t("../utils/common"),h=t("./trees"),u=t("./adler32"),c=t("./crc32"),i=t("./messages"),d=0,f=4,b=0,g=-2,m=-1,w=4,n=2,p=8,v=9,r=286,s=30,o=19,k=2*r+1,y=15,x=3,z=258,B=z+x+1,S=42,E=113,A=1,Z=2,R=3,C=4;function N(t,e){return t.msg=i[e],e}function O(t){return(t<<1)-(4<t?9:0)}function D(t){for(var e=t.length;0<=--e;)t[e]=0}function I(t){var e=t.state,a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(_.arraySet(t.output,e.pending_buf,e.pending_out,a,t.next_out),t.next_out+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))}function U(t,e){h._tr_flush_block(t,0<=t.block_start?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,I(t.strm)}function T(t,e){t.pending_buf[t.pending++]=e}function F(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function L(t,e){var a,i,n=t.max_chain_length,r=t.strstart,s=t.prev_length,o=t.nice_match,l=t.strstart>t.w_size-B?t.strstart-(t.w_size-B):0,h=t.window,d=t.w_mask,f=t.prev,_=t.strstart+z,u=h[r+s-1],c=h[r+s];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do{if(h[(a=e)+s]===c&&h[a+s-1]===u&&h[a]===h[r]&&h[++a]===h[r+1]){r+=2,a++;do{}while(h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&r<_);if(i=z-(_-r),r=_-z,s<i){if(t.match_start=e,o<=(s=i))break;u=h[r+s-1],c=h[r+s]}}}while((e=f[e&d])>l&&0!=--n);return s<=t.lookahead?s:t.lookahead}function H(t){var e,a,i,n,r,s,o,l,h,d,f=t.w_size;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=f+(f-B)){for(_.arraySet(t.window,t.window,f,f,0),t.match_start-=f,t.strstart-=f,t.block_start-=f,e=a=t.hash_size;i=t.head[--e],t.head[e]=f<=i?i-f:0,--a;);for(e=a=f;i=t.prev[--e],t.prev[e]=f<=i?i-f:0,--a;);n+=f}if(0===t.strm.avail_in)break;if(s=t.strm,o=t.window,l=t.strstart+t.lookahead,h=n,d=void 0,d=s.avail_in,h<d&&(d=h),a=0===d?0:(s.avail_in-=d,_.arraySet(o,s.input,s.next_in,d,l),1===s.state.wrap?s.adler=u(s.adler,o,d,l):2===s.state.wrap&&(s.adler=c(s.adler,o,d,l)),s.next_in+=d,s.total_in+=d,d),t.lookahead+=a,t.lookahead+t.insert>=x)for(r=t.strstart-t.insert,t.ins_h=t.window[r],t.ins_h=(t.ins_h<<t.hash_shift^t.window[r+1])&t.hash_mask;t.insert&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[r+x-1])&t.hash_mask,t.prev[r&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=r,r++,t.insert--,!(t.lookahead+t.insert<x)););}while(t.lookahead<B&&0!==t.strm.avail_in)}function j(t,e){for(var a,i;;){if(t.lookahead<B){if(H(t),t.lookahead<B&&e===d)return A;if(0===t.lookahead)break}if(a=0,t.lookahead>=x&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+x-1])&t.hash_mask,a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==a&&t.strstart-a<=t.w_size-B&&(t.match_length=L(t,a)),t.match_length>=x)if(i=h._tr_tally(t,t.strstart-t.match_start,t.match_length-x),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=x){for(t.match_length--;t.strstart++,t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+x-1])&t.hash_mask,a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart,0!=--t.match_length;);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+1])&t.hash_mask;else i=h._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(U(t,!1),0===t.strm.avail_out))return A}return t.insert=t.strstart<x-1?t.strstart:x-1,e===f?(U(t,!0),0===t.strm.avail_out?R:C):t.last_lit&&(U(t,!1),0===t.strm.avail_out)?A:Z}function K(t,e){for(var a,i,n;;){if(t.lookahead<B){if(H(t),t.lookahead<B&&e===d)return A;if(0===t.lookahead)break}if(a=0,t.lookahead>=x&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+x-1])&t.hash_mask,a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=x-1,0!==a&&t.prev_length<t.max_lazy_match&&t.strstart-a<=t.w_size-B&&(t.match_length=L(t,a),t.match_length<=5&&(1===t.strategy||t.match_length===x&&4096<t.strstart-t.match_start)&&(t.match_length=x-1)),t.prev_length>=x&&t.match_length<=t.prev_length){for(n=t.strstart+t.lookahead-x,i=h._tr_tally(t,t.strstart-1-t.prev_match,t.prev_length-x),t.lookahead-=t.prev_length-1,t.prev_length-=2;++t.strstart<=n&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+x-1])&t.hash_mask,a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!=--t.prev_length;);if(t.match_available=0,t.match_length=x-1,t.strstart++,i&&(U(t,!1),0===t.strm.avail_out))return A}else if(t.match_available){if((i=h._tr_tally(t,0,t.window[t.strstart-1]))&&U(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return A}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=h._tr_tally(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<x-1?t.strstart:x-1,e===f?(U(t,!0),0===t.strm.avail_out?R:C):t.last_lit&&(U(t,!1),0===t.strm.avail_out)?A:Z}function M(t,e,a,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=n}function P(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=p,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new _.Buf16(2*k),this.dyn_dtree=new _.Buf16(2*(2*s+1)),this.bl_tree=new _.Buf16(2*(2*o+1)),D(this.dyn_ltree),D(this.dyn_dtree),D(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new _.Buf16(y+1),this.heap=new _.Buf16(2*r+1),D(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new _.Buf16(2*r+1),D(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Y(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=n,(e=t.state).pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?S:E,t.adler=2===e.wrap?0:1,e.last_flush=d,h._tr_init(e),b):N(t,g)}function q(t){var e,a=Y(t);return a===b&&((e=t.state).window_size=2*e.w_size,D(e.head),e.max_lazy_match=l[e.level].max_lazy,e.good_match=l[e.level].good_length,e.nice_match=l[e.level].nice_length,e.max_chain_length=l[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=x-1,e.match_available=0,e.ins_h=0),a}function G(t,e,a,i,n,r){if(!t)return g;var s=1;if(e===m&&(e=6),i<0?(s=0,i=-i):15<i&&(s=2,i-=16),n<1||v<n||a!==p||i<8||15<i||e<0||9<e||r<0||w<r)return N(t,g);8===i&&(i=9);var o=new P;return(t.state=o).strm=t,o.wrap=s,o.gzhead=null,o.w_bits=i,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=n+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+x-1)/x),o.window=new _.Buf8(2*o.w_size),o.head=new _.Buf16(o.hash_size),o.prev=new _.Buf16(o.w_size),o.lit_bufsize=1<<n+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new _.Buf8(o.pending_buf_size),o.d_buf=1*o.lit_bufsize,o.l_buf=3*o.lit_bufsize,o.level=e,o.strategy=r,o.method=a,q(t)}l=[new M(0,0,0,0,function(t,e){var a=65535;for(a>t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(H(t),0===t.lookahead&&e===d)return A;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var i=t.block_start+a;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,U(t,!1),0===t.strm.avail_out))return A;if(t.strstart-t.block_start>=t.w_size-B&&(U(t,!1),0===t.strm.avail_out))return A}return t.insert=0,e===f?(U(t,!0),0===t.strm.avail_out?R:C):(t.strstart>t.block_start&&(U(t,!1),t.strm.avail_out),A)}),new M(4,4,8,4,j),new M(4,5,16,8,j),new M(4,6,32,32,j),new M(4,4,16,16,K),new M(8,16,32,32,K),new M(8,16,128,128,K),new M(8,32,128,256,K),new M(32,128,258,1024,K),new M(32,258,258,4096,K)],a.deflateInit=function(t,e){return G(t,e,p,15,8,0)},a.deflateInit2=G,a.deflateReset=q,a.deflateResetKeep=Y,a.deflateSetHeader=function(t,e){return t&&t.state?2!==t.state.wrap?g:(t.state.gzhead=e,b):g},a.deflate=function(t,e){var a,i,n,r;if(!t||!t.state||5<e||e<0)return t?N(t,g):g;if(i=t.state,!t.output||!t.input&&0!==t.avail_in||666===i.status&&e!==f)return N(t,0===t.avail_out?-5:g);if(i.strm=t,a=i.last_flush,i.last_flush=e,i.status===S)if(2===i.wrap)t.adler=0,T(i,31),T(i,139),T(i,8),i.gzhead?(T(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),T(i,255&i.gzhead.time),T(i,i.gzhead.time>>8&255),T(i,i.gzhead.time>>16&255),T(i,i.gzhead.time>>24&255),T(i,9===i.level?2:2<=i.strategy||i.level<2?4:0),T(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(T(i,255&i.gzhead.extra.length),T(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=c(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(T(i,0),T(i,0),T(i,0),T(i,0),T(i,0),T(i,9===i.level?2:2<=i.strategy||i.level<2?4:0),T(i,3),i.status=E);else{var s=p+(i.w_bits-8<<4)<<8;s|=(2<=i.strategy||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(s|=32),s+=31-s%31,i.status=E,F(i,s),0!==i.strstart&&(F(i,t.adler>>>16),F(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(n=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>n&&(t.adler=c(t.adler,i.pending_buf,i.pending-n,n)),I(t),n=i.pending,i.pending!==i.pending_buf_size));)T(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(t.adler=c(t.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=c(t.adler,i.pending_buf,i.pending-n,n)),I(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}T(i,r=i.gzindex<i.gzhead.name.length?255&i.gzhead.name.charCodeAt(i.gzindex++):0)}while(0!==r);i.gzhead.hcrc&&i.pending>n&&(t.adler=c(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=c(t.adler,i.pending_buf,i.pending-n,n)),I(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}T(i,r=i.gzindex<i.gzhead.comment.length?255&i.gzhead.comment.charCodeAt(i.gzindex++):0)}while(0!==r);i.gzhead.hcrc&&i.pending>n&&(t.adler=c(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.status=103)}else i.status=103;if(103===i.status&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&I(t),i.pending+2<=i.pending_buf_size&&(T(i,255&t.adler),T(i,t.adler>>8&255),t.adler=0,i.status=E)):i.status=E),0!==i.pending){if(I(t),0===t.avail_out)return i.last_flush=-1,b}else if(0===t.avail_in&&O(e)<=O(a)&&e!==f)return N(t,-5);if(666===i.status&&0!==t.avail_in)return N(t,-5);if(0!==t.avail_in||0!==i.lookahead||e!==d&&666!==i.status){var o=2===i.strategy?function(t,e){for(var a;;){if(0===t.lookahead&&(H(t),0===t.lookahead)){if(e===d)return A;break}if(t.match_length=0,a=h._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(U(t,!1),0===t.strm.avail_out))return A}return t.insert=0,e===f?(U(t,!0),0===t.strm.avail_out?R:C):t.last_lit&&(U(t,!1),0===t.strm.avail_out)?A:Z}(i,e):3===i.strategy?function(t,e){for(var a,i,n,r,s=t.window;;){if(t.lookahead<=z){if(H(t),t.lookahead<=z&&e===d)return A;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=x&&0<t.strstart&&(i=s[n=t.strstart-1])===s[++n]&&i===s[++n]&&i===s[++n]){r=t.strstart+z;do{}while(i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&n<r);t.match_length=z-(r-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=x?(a=h._tr_tally(t,1,t.match_length-x),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=h._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(U(t,!1),0===t.strm.avail_out))return A}return t.insert=0,e===f?(U(t,!0),0===t.strm.avail_out?R:C):t.last_lit&&(U(t,!1),0===t.strm.avail_out)?A:Z}(i,e):l[i.level].func(i,e);if(o!==R&&o!==C||(i.status=666),o===A||o===R)return 0===t.avail_out&&(i.last_flush=-1),b;if(o===Z&&(1===e?h._tr_align(i):5!==e&&(h._tr_stored_block(i,0,0,!1),3===e&&(D(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),I(t),0===t.avail_out))return i.last_flush=-1,b}return e!==f?b:i.wrap<=0?1:(2===i.wrap?(T(i,255&t.adler),T(i,t.adler>>8&255),T(i,t.adler>>16&255),T(i,t.adler>>24&255),T(i,255&t.total_in),T(i,t.total_in>>8&255),T(i,t.total_in>>16&255),T(i,t.total_in>>24&255)):(F(i,t.adler>>>16),F(i,65535&t.adler)),I(t),0<i.wrap&&(i.wrap=-i.wrap),0!==i.pending?b:1)},a.deflateEnd=function(t){var e;return t&&t.state?(e=t.state.status)!==S&&69!==e&&73!==e&&91!==e&&103!==e&&e!==E&&666!==e?N(t,g):(t.state=null,e===E?N(t,-3):b):g},a.deflateSetDictionary=function(t,e){var a,i,n,r,s,o,l,h,d=e.length;if(!t||!t.state)return g;if(2===(r=(a=t.state).wrap)||1===r&&a.status!==S||a.lookahead)return g;for(1===r&&(t.adler=u(t.adler,e,d,0)),a.wrap=0,d>=a.w_size&&(0===r&&(D(a.head),a.strstart=0,a.block_start=0,a.insert=0),h=new _.Buf8(a.w_size),_.arraySet(h,e,d-a.w_size,a.w_size,0),e=h,d=a.w_size),s=t.avail_in,o=t.next_in,l=t.input,t.avail_in=d,t.next_in=0,t.input=e,H(a);a.lookahead>=x;){for(i=a.strstart,n=a.lookahead-(x-1);a.ins_h=(a.ins_h<<a.hash_shift^a.window[i+x-1])&a.hash_mask,a.prev[i&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=i,i++,--n;);a.strstart=i,a.lookahead=x-1,H(a)}return a.strstart+=a.lookahead,a.block_start=a.strstart,a.insert=a.lookahead,a.lookahead=0,a.match_length=a.prev_length=x-1,a.match_available=0,t.next_in=o,t.input=l,t.avail_in=s,a.wrap=r,b},a.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":3,"./adler32":5,"./crc32":7,"./messages":13,"./trees":14}],9:[function(t,e,a){"use strict";e.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],10:[function(t,e,a){"use strict";e.exports=function(t,e){var a,i,n,r,s,o,l,h,d,f,_,u,c,b,g,m,w,p,v,k,y,x,z,B,S;a=t.state,i=t.next_in,B=t.input,n=i+(t.avail_in-5),r=t.next_out,S=t.output,s=r-(e-t.avail_out),o=r+(t.avail_out-257),l=a.dmax,h=a.wsize,d=a.whave,f=a.wnext,_=a.window,u=a.hold,c=a.bits,b=a.lencode,g=a.distcode,m=(1<<a.lenbits)-1,w=(1<<a.distbits)-1;t:do{c<15&&(u+=B[i++]<<c,c+=8,u+=B[i++]<<c,c+=8),p=b[u&m];e:for(;;){if(u>>>=v=p>>>24,c-=v,0===(v=p>>>16&255))S[r++]=65535&p;else{if(!(16&v)){if(0==(64&v)){p=b[(65535&p)+(u&(1<<v)-1)];continue e}if(32&v){a.mode=12;break t}t.msg="invalid literal/length code",a.mode=30;break t}k=65535&p,(v&=15)&&(c<v&&(u+=B[i++]<<c,c+=8),k+=u&(1<<v)-1,u>>>=v,c-=v),c<15&&(u+=B[i++]<<c,c+=8,u+=B[i++]<<c,c+=8),p=g[u&w];a:for(;;){if(u>>>=v=p>>>24,c-=v,!(16&(v=p>>>16&255))){if(0==(64&v)){p=g[(65535&p)+(u&(1<<v)-1)];continue a}t.msg="invalid distance code",a.mode=30;break t}if(y=65535&p,c<(v&=15)&&(u+=B[i++]<<c,(c+=8)<v&&(u+=B[i++]<<c,c+=8)),l<(y+=u&(1<<v)-1)){t.msg="invalid distance too far back",a.mode=30;break t}if(u>>>=v,c-=v,(v=r-s)<y){if(d<(v=y-v)&&a.sane){t.msg="invalid distance too far back",a.mode=30;break t}if(z=_,(x=0)===f){if(x+=h-v,v<k){for(k-=v;S[r++]=_[x++],--v;);x=r-y,z=S}}else if(f<v){if(x+=h+f-v,(v-=f)<k){for(k-=v;S[r++]=_[x++],--v;);if(x=0,f<k){for(k-=v=f;S[r++]=_[x++],--v;);x=r-y,z=S}}}else if(x+=f-v,v<k){for(k-=v;S[r++]=_[x++],--v;);x=r-y,z=S}for(;2<k;)S[r++]=z[x++],S[r++]=z[x++],S[r++]=z[x++],k-=3;k&&(S[r++]=z[x++],1<k&&(S[r++]=z[x++]))}else{for(x=r-y;S[r++]=S[x++],S[r++]=S[x++],S[r++]=S[x++],2<(k-=3););k&&(S[r++]=S[x++],1<k&&(S[r++]=S[x++]))}break}}break}}while(i<n&&r<o);i-=k=c>>3,u&=(1<<(c-=k<<3))-1,t.next_in=i,t.next_out=r,t.avail_in=i<n?n-i+5:5-(i-n),t.avail_out=r<o?o-r+257:257-(r-o),a.hold=u,a.bits=c}},{}],11:[function(t,e,a){"use strict";var Z=t("../utils/common"),R=t("./adler32"),C=t("./crc32"),N=t("./inffast"),O=t("./inftrees"),D=1,I=2,U=0,T=-2,F=1,i=852,n=592;function L(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)}function r(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Z.Buf16(320),this.work=new Z.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function s(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=F,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Z.Buf32(i),e.distcode=e.distdyn=new Z.Buf32(n),e.sane=1,e.back=-1,U):T}function o(t){var e;return t&&t.state?((e=t.state).wsize=0,e.whave=0,e.wnext=0,s(t)):T}function l(t,e){var a,i;return t&&t.state?(i=t.state,e<0?(a=0,e=-e):(a=1+(e>>4),e<48&&(e&=15)),e&&(e<8||15<e)?T:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=a,i.wbits=e,o(t))):T}function h(t,e){var a,i;return t?(i=new r,(t.state=i).window=null,(a=l(t,e))!==U&&(t.state=null),a):T}var d,f,_=!0;function H(t){if(_){var e;for(d=new Z.Buf32(512),f=new Z.Buf32(32),e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(O(D,t.lens,0,288,d,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;O(I,t.lens,0,32,f,0,t.work,{bits:5}),_=!1}t.lencode=d,t.lenbits=9,t.distcode=f,t.distbits=5}function j(t,e,a,i){var n,r=t.state;return null===r.window&&(r.wsize=1<<r.wbits,r.wnext=0,r.whave=0,r.window=new Z.Buf8(r.wsize)),i>=r.wsize?(Z.arraySet(r.window,e,a-r.wsize,r.wsize,0),r.wnext=0,r.whave=r.wsize):(i<(n=r.wsize-r.wnext)&&(n=i),Z.arraySet(r.window,e,a-i,n,r.wnext),(i-=n)?(Z.arraySet(r.window,e,a-i,i,0),r.wnext=i,r.whave=r.wsize):(r.wnext+=n,r.wnext===r.wsize&&(r.wnext=0),r.whave<r.wsize&&(r.whave+=n))),0}a.inflateReset=o,a.inflateReset2=l,a.inflateResetKeep=s,a.inflateInit=function(t){return h(t,15)},a.inflateInit2=h,a.inflate=function(t,e){var a,i,n,r,s,o,l,h,d,f,_,u,c,b,g,m,w,p,v,k,y,x,z,B,S=0,E=new Z.Buf8(4),A=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return T;12===(a=t.state).mode&&(a.mode=13),s=t.next_out,n=t.output,l=t.avail_out,r=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,f=o,_=l,x=U;t:for(;;)switch(a.mode){case F:if(0===a.wrap){a.mode=13;break}for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(2&a.wrap&&35615===h){E[a.check=0]=255&h,E[1]=h>>>8&255,a.check=C(a.check,E,2,0),d=h=0,a.mode=2;break}if(a.flags=0,a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",a.mode=30;break}if(8!=(15&h)){t.msg="unknown compression method",a.mode=30;break}if(d-=4,y=8+(15&(h>>>=4)),0===a.wbits)a.wbits=y;else if(y>a.wbits){t.msg="invalid window size",a.mode=30;break}a.dmax=1<<y,t.adler=a.check=1,a.mode=512&h?10:12,d=h=0;break;case 2:for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(a.flags=h,8!=(255&a.flags)){t.msg="unknown compression method",a.mode=30;break}if(57344&a.flags){t.msg="unknown header flags set",a.mode=30;break}a.head&&(a.head.text=h>>8&1),512&a.flags&&(E[0]=255&h,E[1]=h>>>8&255,a.check=C(a.check,E,2,0)),d=h=0,a.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.head&&(a.head.time=h),512&a.flags&&(E[0]=255&h,E[1]=h>>>8&255,E[2]=h>>>16&255,E[3]=h>>>24&255,a.check=C(a.check,E,4,0)),d=h=0,a.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.head&&(a.head.xflags=255&h,a.head.os=h>>8),512&a.flags&&(E[0]=255&h,E[1]=h>>>8&255,a.check=C(a.check,E,2,0)),d=h=0,a.mode=5;case 5:if(1024&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.length=h,a.head&&(a.head.extra_len=h),512&a.flags&&(E[0]=255&h,E[1]=h>>>8&255,a.check=C(a.check,E,2,0)),d=h=0}else a.head&&(a.head.extra=null);a.mode=6;case 6:if(1024&a.flags&&(o<(u=a.length)&&(u=o),u&&(a.head&&(y=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Array(a.head.extra_len)),Z.arraySet(a.head.extra,i,r,u,y)),512&a.flags&&(a.check=C(a.check,i,u,r)),o-=u,r+=u,a.length-=u),a.length))break t;a.length=0,a.mode=7;case 7:if(2048&a.flags){if(0===o)break t;for(u=0;y=i[r+u++],a.head&&y&&a.length<65536&&(a.head.name+=String.fromCharCode(y)),y&&u<o;);if(512&a.flags&&(a.check=C(a.check,i,u,r)),o-=u,r+=u,y)break t}else a.head&&(a.head.name=null);a.length=0,a.mode=8;case 8:if(4096&a.flags){if(0===o)break t;for(u=0;y=i[r+u++],a.head&&y&&a.length<65536&&(a.head.comment+=String.fromCharCode(y)),y&&u<o;);if(512&a.flags&&(a.check=C(a.check,i,u,r)),o-=u,r+=u,y)break t}else a.head&&(a.head.comment=null);a.mode=9;case 9:if(512&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(h!==(65535&a.check)){t.msg="header crc mismatch",a.mode=30;break}d=h=0}a.head&&(a.head.hcrc=a.flags>>9&1,a.head.done=!0),t.adler=a.check=0,a.mode=12;break;case 10:for(;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}t.adler=a.check=L(h),d=h=0,a.mode=11;case 11:if(0===a.havedict)return t.next_out=s,t.avail_out=l,t.next_in=r,t.avail_in=o,a.hold=h,a.bits=d,2;t.adler=a.check=1,a.mode=12;case 12:if(5===e||6===e)break t;case 13:if(a.last){h>>>=7&d,d-=7&d,a.mode=27;break}for(;d<3;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}switch(a.last=1&h,d-=1,3&(h>>>=1)){case 0:a.mode=14;break;case 1:if(H(a),a.mode=20,6!==e)break;h>>>=2,d-=2;break t;case 2:a.mode=17;break;case 3:t.msg="invalid block type",a.mode=30}h>>>=2,d-=2;break;case 14:for(h>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if((65535&h)!=(h>>>16^65535)){t.msg="invalid stored block lengths",a.mode=30;break}if(a.length=65535&h,d=h=0,a.mode=15,6===e)break t;case 15:a.mode=16;case 16:if(u=a.length){if(o<u&&(u=o),l<u&&(u=l),0===u)break t;Z.arraySet(n,i,r,u,s),o-=u,r+=u,l-=u,s+=u,a.length-=u;break}a.mode=12;break;case 17:for(;d<14;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(a.nlen=257+(31&h),h>>>=5,d-=5,a.ndist=1+(31&h),h>>>=5,d-=5,a.ncode=4+(15&h),h>>>=4,d-=4,286<a.nlen||30<a.ndist){t.msg="too many length or distance symbols",a.mode=30;break}a.have=0,a.mode=18;case 18:for(;a.have<a.ncode;){for(;d<3;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.lens[A[a.have++]]=7&h,h>>>=3,d-=3}for(;a.have<19;)a.lens[A[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,z={bits:a.lenbits},x=O(0,a.lens,0,19,a.lencode,0,a.work,z),a.lenbits=z.bits,x){t.msg="invalid code lengths set",a.mode=30;break}a.have=0,a.mode=19;case 19:for(;a.have<a.nlen+a.ndist;){for(;m=(S=a.lencode[h&(1<<a.lenbits)-1])>>>16&255,w=65535&S,!((g=S>>>24)<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(w<16)h>>>=g,d-=g,a.lens[a.have++]=w;else{if(16===w){for(B=g+2;d<B;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(h>>>=g,d-=g,0===a.have){t.msg="invalid bit length repeat",a.mode=30;break}y=a.lens[a.have-1],u=3+(3&h),h>>>=2,d-=2}else if(17===w){for(B=g+3;d<B;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}d-=g,y=0,u=3+(7&(h>>>=g)),h>>>=3,d-=3}else{for(B=g+7;d<B;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}d-=g,y=0,u=11+(127&(h>>>=g)),h>>>=7,d-=7}if(a.have+u>a.nlen+a.ndist){t.msg="invalid bit length repeat",a.mode=30;break}for(;u--;)a.lens[a.have++]=y}}if(30===a.mode)break;if(0===a.lens[256]){t.msg="invalid code -- missing end-of-block",a.mode=30;break}if(a.lenbits=9,z={bits:a.lenbits},x=O(D,a.lens,0,a.nlen,a.lencode,0,a.work,z),a.lenbits=z.bits,x){t.msg="invalid literal/lengths set",a.mode=30;break}if(a.distbits=6,a.distcode=a.distdyn,z={bits:a.distbits},x=O(I,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,z),a.distbits=z.bits,x){t.msg="invalid distances set",a.mode=30;break}if(a.mode=20,6===e)break t;case 20:a.mode=21;case 21:if(6<=o&&258<=l){t.next_out=s,t.avail_out=l,t.next_in=r,t.avail_in=o,a.hold=h,a.bits=d,N(t,_),s=t.next_out,n=t.output,l=t.avail_out,r=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,12===a.mode&&(a.back=-1);break}for(a.back=0;m=(S=a.lencode[h&(1<<a.lenbits)-1])>>>16&255,w=65535&S,!((g=S>>>24)<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(m&&0==(240&m)){for(p=g,v=m,k=w;m=(S=a.lencode[k+((h&(1<<p+v)-1)>>p)])>>>16&255,w=65535&S,!(p+(g=S>>>24)<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=p,d-=p,a.back+=p}if(h>>>=g,d-=g,a.back+=g,a.length=w,0===m){a.mode=26;break}if(32&m){a.back=-1,a.mode=12;break}if(64&m){t.msg="invalid literal/length code",a.mode=30;break}a.extra=15&m,a.mode=22;case 22:if(a.extra){for(B=a.extra;d<B;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.length+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=23;case 23:for(;m=(S=a.distcode[h&(1<<a.distbits)-1])>>>16&255,w=65535&S,!((g=S>>>24)<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(0==(240&m)){for(p=g,v=m,k=w;m=(S=a.distcode[k+((h&(1<<p+v)-1)>>p)])>>>16&255,w=65535&S,!(p+(g=S>>>24)<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=p,d-=p,a.back+=p}if(h>>>=g,d-=g,a.back+=g,64&m){t.msg="invalid distance code",a.mode=30;break}a.offset=w,a.extra=15&m,a.mode=24;case 24:if(a.extra){for(B=a.extra;d<B;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.offset+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){t.msg="invalid distance too far back",a.mode=30;break}a.mode=25;case 25:if(0===l)break t;if(u=_-l,a.offset>u){if((u=a.offset-u)>a.whave&&a.sane){t.msg="invalid distance too far back",a.mode=30;break}u>a.wnext?(u-=a.wnext,c=a.wsize-u):c=a.wnext-u,u>a.length&&(u=a.length),b=a.window}else b=n,c=s-a.offset,u=a.length;for(l<u&&(u=l),l-=u,a.length-=u;n[s++]=b[c++],--u;);0===a.length&&(a.mode=21);break;case 26:if(0===l)break t;n[s++]=a.length,l--,a.mode=21;break;case 27:if(a.wrap){for(;d<32;){if(0===o)break t;o--,h|=i[r++]<<d,d+=8}if(_-=l,t.total_out+=_,a.total+=_,_&&(t.adler=a.check=a.flags?C(a.check,n,_,s-_):R(a.check,n,_,s-_)),_=l,(a.flags?h:L(h))!==a.check){t.msg="incorrect data check",a.mode=30;break}d=h=0}a.mode=28;case 28:if(a.wrap&&a.flags){for(;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(h!==(4294967295&a.total)){t.msg="incorrect length check",a.mode=30;break}d=h=0}a.mode=29;case 29:x=1;break t;case 30:x=-3;break t;case 31:return-4;case 32:default:return T}return t.next_out=s,t.avail_out=l,t.next_in=r,t.avail_in=o,a.hold=h,a.bits=d,(a.wsize||_!==t.avail_out&&a.mode<30&&(a.mode<27||4!==e))&&j(t,t.output,t.next_out,_-t.avail_out)?(a.mode=31,-4):(f-=t.avail_in,_-=t.avail_out,t.total_in+=f,t.total_out+=_,a.total+=_,a.wrap&&_&&(t.adler=a.check=a.flags?C(a.check,n,_,t.next_out-_):R(a.check,n,_,t.next_out-_)),t.data_type=a.bits+(a.last?64:0)+(12===a.mode?128:0)+(20===a.mode||15===a.mode?256:0),(0===f&&0===_||4===e)&&x===U&&(x=-5),x)},a.inflateEnd=function(t){if(!t||!t.state)return T;var e=t.state;return e.window&&(e.window=null),t.state=null,U},a.inflateGetHeader=function(t,e){var a;return t&&t.state?0==(2&(a=t.state).wrap)?T:((a.head=e).done=!1,U):T},a.inflateSetDictionary=function(t,e){var a,i=e.length;return t&&t.state?0!==(a=t.state).wrap&&11!==a.mode?T:11===a.mode&&R(1,e,i,0)!==a.check?-3:j(t,e,i,i)?(a.mode=31,-4):(a.havedict=1,U):T},a.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":3,"./adler32":5,"./crc32":7,"./inffast":10,"./inftrees":12}],12:[function(t,e,a){"use strict";var D=t("../utils/common"),I=[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,0,0],U=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],T=[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,0,0],F=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];e.exports=function(t,e,a,i,n,r,s,o){var l,h,d,f,_,u,c,b,g,m=o.bits,w=0,p=0,v=0,k=0,y=0,x=0,z=0,B=0,S=0,E=0,A=null,Z=0,R=new D.Buf16(16),C=new D.Buf16(16),N=null,O=0;for(w=0;w<=15;w++)R[w]=0;for(p=0;p<i;p++)R[e[a+p]]++;for(y=m,k=15;1<=k&&0===R[k];k--);if(k<y&&(y=k),0===k)return n[r++]=20971520,n[r++]=20971520,o.bits=1,0;for(v=1;v<k&&0===R[v];v++);for(y<v&&(y=v),w=B=1;w<=15;w++)if(B<<=1,(B-=R[w])<0)return-1;if(0<B&&(0===t||1!==k))return-1;for(C[1]=0,w=1;w<15;w++)C[w+1]=C[w]+R[w];for(p=0;p<i;p++)0!==e[a+p]&&(s[C[e[a+p]]++]=p);if(0===t?(A=N=s,u=19):1===t?(A=I,Z-=257,N=U,O-=257,u=256):(A=T,N=F,u=-1),w=v,_=r,z=p=E=0,d=-1,f=(S=1<<(x=y))-1,1===t&&852<S||2===t&&592<S)return 1;for(;;){for(c=w-z,s[p]<u?(b=0,g=s[p]):s[p]>u?(b=N[O+s[p]],g=A[Z+s[p]]):(b=96,g=0),l=1<<w-z,v=h=1<<x;n[_+(E>>z)+(h-=l)]=c<<24|b<<16|g|0,0!==h;);for(l=1<<w-1;E&l;)l>>=1;if(0!==l?(E&=l-1,E+=l):E=0,p++,0==--R[w]){if(w===k)break;w=e[a+s[p]]}if(y<w&&(E&f)!==d){for(0===z&&(z=y),_+=v,B=1<<(x=w-z);x+z<k&&!((B-=R[x+z])<=0);)x++,B<<=1;if(S+=1<<x,1===t&&852<S||2===t&&592<S)return 1;n[d=E&f]=y<<24|x<<16|_-r|0}}return 0!==E&&(n[_+E]=w-z<<24|64<<16|0),o.bits=y,0}},{"../utils/common":3}],13:[function(t,e,a){"use strict";e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],14:[function(t,e,a){"use strict";var l=t("../utils/common"),o=0,h=1;function i(t){for(var e=t.length;0<=--e;)t[e]=0}var d=0,s=29,f=256,_=f+1+s,u=30,c=19,g=2*_+1,m=15,n=16,b=7,w=256,p=16,v=17,k=18,y=[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],x=[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,13,13],z=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],B=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S=new Array(2*(_+2));i(S);var E=new Array(2*u);i(E);var A=new Array(512);i(A);var Z=new Array(256);i(Z);var R=new Array(s);i(R);var C,N,O,D=new Array(u);function I(t,e,a,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}function r(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}function U(t){return t<256?A[t]:A[256+(t>>>7)]}function T(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function F(t,e,a){t.bi_valid>n-a?(t.bi_buf|=e<<t.bi_valid&65535,T(t,t.bi_buf),t.bi_buf=e>>n-t.bi_valid,t.bi_valid+=a-n):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=a)}function L(t,e,a){F(t,a[2*e],a[2*e+1])}function H(t,e){for(var a=0;a|=1&t,t>>>=1,a<<=1,0<--e;);return a>>>1}function j(t,e,a){var i,n,r=new Array(m+1),s=0;for(i=1;i<=m;i++)r[i]=s=s+a[i-1]<<1;for(n=0;n<=e;n++){var o=t[2*n+1];0!==o&&(t[2*n]=H(r[o]++,o))}}function K(t){var e;for(e=0;e<_;e++)t.dyn_ltree[2*e]=0;for(e=0;e<u;e++)t.dyn_dtree[2*e]=0;for(e=0;e<c;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*w]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function M(t){8<t.bi_valid?T(t,t.bi_buf):0<t.bi_valid&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function P(t,e,a,i){var n=2*e,r=2*a;return t[n]<t[r]||t[n]===t[r]&&i[e]<=i[a]}function Y(t,e,a){for(var i=t.heap[a],n=a<<1;n<=t.heap_len&&(n<t.heap_len&&P(e,t.heap[n+1],t.heap[n],t.depth)&&n++,!P(e,i,t.heap[n],t.depth));)t.heap[a]=t.heap[n],a=n,n<<=1;t.heap[a]=i}function q(t,e,a){var i,n,r,s,o=0;if(0!==t.last_lit)for(;i=t.pending_buf[t.d_buf+2*o]<<8|t.pending_buf[t.d_buf+2*o+1],n=t.pending_buf[t.l_buf+o],o++,0===i?L(t,n,e):(L(t,(r=Z[n])+f+1,e),0!==(s=y[r])&&F(t,n-=R[r],s),L(t,r=U(--i),a),0!==(s=x[r])&&F(t,i-=D[r],s)),o<t.last_lit;);L(t,w,e)}function G(t,e){var a,i,n,r=e.dyn_tree,s=e.stat_desc.static_tree,o=e.stat_desc.has_stree,l=e.stat_desc.elems,h=-1;for(t.heap_len=0,t.heap_max=g,a=0;a<l;a++)0!==r[2*a]?(t.heap[++t.heap_len]=h=a,t.depth[a]=0):r[2*a+1]=0;for(;t.heap_len<2;)r[2*(n=t.heap[++t.heap_len]=h<2?++h:0)]=1,t.depth[n]=0,t.opt_len--,o&&(t.static_len-=s[2*n+1]);for(e.max_code=h,a=t.heap_len>>1;1<=a;a--)Y(t,r,a);for(n=l;a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],Y(t,r,1),i=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=i,r[2*n]=r[2*a]+r[2*i],t.depth[n]=(t.depth[a]>=t.depth[i]?t.depth[a]:t.depth[i])+1,r[2*a+1]=r[2*i+1]=n,t.heap[1]=n++,Y(t,r,1),2<=t.heap_len;);t.heap[--t.heap_max]=t.heap[1],function(t,e){var a,i,n,r,s,o,l=e.dyn_tree,h=e.max_code,d=e.stat_desc.static_tree,f=e.stat_desc.has_stree,_=e.stat_desc.extra_bits,u=e.stat_desc.extra_base,c=e.stat_desc.max_length,b=0;for(r=0;r<=m;r++)t.bl_count[r]=0;for(l[2*t.heap[t.heap_max]+1]=0,a=t.heap_max+1;a<g;a++)c<(r=l[2*l[2*(i=t.heap[a])+1]+1]+1)&&(r=c,b++),l[2*i+1]=r,h<i||(t.bl_count[r]++,s=0,u<=i&&(s=_[i-u]),o=l[2*i],t.opt_len+=o*(r+s),f&&(t.static_len+=o*(d[2*i+1]+s)));if(0!==b){do{for(r=c-1;0===t.bl_count[r];)r--;t.bl_count[r]--,t.bl_count[r+1]+=2,t.bl_count[c]--,b-=2}while(0<b);for(r=c;0!==r;r--)for(i=t.bl_count[r];0!==i;)h<(n=t.heap[--a])||(l[2*n+1]!==r&&(t.opt_len+=(r-l[2*n+1])*l[2*n],l[2*n+1]=r),i--)}}(t,e),j(r,h,t.bl_count)}function X(t,e,a){var i,n,r=-1,s=e[1],o=0,l=7,h=4;for(0===s&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;i<=a;i++)n=s,s=e[2*(i+1)+1],++o<l&&n===s||(o<h?t.bl_tree[2*n]+=o:0!==n?(n!==r&&t.bl_tree[2*n]++,t.bl_tree[2*p]++):o<=10?t.bl_tree[2*v]++:t.bl_tree[2*k]++,r=n,(o=0)===s?(l=138,h=3):n===s?(l=6,h=3):(l=7,h=4))}function W(t,e,a){var i,n,r=-1,s=e[1],o=0,l=7,h=4;for(0===s&&(l=138,h=3),i=0;i<=a;i++)if(n=s,s=e[2*(i+1)+1],!(++o<l&&n===s)){if(o<h)for(;L(t,n,t.bl_tree),0!=--o;);else 0!==n?(n!==r&&(L(t,n,t.bl_tree),o--),L(t,p,t.bl_tree),F(t,o-3,2)):o<=10?(L(t,v,t.bl_tree),F(t,o-3,3)):(L(t,k,t.bl_tree),F(t,o-11,7));r=n,(o=0)===s?(l=138,h=3):n===s?(l=6,h=3):(l=7,h=4)}}i(D);var J=!1;function Q(t,e,a,i){var n,r,s,o;F(t,(d<<1)+(i?1:0),3),r=e,s=a,o=!0,M(n=t),o&&(T(n,s),T(n,~s)),l.arraySet(n.pending_buf,n.window,r,s,n.pending),n.pending+=s}a._tr_init=function(t){J||(function(){var t,e,a,i,n,r=new Array(m+1);for(i=a=0;i<s-1;i++)for(R[i]=a,t=0;t<1<<y[i];t++)Z[a++]=i;for(Z[a-1]=i,i=n=0;i<16;i++)for(D[i]=n,t=0;t<1<<x[i];t++)A[n++]=i;for(n>>=7;i<u;i++)for(D[i]=n<<7,t=0;t<1<<x[i]-7;t++)A[256+n++]=i;for(e=0;e<=m;e++)r[e]=0;for(t=0;t<=143;)S[2*t+1]=8,t++,r[8]++;for(;t<=255;)S[2*t+1]=9,t++,r[9]++;for(;t<=279;)S[2*t+1]=7,t++,r[7]++;for(;t<=287;)S[2*t+1]=8,t++,r[8]++;for(j(S,_+1,r),t=0;t<u;t++)E[2*t+1]=5,E[2*t]=H(t,5);C=new I(S,y,f+1,_,m),N=new I(E,x,0,u,m),O=new I(new Array(0),z,0,c,b)}(),J=!0),t.l_desc=new r(t.dyn_ltree,C),t.d_desc=new r(t.dyn_dtree,N),t.bl_desc=new r(t.bl_tree,O),t.bi_buf=0,t.bi_valid=0,K(t)},a._tr_stored_block=Q,a._tr_flush_block=function(t,e,a,i){var n,r,s=0;0<t.level?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,a=4093624447;for(e=0;e<=31;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return o;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return h;for(e=32;e<f;e++)if(0!==t.dyn_ltree[2*e])return h;return o}(t)),G(t,t.l_desc),G(t,t.d_desc),s=function(t){var e;for(X(t,t.dyn_ltree,t.l_desc.max_code),X(t,t.dyn_dtree,t.d_desc.max_code),G(t,t.bl_desc),e=c-1;3<=e&&0===t.bl_tree[2*B[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),n=t.opt_len+3+7>>>3,(r=t.static_len+3+7>>>3)<=n&&(n=r)):n=r=a+5,a+4<=n&&-1!==e?Q(t,e,a,i):4===t.strategy||r===n?(F(t,2+(i?1:0),3),q(t,S,E)):(F(t,4+(i?1:0),3),function(t,e,a,i){var n;for(F(t,e-257,5),F(t,a-1,5),F(t,i-4,4),n=0;n<i;n++)F(t,t.bl_tree[2*B[n]+1],3);W(t,t.dyn_ltree,e-1),W(t,t.dyn_dtree,a-1)}(t,t.l_desc.max_code+1,t.d_desc.max_code+1,s+1),q(t,t.dyn_ltree,t.dyn_dtree)),K(t),i&&M(t)},a._tr_tally=function(t,e,a){return t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(Z[a]+f+1)]++,t.dyn_dtree[2*U(e)]++),t.last_lit===t.lit_bufsize-1},a._tr_align=function(t){var e;F(t,2,3),L(t,w,S),16===(e=t).bi_valid?(T(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}},{"../utils/common":3}],15:[function(t,e,a){"use strict";e.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],"/":[function(t,e,a){"use strict";var i={};(0,t("./lib/utils/common").assign)(i,t("./lib/deflate"),t("./lib/inflate"),t("./lib/zlib/constants")),e.exports=i},{"./lib/deflate":1,"./lib/inflate":2,"./lib/utils/common":3,"./lib/zlib/constants":6}]},{},[])("/")});
@@ -0,0 +1,3997 @@
1
+ /* pako 1.0.11 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
+ 'use strict';
3
+
4
+
5
+ var TYPED_OK = (typeof Uint8Array !== 'undefined') &&
6
+ (typeof Uint16Array !== 'undefined') &&
7
+ (typeof Int32Array !== 'undefined');
8
+
9
+ function _has(obj, key) {
10
+ return Object.prototype.hasOwnProperty.call(obj, key);
11
+ }
12
+
13
+ exports.assign = function (obj /*from1, from2, from3, ...*/) {
14
+ var sources = Array.prototype.slice.call(arguments, 1);
15
+ while (sources.length) {
16
+ var source = sources.shift();
17
+ if (!source) { continue; }
18
+
19
+ if (typeof source !== 'object') {
20
+ throw new TypeError(source + 'must be non-object');
21
+ }
22
+
23
+ for (var p in source) {
24
+ if (_has(source, p)) {
25
+ obj[p] = source[p];
26
+ }
27
+ }
28
+ }
29
+
30
+ return obj;
31
+ };
32
+
33
+
34
+ // reduce buffer size, avoiding mem copy
35
+ exports.shrinkBuf = function (buf, size) {
36
+ if (buf.length === size) { return buf; }
37
+ if (buf.subarray) { return buf.subarray(0, size); }
38
+ buf.length = size;
39
+ return buf;
40
+ };
41
+
42
+
43
+ var fnTyped = {
44
+ arraySet: function (dest, src, src_offs, len, dest_offs) {
45
+ if (src.subarray && dest.subarray) {
46
+ dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
47
+ return;
48
+ }
49
+ // Fallback to ordinary array
50
+ for (var i = 0; i < len; i++) {
51
+ dest[dest_offs + i] = src[src_offs + i];
52
+ }
53
+ },
54
+ // Join array of chunks to single array.
55
+ flattenChunks: function (chunks) {
56
+ var i, l, len, pos, chunk, result;
57
+
58
+ // calculate data length
59
+ len = 0;
60
+ for (i = 0, l = chunks.length; i < l; i++) {
61
+ len += chunks[i].length;
62
+ }
63
+
64
+ // join chunks
65
+ result = new Uint8Array(len);
66
+ pos = 0;
67
+ for (i = 0, l = chunks.length; i < l; i++) {
68
+ chunk = chunks[i];
69
+ result.set(chunk, pos);
70
+ pos += chunk.length;
71
+ }
72
+
73
+ return result;
74
+ }
75
+ };
76
+
77
+ var fnUntyped = {
78
+ arraySet: function (dest, src, src_offs, len, dest_offs) {
79
+ for (var i = 0; i < len; i++) {
80
+ dest[dest_offs + i] = src[src_offs + i];
81
+ }
82
+ },
83
+ // Join array of chunks to single array.
84
+ flattenChunks: function (chunks) {
85
+ return [].concat.apply([], chunks);
86
+ }
87
+ };
88
+
89
+
90
+ // Enable/Disable typed arrays use, for testing
91
+ //
92
+ exports.setTyped = function (on) {
93
+ if (on) {
94
+ exports.Buf8 = Uint8Array;
95
+ exports.Buf16 = Uint16Array;
96
+ exports.Buf32 = Int32Array;
97
+ exports.assign(exports, fnTyped);
98
+ } else {
99
+ exports.Buf8 = Array;
100
+ exports.Buf16 = Array;
101
+ exports.Buf32 = Array;
102
+ exports.assign(exports, fnUntyped);
103
+ }
104
+ };
105
+
106
+ exports.setTyped(TYPED_OK);
107
+
108
+ },{}],2:[function(require,module,exports){
109
+ // String encode/decode helpers
110
+ 'use strict';
111
+
112
+
113
+ var utils = require('./common');
114
+
115
+
116
+ // Quick check if we can use fast array to bin string conversion
117
+ //
118
+ // - apply(Array) can fail on Android 2.2
119
+ // - apply(Uint8Array) can fail on iOS 5.1 Safari
120
+ //
121
+ var STR_APPLY_OK = true;
122
+ var STR_APPLY_UIA_OK = true;
123
+
124
+ try { String.fromCharCode.apply(null, [ 0 ]); } catch (__) { STR_APPLY_OK = false; }
125
+ try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; }
126
+
127
+
128
+ // Table with utf8 lengths (calculated by first byte of sequence)
129
+ // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
130
+ // because max possible codepoint is 0x10ffff
131
+ var _utf8len = new utils.Buf8(256);
132
+ for (var q = 0; q < 256; q++) {
133
+ _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
134
+ }
135
+ _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
136
+
137
+
138
+ // convert string to array (typed, when possible)
139
+ exports.string2buf = function (str) {
140
+ var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
141
+
142
+ // count binary size
143
+ for (m_pos = 0; m_pos < str_len; m_pos++) {
144
+ c = str.charCodeAt(m_pos);
145
+ if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
146
+ c2 = str.charCodeAt(m_pos + 1);
147
+ if ((c2 & 0xfc00) === 0xdc00) {
148
+ c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
149
+ m_pos++;
150
+ }
151
+ }
152
+ buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
153
+ }
154
+
155
+ // allocate buffer
156
+ buf = new utils.Buf8(buf_len);
157
+
158
+ // convert
159
+ for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
160
+ c = str.charCodeAt(m_pos);
161
+ if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
162
+ c2 = str.charCodeAt(m_pos + 1);
163
+ if ((c2 & 0xfc00) === 0xdc00) {
164
+ c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
165
+ m_pos++;
166
+ }
167
+ }
168
+ if (c < 0x80) {
169
+ /* one byte */
170
+ buf[i++] = c;
171
+ } else if (c < 0x800) {
172
+ /* two bytes */
173
+ buf[i++] = 0xC0 | (c >>> 6);
174
+ buf[i++] = 0x80 | (c & 0x3f);
175
+ } else if (c < 0x10000) {
176
+ /* three bytes */
177
+ buf[i++] = 0xE0 | (c >>> 12);
178
+ buf[i++] = 0x80 | (c >>> 6 & 0x3f);
179
+ buf[i++] = 0x80 | (c & 0x3f);
180
+ } else {
181
+ /* four bytes */
182
+ buf[i++] = 0xf0 | (c >>> 18);
183
+ buf[i++] = 0x80 | (c >>> 12 & 0x3f);
184
+ buf[i++] = 0x80 | (c >>> 6 & 0x3f);
185
+ buf[i++] = 0x80 | (c & 0x3f);
186
+ }
187
+ }
188
+
189
+ return buf;
190
+ };
191
+
192
+ // Helper (used in 2 places)
193
+ function buf2binstring(buf, len) {
194
+ // On Chrome, the arguments in a function call that are allowed is `65534`.
195
+ // If the length of the buffer is smaller than that, we can use this optimization,
196
+ // otherwise we will take a slower path.
197
+ if (len < 65534) {
198
+ if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
199
+ return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
200
+ }
201
+ }
202
+
203
+ var result = '';
204
+ for (var i = 0; i < len; i++) {
205
+ result += String.fromCharCode(buf[i]);
206
+ }
207
+ return result;
208
+ }
209
+
210
+
211
+ // Convert byte array to binary string
212
+ exports.buf2binstring = function (buf) {
213
+ return buf2binstring(buf, buf.length);
214
+ };
215
+
216
+
217
+ // Convert binary string (typed, when possible)
218
+ exports.binstring2buf = function (str) {
219
+ var buf = new utils.Buf8(str.length);
220
+ for (var i = 0, len = buf.length; i < len; i++) {
221
+ buf[i] = str.charCodeAt(i);
222
+ }
223
+ return buf;
224
+ };
225
+
226
+
227
+ // convert array to string
228
+ exports.buf2string = function (buf, max) {
229
+ var i, out, c, c_len;
230
+ var len = max || buf.length;
231
+
232
+ // Reserve max possible length (2 words per char)
233
+ // NB: by unknown reasons, Array is significantly faster for
234
+ // String.fromCharCode.apply than Uint16Array.
235
+ var utf16buf = new Array(len * 2);
236
+
237
+ for (out = 0, i = 0; i < len;) {
238
+ c = buf[i++];
239
+ // quick process ascii
240
+ if (c < 0x80) { utf16buf[out++] = c; continue; }
241
+
242
+ c_len = _utf8len[c];
243
+ // skip 5 & 6 byte codes
244
+ if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; }
245
+
246
+ // apply mask on first byte
247
+ c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
248
+ // join the rest
249
+ while (c_len > 1 && i < len) {
250
+ c = (c << 6) | (buf[i++] & 0x3f);
251
+ c_len--;
252
+ }
253
+
254
+ // terminated by end of string?
255
+ if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
256
+
257
+ if (c < 0x10000) {
258
+ utf16buf[out++] = c;
259
+ } else {
260
+ c -= 0x10000;
261
+ utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
262
+ utf16buf[out++] = 0xdc00 | (c & 0x3ff);
263
+ }
264
+ }
265
+
266
+ return buf2binstring(utf16buf, out);
267
+ };
268
+
269
+
270
+ // Calculate max possible position in utf8 buffer,
271
+ // that will not break sequence. If that's not possible
272
+ // - (very small limits) return max size as is.
273
+ //
274
+ // buf[] - utf8 bytes array
275
+ // max - length limit (mandatory);
276
+ exports.utf8border = function (buf, max) {
277
+ var pos;
278
+
279
+ max = max || buf.length;
280
+ if (max > buf.length) { max = buf.length; }
281
+
282
+ // go back from last position, until start of sequence found
283
+ pos = max - 1;
284
+ while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
285
+
286
+ // Very small and broken sequence,
287
+ // return max, because we should return something anyway.
288
+ if (pos < 0) { return max; }
289
+
290
+ // If we came to start of buffer - that means buffer is too small,
291
+ // return max too.
292
+ if (pos === 0) { return max; }
293
+
294
+ return (pos + _utf8len[buf[pos]] > max) ? pos : max;
295
+ };
296
+
297
+ },{"./common":1}],3:[function(require,module,exports){
298
+ 'use strict';
299
+
300
+ // Note: adler32 takes 12% for level 0 and 2% for level 6.
301
+ // It isn't worth it to make additional optimizations as in original.
302
+ // Small size is preferable.
303
+
304
+ // (C) 1995-2013 Jean-loup Gailly and Mark Adler
305
+ // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
306
+ //
307
+ // This software is provided 'as-is', without any express or implied
308
+ // warranty. In no event will the authors be held liable for any damages
309
+ // arising from the use of this software.
310
+ //
311
+ // Permission is granted to anyone to use this software for any purpose,
312
+ // including commercial applications, and to alter it and redistribute it
313
+ // freely, subject to the following restrictions:
314
+ //
315
+ // 1. The origin of this software must not be misrepresented; you must not
316
+ // claim that you wrote the original software. If you use this software
317
+ // in a product, an acknowledgment in the product documentation would be
318
+ // appreciated but is not required.
319
+ // 2. Altered source versions must be plainly marked as such, and must not be
320
+ // misrepresented as being the original software.
321
+ // 3. This notice may not be removed or altered from any source distribution.
322
+
323
+ function adler32(adler, buf, len, pos) {
324
+ var s1 = (adler & 0xffff) |0,
325
+ s2 = ((adler >>> 16) & 0xffff) |0,
326
+ n = 0;
327
+
328
+ while (len !== 0) {
329
+ // Set limit ~ twice less than 5552, to keep
330
+ // s2 in 31-bits, because we force signed ints.
331
+ // in other case %= will fail.
332
+ n = len > 2000 ? 2000 : len;
333
+ len -= n;
334
+
335
+ do {
336
+ s1 = (s1 + buf[pos++]) |0;
337
+ s2 = (s2 + s1) |0;
338
+ } while (--n);
339
+
340
+ s1 %= 65521;
341
+ s2 %= 65521;
342
+ }
343
+
344
+ return (s1 | (s2 << 16)) |0;
345
+ }
346
+
347
+
348
+ module.exports = adler32;
349
+
350
+ },{}],4:[function(require,module,exports){
351
+ 'use strict';
352
+
353
+ // Note: we can't get significant speed boost here.
354
+ // So write code to minimize size - no pregenerated tables
355
+ // and array tools dependencies.
356
+
357
+ // (C) 1995-2013 Jean-loup Gailly and Mark Adler
358
+ // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
359
+ //
360
+ // This software is provided 'as-is', without any express or implied
361
+ // warranty. In no event will the authors be held liable for any damages
362
+ // arising from the use of this software.
363
+ //
364
+ // Permission is granted to anyone to use this software for any purpose,
365
+ // including commercial applications, and to alter it and redistribute it
366
+ // freely, subject to the following restrictions:
367
+ //
368
+ // 1. The origin of this software must not be misrepresented; you must not
369
+ // claim that you wrote the original software. If you use this software
370
+ // in a product, an acknowledgment in the product documentation would be
371
+ // appreciated but is not required.
372
+ // 2. Altered source versions must be plainly marked as such, and must not be
373
+ // misrepresented as being the original software.
374
+ // 3. This notice may not be removed or altered from any source distribution.
375
+
376
+ // Use ordinary array, since untyped makes no boost here
377
+ function makeTable() {
378
+ var c, table = [];
379
+
380
+ for (var n = 0; n < 256; n++) {
381
+ c = n;
382
+ for (var k = 0; k < 8; k++) {
383
+ c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
384
+ }
385
+ table[n] = c;
386
+ }
387
+
388
+ return table;
389
+ }
390
+
391
+ // Create table on load. Just 255 signed longs. Not a problem.
392
+ var crcTable = makeTable();
393
+
394
+
395
+ function crc32(crc, buf, len, pos) {
396
+ var t = crcTable,
397
+ end = pos + len;
398
+
399
+ crc ^= -1;
400
+
401
+ for (var i = pos; i < end; i++) {
402
+ crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
403
+ }
404
+
405
+ return (crc ^ (-1)); // >>> 0;
406
+ }
407
+
408
+
409
+ module.exports = crc32;
410
+
411
+ },{}],5:[function(require,module,exports){
412
+ 'use strict';
413
+
414
+ // (C) 1995-2013 Jean-loup Gailly and Mark Adler
415
+ // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
416
+ //
417
+ // This software is provided 'as-is', without any express or implied
418
+ // warranty. In no event will the authors be held liable for any damages
419
+ // arising from the use of this software.
420
+ //
421
+ // Permission is granted to anyone to use this software for any purpose,
422
+ // including commercial applications, and to alter it and redistribute it
423
+ // freely, subject to the following restrictions:
424
+ //
425
+ // 1. The origin of this software must not be misrepresented; you must not
426
+ // claim that you wrote the original software. If you use this software
427
+ // in a product, an acknowledgment in the product documentation would be
428
+ // appreciated but is not required.
429
+ // 2. Altered source versions must be plainly marked as such, and must not be
430
+ // misrepresented as being the original software.
431
+ // 3. This notice may not be removed or altered from any source distribution.
432
+
433
+ var utils = require('../utils/common');
434
+ var trees = require('./trees');
435
+ var adler32 = require('./adler32');
436
+ var crc32 = require('./crc32');
437
+ var msg = require('./messages');
438
+
439
+ /* Public constants ==========================================================*/
440
+ /* ===========================================================================*/
441
+
442
+
443
+ /* Allowed flush values; see deflate() and inflate() below for details */
444
+ var Z_NO_FLUSH = 0;
445
+ var Z_PARTIAL_FLUSH = 1;
446
+ //var Z_SYNC_FLUSH = 2;
447
+ var Z_FULL_FLUSH = 3;
448
+ var Z_FINISH = 4;
449
+ var Z_BLOCK = 5;
450
+ //var Z_TREES = 6;
451
+
452
+
453
+ /* Return codes for the compression/decompression functions. Negative values
454
+ * are errors, positive values are used for special but normal events.
455
+ */
456
+ var Z_OK = 0;
457
+ var Z_STREAM_END = 1;
458
+ //var Z_NEED_DICT = 2;
459
+ //var Z_ERRNO = -1;
460
+ var Z_STREAM_ERROR = -2;
461
+ var Z_DATA_ERROR = -3;
462
+ //var Z_MEM_ERROR = -4;
463
+ var Z_BUF_ERROR = -5;
464
+ //var Z_VERSION_ERROR = -6;
465
+
466
+
467
+ /* compression levels */
468
+ //var Z_NO_COMPRESSION = 0;
469
+ //var Z_BEST_SPEED = 1;
470
+ //var Z_BEST_COMPRESSION = 9;
471
+ var Z_DEFAULT_COMPRESSION = -1;
472
+
473
+
474
+ var Z_FILTERED = 1;
475
+ var Z_HUFFMAN_ONLY = 2;
476
+ var Z_RLE = 3;
477
+ var Z_FIXED = 4;
478
+ var Z_DEFAULT_STRATEGY = 0;
479
+
480
+ /* Possible values of the data_type field (though see inflate()) */
481
+ //var Z_BINARY = 0;
482
+ //var Z_TEXT = 1;
483
+ //var Z_ASCII = 1; // = Z_TEXT
484
+ var Z_UNKNOWN = 2;
485
+
486
+
487
+ /* The deflate compression method */
488
+ var Z_DEFLATED = 8;
489
+
490
+ /*============================================================================*/
491
+
492
+
493
+ var MAX_MEM_LEVEL = 9;
494
+ /* Maximum value for memLevel in deflateInit2 */
495
+ var MAX_WBITS = 15;
496
+ /* 32K LZ77 window */
497
+ var DEF_MEM_LEVEL = 8;
498
+
499
+
500
+ var LENGTH_CODES = 29;
501
+ /* number of length codes, not counting the special END_BLOCK code */
502
+ var LITERALS = 256;
503
+ /* number of literal bytes 0..255 */
504
+ var L_CODES = LITERALS + 1 + LENGTH_CODES;
505
+ /* number of Literal or Length codes, including the END_BLOCK code */
506
+ var D_CODES = 30;
507
+ /* number of distance codes */
508
+ var BL_CODES = 19;
509
+ /* number of codes used to transfer the bit lengths */
510
+ var HEAP_SIZE = 2 * L_CODES + 1;
511
+ /* maximum heap size */
512
+ var MAX_BITS = 15;
513
+ /* All codes must not exceed MAX_BITS bits */
514
+
515
+ var MIN_MATCH = 3;
516
+ var MAX_MATCH = 258;
517
+ var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);
518
+
519
+ var PRESET_DICT = 0x20;
520
+
521
+ var INIT_STATE = 42;
522
+ var EXTRA_STATE = 69;
523
+ var NAME_STATE = 73;
524
+ var COMMENT_STATE = 91;
525
+ var HCRC_STATE = 103;
526
+ var BUSY_STATE = 113;
527
+ var FINISH_STATE = 666;
528
+
529
+ var BS_NEED_MORE = 1; /* block not completed, need more input or more output */
530
+ var BS_BLOCK_DONE = 2; /* block flush performed */
531
+ var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */
532
+ var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */
533
+
534
+ var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
535
+
536
+ function err(strm, errorCode) {
537
+ strm.msg = msg[errorCode];
538
+ return errorCode;
539
+ }
540
+
541
+ function rank(f) {
542
+ return ((f) << 1) - ((f) > 4 ? 9 : 0);
543
+ }
544
+
545
+ function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
546
+
547
+
548
+ /* =========================================================================
549
+ * Flush as much pending output as possible. All deflate() output goes
550
+ * through this function so some applications may wish to modify it
551
+ * to avoid allocating a large strm->output buffer and copying into it.
552
+ * (See also read_buf()).
553
+ */
554
+ function flush_pending(strm) {
555
+ var s = strm.state;
556
+
557
+ //_tr_flush_bits(s);
558
+ var len = s.pending;
559
+ if (len > strm.avail_out) {
560
+ len = strm.avail_out;
561
+ }
562
+ if (len === 0) { return; }
563
+
564
+ utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
565
+ strm.next_out += len;
566
+ s.pending_out += len;
567
+ strm.total_out += len;
568
+ strm.avail_out -= len;
569
+ s.pending -= len;
570
+ if (s.pending === 0) {
571
+ s.pending_out = 0;
572
+ }
573
+ }
574
+
575
+
576
+ function flush_block_only(s, last) {
577
+ trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last);
578
+ s.block_start = s.strstart;
579
+ flush_pending(s.strm);
580
+ }
581
+
582
+
583
+ function put_byte(s, b) {
584
+ s.pending_buf[s.pending++] = b;
585
+ }
586
+
587
+
588
+ /* =========================================================================
589
+ * Put a short in the pending buffer. The 16-bit value is put in MSB order.
590
+ * IN assertion: the stream state is correct and there is enough room in
591
+ * pending_buf.
592
+ */
593
+ function putShortMSB(s, b) {
594
+ // put_byte(s, (Byte)(b >> 8));
595
+ // put_byte(s, (Byte)(b & 0xff));
596
+ s.pending_buf[s.pending++] = (b >>> 8) & 0xff;
597
+ s.pending_buf[s.pending++] = b & 0xff;
598
+ }
599
+
600
+
601
+ /* ===========================================================================
602
+ * Read a new buffer from the current input stream, update the adler32
603
+ * and total number of bytes read. All deflate() input goes through
604
+ * this function so some applications may wish to modify it to avoid
605
+ * allocating a large strm->input buffer and copying from it.
606
+ * (See also flush_pending()).
607
+ */
608
+ function read_buf(strm, buf, start, size) {
609
+ var len = strm.avail_in;
610
+
611
+ if (len > size) { len = size; }
612
+ if (len === 0) { return 0; }
613
+
614
+ strm.avail_in -= len;
615
+
616
+ // zmemcpy(buf, strm->next_in, len);
617
+ utils.arraySet(buf, strm.input, strm.next_in, len, start);
618
+ if (strm.state.wrap === 1) {
619
+ strm.adler = adler32(strm.adler, buf, len, start);
620
+ }
621
+
622
+ else if (strm.state.wrap === 2) {
623
+ strm.adler = crc32(strm.adler, buf, len, start);
624
+ }
625
+
626
+ strm.next_in += len;
627
+ strm.total_in += len;
628
+
629
+ return len;
630
+ }
631
+
632
+
633
+ /* ===========================================================================
634
+ * Set match_start to the longest match starting at the given string and
635
+ * return its length. Matches shorter or equal to prev_length are discarded,
636
+ * in which case the result is equal to prev_length and match_start is
637
+ * garbage.
638
+ * IN assertions: cur_match is the head of the hash chain for the current
639
+ * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
640
+ * OUT assertion: the match length is not greater than s->lookahead.
641
+ */
642
+ function longest_match(s, cur_match) {
643
+ var chain_length = s.max_chain_length; /* max hash chain length */
644
+ var scan = s.strstart; /* current string */
645
+ var match; /* matched string */
646
+ var len; /* length of current match */
647
+ var best_len = s.prev_length; /* best match length so far */
648
+ var nice_match = s.nice_match; /* stop if match long enough */
649
+ var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?
650
+ s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;
651
+
652
+ var _win = s.window; // shortcut
653
+
654
+ var wmask = s.w_mask;
655
+ var prev = s.prev;
656
+
657
+ /* Stop when cur_match becomes <= limit. To simplify the code,
658
+ * we prevent matches with the string of window index 0.
659
+ */
660
+
661
+ var strend = s.strstart + MAX_MATCH;
662
+ var scan_end1 = _win[scan + best_len - 1];
663
+ var scan_end = _win[scan + best_len];
664
+
665
+ /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
666
+ * It is easy to get rid of this optimization if necessary.
667
+ */
668
+ // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
669
+
670
+ /* Do not waste too much time if we already have a good match: */
671
+ if (s.prev_length >= s.good_match) {
672
+ chain_length >>= 2;
673
+ }
674
+ /* Do not look for matches beyond the end of the input. This is necessary
675
+ * to make deflate deterministic.
676
+ */
677
+ if (nice_match > s.lookahead) { nice_match = s.lookahead; }
678
+
679
+ // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
680
+
681
+ do {
682
+ // Assert(cur_match < s->strstart, "no future");
683
+ match = cur_match;
684
+
685
+ /* Skip to next match if the match length cannot increase
686
+ * or if the match length is less than 2. Note that the checks below
687
+ * for insufficient lookahead only occur occasionally for performance
688
+ * reasons. Therefore uninitialized memory will be accessed, and
689
+ * conditional jumps will be made that depend on those values.
690
+ * However the length of the match is limited to the lookahead, so
691
+ * the output of deflate is not affected by the uninitialized values.
692
+ */
693
+
694
+ if (_win[match + best_len] !== scan_end ||
695
+ _win[match + best_len - 1] !== scan_end1 ||
696
+ _win[match] !== _win[scan] ||
697
+ _win[++match] !== _win[scan + 1]) {
698
+ continue;
699
+ }
700
+
701
+ /* The check at best_len-1 can be removed because it will be made
702
+ * again later. (This heuristic is not always a win.)
703
+ * It is not necessary to compare scan[2] and match[2] since they
704
+ * are always equal when the other bytes match, given that
705
+ * the hash keys are equal and that HASH_BITS >= 8.
706
+ */
707
+ scan += 2;
708
+ match++;
709
+ // Assert(*scan == *match, "match[2]?");
710
+
711
+ /* We check for insufficient lookahead only every 8th comparison;
712
+ * the 256th check will be made at strstart+258.
713
+ */
714
+ do {
715
+ /*jshint noempty:false*/
716
+ } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
717
+ _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
718
+ _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
719
+ _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
720
+ scan < strend);
721
+
722
+ // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
723
+
724
+ len = MAX_MATCH - (strend - scan);
725
+ scan = strend - MAX_MATCH;
726
+
727
+ if (len > best_len) {
728
+ s.match_start = cur_match;
729
+ best_len = len;
730
+ if (len >= nice_match) {
731
+ break;
732
+ }
733
+ scan_end1 = _win[scan + best_len - 1];
734
+ scan_end = _win[scan + best_len];
735
+ }
736
+ } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
737
+
738
+ if (best_len <= s.lookahead) {
739
+ return best_len;
740
+ }
741
+ return s.lookahead;
742
+ }
743
+
744
+
745
+ /* ===========================================================================
746
+ * Fill the window when the lookahead becomes insufficient.
747
+ * Updates strstart and lookahead.
748
+ *
749
+ * IN assertion: lookahead < MIN_LOOKAHEAD
750
+ * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
751
+ * At least one byte has been read, or avail_in == 0; reads are
752
+ * performed for at least two bytes (required for the zip translate_eol
753
+ * option -- not supported here).
754
+ */
755
+ function fill_window(s) {
756
+ var _w_size = s.w_size;
757
+ var p, n, m, more, str;
758
+
759
+ //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
760
+
761
+ do {
762
+ more = s.window_size - s.lookahead - s.strstart;
763
+
764
+ // JS ints have 32 bit, block below not needed
765
+ /* Deal with !@#$% 64K limit: */
766
+ //if (sizeof(int) <= 2) {
767
+ // if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
768
+ // more = wsize;
769
+ //
770
+ // } else if (more == (unsigned)(-1)) {
771
+ // /* Very unlikely, but possible on 16 bit machine if
772
+ // * strstart == 0 && lookahead == 1 (input done a byte at time)
773
+ // */
774
+ // more--;
775
+ // }
776
+ //}
777
+
778
+
779
+ /* If the window is almost full and there is insufficient lookahead,
780
+ * move the upper half to the lower one to make room in the upper half.
781
+ */
782
+ if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
783
+
784
+ utils.arraySet(s.window, s.window, _w_size, _w_size, 0);
785
+ s.match_start -= _w_size;
786
+ s.strstart -= _w_size;
787
+ /* we now have strstart >= MAX_DIST */
788
+ s.block_start -= _w_size;
789
+
790
+ /* Slide the hash table (could be avoided with 32 bit values
791
+ at the expense of memory usage). We slide even when level == 0
792
+ to keep the hash table consistent if we switch back to level > 0
793
+ later. (Using level 0 permanently is not an optimal usage of
794
+ zlib, so we don't care about this pathological case.)
795
+ */
796
+
797
+ n = s.hash_size;
798
+ p = n;
799
+ do {
800
+ m = s.head[--p];
801
+ s.head[p] = (m >= _w_size ? m - _w_size : 0);
802
+ } while (--n);
803
+
804
+ n = _w_size;
805
+ p = n;
806
+ do {
807
+ m = s.prev[--p];
808
+ s.prev[p] = (m >= _w_size ? m - _w_size : 0);
809
+ /* If n is not on any hash chain, prev[n] is garbage but
810
+ * its value will never be used.
811
+ */
812
+ } while (--n);
813
+
814
+ more += _w_size;
815
+ }
816
+ if (s.strm.avail_in === 0) {
817
+ break;
818
+ }
819
+
820
+ /* If there was no sliding:
821
+ * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
822
+ * more == window_size - lookahead - strstart
823
+ * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
824
+ * => more >= window_size - 2*WSIZE + 2
825
+ * In the BIG_MEM or MMAP case (not yet supported),
826
+ * window_size == input_size + MIN_LOOKAHEAD &&
827
+ * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
828
+ * Otherwise, window_size == 2*WSIZE so more >= 2.
829
+ * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
830
+ */
831
+ //Assert(more >= 2, "more < 2");
832
+ n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
833
+ s.lookahead += n;
834
+
835
+ /* Initialize the hash value now that we have some input: */
836
+ if (s.lookahead + s.insert >= MIN_MATCH) {
837
+ str = s.strstart - s.insert;
838
+ s.ins_h = s.window[str];
839
+
840
+ /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
841
+ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;
842
+ //#if MIN_MATCH != 3
843
+ // Call update_hash() MIN_MATCH-3 more times
844
+ //#endif
845
+ while (s.insert) {
846
+ /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
847
+ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
848
+
849
+ s.prev[str & s.w_mask] = s.head[s.ins_h];
850
+ s.head[s.ins_h] = str;
851
+ str++;
852
+ s.insert--;
853
+ if (s.lookahead + s.insert < MIN_MATCH) {
854
+ break;
855
+ }
856
+ }
857
+ }
858
+ /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
859
+ * but this is not important since only literal bytes will be emitted.
860
+ */
861
+
862
+ } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
863
+
864
+ /* If the WIN_INIT bytes after the end of the current data have never been
865
+ * written, then zero those bytes in order to avoid memory check reports of
866
+ * the use of uninitialized (or uninitialised as Julian writes) bytes by
867
+ * the longest match routines. Update the high water mark for the next
868
+ * time through here. WIN_INIT is set to MAX_MATCH since the longest match
869
+ * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
870
+ */
871
+ // if (s.high_water < s.window_size) {
872
+ // var curr = s.strstart + s.lookahead;
873
+ // var init = 0;
874
+ //
875
+ // if (s.high_water < curr) {
876
+ // /* Previous high water mark below current data -- zero WIN_INIT
877
+ // * bytes or up to end of window, whichever is less.
878
+ // */
879
+ // init = s.window_size - curr;
880
+ // if (init > WIN_INIT)
881
+ // init = WIN_INIT;
882
+ // zmemzero(s->window + curr, (unsigned)init);
883
+ // s->high_water = curr + init;
884
+ // }
885
+ // else if (s->high_water < (ulg)curr + WIN_INIT) {
886
+ // /* High water mark at or above current data, but below current data
887
+ // * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
888
+ // * to end of window, whichever is less.
889
+ // */
890
+ // init = (ulg)curr + WIN_INIT - s->high_water;
891
+ // if (init > s->window_size - s->high_water)
892
+ // init = s->window_size - s->high_water;
893
+ // zmemzero(s->window + s->high_water, (unsigned)init);
894
+ // s->high_water += init;
895
+ // }
896
+ // }
897
+ //
898
+ // Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
899
+ // "not enough room for search");
900
+ }
901
+
902
+ /* ===========================================================================
903
+ * Copy without compression as much as possible from the input stream, return
904
+ * the current block state.
905
+ * This function does not insert new strings in the dictionary since
906
+ * uncompressible data is probably not useful. This function is used
907
+ * only for the level=0 compression option.
908
+ * NOTE: this function should be optimized to avoid extra copying from
909
+ * window to pending_buf.
910
+ */
911
+ function deflate_stored(s, flush) {
912
+ /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
913
+ * to pending_buf_size, and each stored block has a 5 byte header:
914
+ */
915
+ var max_block_size = 0xffff;
916
+
917
+ if (max_block_size > s.pending_buf_size - 5) {
918
+ max_block_size = s.pending_buf_size - 5;
919
+ }
920
+
921
+ /* Copy as much as possible from input to output: */
922
+ for (;;) {
923
+ /* Fill the window as much as possible: */
924
+ if (s.lookahead <= 1) {
925
+
926
+ //Assert(s->strstart < s->w_size+MAX_DIST(s) ||
927
+ // s->block_start >= (long)s->w_size, "slide too late");
928
+ // if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||
929
+ // s.block_start >= s.w_size)) {
930
+ // throw new Error("slide too late");
931
+ // }
932
+
933
+ fill_window(s);
934
+ if (s.lookahead === 0 && flush === Z_NO_FLUSH) {
935
+ return BS_NEED_MORE;
936
+ }
937
+
938
+ if (s.lookahead === 0) {
939
+ break;
940
+ }
941
+ /* flush the current block */
942
+ }
943
+ //Assert(s->block_start >= 0L, "block gone");
944
+ // if (s.block_start < 0) throw new Error("block gone");
945
+
946
+ s.strstart += s.lookahead;
947
+ s.lookahead = 0;
948
+
949
+ /* Emit a stored block if pending_buf will be full: */
950
+ var max_start = s.block_start + max_block_size;
951
+
952
+ if (s.strstart === 0 || s.strstart >= max_start) {
953
+ /* strstart == 0 is possible when wraparound on 16-bit machine */
954
+ s.lookahead = s.strstart - max_start;
955
+ s.strstart = max_start;
956
+ /*** FLUSH_BLOCK(s, 0); ***/
957
+ flush_block_only(s, false);
958
+ if (s.strm.avail_out === 0) {
959
+ return BS_NEED_MORE;
960
+ }
961
+ /***/
962
+
963
+
964
+ }
965
+ /* Flush if we may have to slide, otherwise block_start may become
966
+ * negative and the data will be gone:
967
+ */
968
+ if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) {
969
+ /*** FLUSH_BLOCK(s, 0); ***/
970
+ flush_block_only(s, false);
971
+ if (s.strm.avail_out === 0) {
972
+ return BS_NEED_MORE;
973
+ }
974
+ /***/
975
+ }
976
+ }
977
+
978
+ s.insert = 0;
979
+
980
+ if (flush === Z_FINISH) {
981
+ /*** FLUSH_BLOCK(s, 1); ***/
982
+ flush_block_only(s, true);
983
+ if (s.strm.avail_out === 0) {
984
+ return BS_FINISH_STARTED;
985
+ }
986
+ /***/
987
+ return BS_FINISH_DONE;
988
+ }
989
+
990
+ if (s.strstart > s.block_start) {
991
+ /*** FLUSH_BLOCK(s, 0); ***/
992
+ flush_block_only(s, false);
993
+ if (s.strm.avail_out === 0) {
994
+ return BS_NEED_MORE;
995
+ }
996
+ /***/
997
+ }
998
+
999
+ return BS_NEED_MORE;
1000
+ }
1001
+
1002
+ /* ===========================================================================
1003
+ * Compress as much as possible from the input stream, return the current
1004
+ * block state.
1005
+ * This function does not perform lazy evaluation of matches and inserts
1006
+ * new strings in the dictionary only for unmatched strings or for short
1007
+ * matches. It is used only for the fast compression options.
1008
+ */
1009
+ function deflate_fast(s, flush) {
1010
+ var hash_head; /* head of the hash chain */
1011
+ var bflush; /* set if current block must be flushed */
1012
+
1013
+ for (;;) {
1014
+ /* Make sure that we always have enough lookahead, except
1015
+ * at the end of the input file. We need MAX_MATCH bytes
1016
+ * for the next match, plus MIN_MATCH bytes to insert the
1017
+ * string following the next match.
1018
+ */
1019
+ if (s.lookahead < MIN_LOOKAHEAD) {
1020
+ fill_window(s);
1021
+ if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
1022
+ return BS_NEED_MORE;
1023
+ }
1024
+ if (s.lookahead === 0) {
1025
+ break; /* flush the current block */
1026
+ }
1027
+ }
1028
+
1029
+ /* Insert the string window[strstart .. strstart+2] in the
1030
+ * dictionary, and set hash_head to the head of the hash chain:
1031
+ */
1032
+ hash_head = 0/*NIL*/;
1033
+ if (s.lookahead >= MIN_MATCH) {
1034
+ /*** INSERT_STRING(s, s.strstart, hash_head); ***/
1035
+ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
1036
+ hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
1037
+ s.head[s.ins_h] = s.strstart;
1038
+ /***/
1039
+ }
1040
+
1041
+ /* Find the longest match, discarding those <= prev_length.
1042
+ * At this point we have always match_length < MIN_MATCH
1043
+ */
1044
+ if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {
1045
+ /* To simplify the code, we prevent matches with the string
1046
+ * of window index 0 (in particular we have to avoid a match
1047
+ * of the string with itself at the start of the input file).
1048
+ */
1049
+ s.match_length = longest_match(s, hash_head);
1050
+ /* longest_match() sets match_start */
1051
+ }
1052
+ if (s.match_length >= MIN_MATCH) {
1053
+ // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
1054
+
1055
+ /*** _tr_tally_dist(s, s.strstart - s.match_start,
1056
+ s.match_length - MIN_MATCH, bflush); ***/
1057
+ bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
1058
+
1059
+ s.lookahead -= s.match_length;
1060
+
1061
+ /* Insert new strings in the hash table only if the match length
1062
+ * is not too large. This saves time but degrades compression.
1063
+ */
1064
+ if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
1065
+ s.match_length--; /* string at strstart already in table */
1066
+ do {
1067
+ s.strstart++;
1068
+ /*** INSERT_STRING(s, s.strstart, hash_head); ***/
1069
+ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
1070
+ hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
1071
+ s.head[s.ins_h] = s.strstart;
1072
+ /***/
1073
+ /* strstart never exceeds WSIZE-MAX_MATCH, so there are
1074
+ * always MIN_MATCH bytes ahead.
1075
+ */
1076
+ } while (--s.match_length !== 0);
1077
+ s.strstart++;
1078
+ } else
1079
+ {
1080
+ s.strstart += s.match_length;
1081
+ s.match_length = 0;
1082
+ s.ins_h = s.window[s.strstart];
1083
+ /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
1084
+ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;
1085
+
1086
+ //#if MIN_MATCH != 3
1087
+ // Call UPDATE_HASH() MIN_MATCH-3 more times
1088
+ //#endif
1089
+ /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
1090
+ * matter since it will be recomputed at next deflate call.
1091
+ */
1092
+ }
1093
+ } else {
1094
+ /* No match, output a literal byte */
1095
+ //Tracevv((stderr,"%c", s.window[s.strstart]));
1096
+ /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
1097
+ bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
1098
+
1099
+ s.lookahead--;
1100
+ s.strstart++;
1101
+ }
1102
+ if (bflush) {
1103
+ /*** FLUSH_BLOCK(s, 0); ***/
1104
+ flush_block_only(s, false);
1105
+ if (s.strm.avail_out === 0) {
1106
+ return BS_NEED_MORE;
1107
+ }
1108
+ /***/
1109
+ }
1110
+ }
1111
+ s.insert = ((s.strstart < (MIN_MATCH - 1)) ? s.strstart : MIN_MATCH - 1);
1112
+ if (flush === Z_FINISH) {
1113
+ /*** FLUSH_BLOCK(s, 1); ***/
1114
+ flush_block_only(s, true);
1115
+ if (s.strm.avail_out === 0) {
1116
+ return BS_FINISH_STARTED;
1117
+ }
1118
+ /***/
1119
+ return BS_FINISH_DONE;
1120
+ }
1121
+ if (s.last_lit) {
1122
+ /*** FLUSH_BLOCK(s, 0); ***/
1123
+ flush_block_only(s, false);
1124
+ if (s.strm.avail_out === 0) {
1125
+ return BS_NEED_MORE;
1126
+ }
1127
+ /***/
1128
+ }
1129
+ return BS_BLOCK_DONE;
1130
+ }
1131
+
1132
+ /* ===========================================================================
1133
+ * Same as above, but achieves better compression. We use a lazy
1134
+ * evaluation for matches: a match is finally adopted only if there is
1135
+ * no better match at the next window position.
1136
+ */
1137
+ function deflate_slow(s, flush) {
1138
+ var hash_head; /* head of hash chain */
1139
+ var bflush; /* set if current block must be flushed */
1140
+
1141
+ var max_insert;
1142
+
1143
+ /* Process the input block. */
1144
+ for (;;) {
1145
+ /* Make sure that we always have enough lookahead, except
1146
+ * at the end of the input file. We need MAX_MATCH bytes
1147
+ * for the next match, plus MIN_MATCH bytes to insert the
1148
+ * string following the next match.
1149
+ */
1150
+ if (s.lookahead < MIN_LOOKAHEAD) {
1151
+ fill_window(s);
1152
+ if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
1153
+ return BS_NEED_MORE;
1154
+ }
1155
+ if (s.lookahead === 0) { break; } /* flush the current block */
1156
+ }
1157
+
1158
+ /* Insert the string window[strstart .. strstart+2] in the
1159
+ * dictionary, and set hash_head to the head of the hash chain:
1160
+ */
1161
+ hash_head = 0/*NIL*/;
1162
+ if (s.lookahead >= MIN_MATCH) {
1163
+ /*** INSERT_STRING(s, s.strstart, hash_head); ***/
1164
+ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
1165
+ hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
1166
+ s.head[s.ins_h] = s.strstart;
1167
+ /***/
1168
+ }
1169
+
1170
+ /* Find the longest match, discarding those <= prev_length.
1171
+ */
1172
+ s.prev_length = s.match_length;
1173
+ s.prev_match = s.match_start;
1174
+ s.match_length = MIN_MATCH - 1;
1175
+
1176
+ if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&
1177
+ s.strstart - hash_head <= (s.w_size - MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {
1178
+ /* To simplify the code, we prevent matches with the string
1179
+ * of window index 0 (in particular we have to avoid a match
1180
+ * of the string with itself at the start of the input file).
1181
+ */
1182
+ s.match_length = longest_match(s, hash_head);
1183
+ /* longest_match() sets match_start */
1184
+
1185
+ if (s.match_length <= 5 &&
1186
+ (s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {
1187
+
1188
+ /* If prev_match is also MIN_MATCH, match_start is garbage
1189
+ * but we will ignore the current match anyway.
1190
+ */
1191
+ s.match_length = MIN_MATCH - 1;
1192
+ }
1193
+ }
1194
+ /* If there was a match at the previous step and the current
1195
+ * match is not better, output the previous match:
1196
+ */
1197
+ if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {
1198
+ max_insert = s.strstart + s.lookahead - MIN_MATCH;
1199
+ /* Do not insert strings in hash table beyond this. */
1200
+
1201
+ //check_match(s, s.strstart-1, s.prev_match, s.prev_length);
1202
+
1203
+ /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,
1204
+ s.prev_length - MIN_MATCH, bflush);***/
1205
+ bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH);
1206
+ /* Insert in hash table all strings up to the end of the match.
1207
+ * strstart-1 and strstart are already inserted. If there is not
1208
+ * enough lookahead, the last two strings are not inserted in
1209
+ * the hash table.
1210
+ */
1211
+ s.lookahead -= s.prev_length - 1;
1212
+ s.prev_length -= 2;
1213
+ do {
1214
+ if (++s.strstart <= max_insert) {
1215
+ /*** INSERT_STRING(s, s.strstart, hash_head); ***/
1216
+ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
1217
+ hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
1218
+ s.head[s.ins_h] = s.strstart;
1219
+ /***/
1220
+ }
1221
+ } while (--s.prev_length !== 0);
1222
+ s.match_available = 0;
1223
+ s.match_length = MIN_MATCH - 1;
1224
+ s.strstart++;
1225
+
1226
+ if (bflush) {
1227
+ /*** FLUSH_BLOCK(s, 0); ***/
1228
+ flush_block_only(s, false);
1229
+ if (s.strm.avail_out === 0) {
1230
+ return BS_NEED_MORE;
1231
+ }
1232
+ /***/
1233
+ }
1234
+
1235
+ } else if (s.match_available) {
1236
+ /* If there was no match at the previous position, output a
1237
+ * single literal. If there was a match but the current match
1238
+ * is longer, truncate the previous match to a single literal.
1239
+ */
1240
+ //Tracevv((stderr,"%c", s->window[s->strstart-1]));
1241
+ /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
1242
+ bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
1243
+
1244
+ if (bflush) {
1245
+ /*** FLUSH_BLOCK_ONLY(s, 0) ***/
1246
+ flush_block_only(s, false);
1247
+ /***/
1248
+ }
1249
+ s.strstart++;
1250
+ s.lookahead--;
1251
+ if (s.strm.avail_out === 0) {
1252
+ return BS_NEED_MORE;
1253
+ }
1254
+ } else {
1255
+ /* There is no previous match to compare with, wait for
1256
+ * the next step to decide.
1257
+ */
1258
+ s.match_available = 1;
1259
+ s.strstart++;
1260
+ s.lookahead--;
1261
+ }
1262
+ }
1263
+ //Assert (flush != Z_NO_FLUSH, "no flush?");
1264
+ if (s.match_available) {
1265
+ //Tracevv((stderr,"%c", s->window[s->strstart-1]));
1266
+ /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
1267
+ bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
1268
+
1269
+ s.match_available = 0;
1270
+ }
1271
+ s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
1272
+ if (flush === Z_FINISH) {
1273
+ /*** FLUSH_BLOCK(s, 1); ***/
1274
+ flush_block_only(s, true);
1275
+ if (s.strm.avail_out === 0) {
1276
+ return BS_FINISH_STARTED;
1277
+ }
1278
+ /***/
1279
+ return BS_FINISH_DONE;
1280
+ }
1281
+ if (s.last_lit) {
1282
+ /*** FLUSH_BLOCK(s, 0); ***/
1283
+ flush_block_only(s, false);
1284
+ if (s.strm.avail_out === 0) {
1285
+ return BS_NEED_MORE;
1286
+ }
1287
+ /***/
1288
+ }
1289
+
1290
+ return BS_BLOCK_DONE;
1291
+ }
1292
+
1293
+
1294
+ /* ===========================================================================
1295
+ * For Z_RLE, simply look for runs of bytes, generate matches only of distance
1296
+ * one. Do not maintain a hash table. (It will be regenerated if this run of
1297
+ * deflate switches away from Z_RLE.)
1298
+ */
1299
+ function deflate_rle(s, flush) {
1300
+ var bflush; /* set if current block must be flushed */
1301
+ var prev; /* byte at distance one to match */
1302
+ var scan, strend; /* scan goes up to strend for length of run */
1303
+
1304
+ var _win = s.window;
1305
+
1306
+ for (;;) {
1307
+ /* Make sure that we always have enough lookahead, except
1308
+ * at the end of the input file. We need MAX_MATCH bytes
1309
+ * for the longest run, plus one for the unrolled loop.
1310
+ */
1311
+ if (s.lookahead <= MAX_MATCH) {
1312
+ fill_window(s);
1313
+ if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
1314
+ return BS_NEED_MORE;
1315
+ }
1316
+ if (s.lookahead === 0) { break; } /* flush the current block */
1317
+ }
1318
+
1319
+ /* See how many times the previous byte repeats */
1320
+ s.match_length = 0;
1321
+ if (s.lookahead >= MIN_MATCH && s.strstart > 0) {
1322
+ scan = s.strstart - 1;
1323
+ prev = _win[scan];
1324
+ if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
1325
+ strend = s.strstart + MAX_MATCH;
1326
+ do {
1327
+ /*jshint noempty:false*/
1328
+ } while (prev === _win[++scan] && prev === _win[++scan] &&
1329
+ prev === _win[++scan] && prev === _win[++scan] &&
1330
+ prev === _win[++scan] && prev === _win[++scan] &&
1331
+ prev === _win[++scan] && prev === _win[++scan] &&
1332
+ scan < strend);
1333
+ s.match_length = MAX_MATCH - (strend - scan);
1334
+ if (s.match_length > s.lookahead) {
1335
+ s.match_length = s.lookahead;
1336
+ }
1337
+ }
1338
+ //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
1339
+ }
1340
+
1341
+ /* Emit match if have run of MIN_MATCH or longer, else emit literal */
1342
+ if (s.match_length >= MIN_MATCH) {
1343
+ //check_match(s, s.strstart, s.strstart - 1, s.match_length);
1344
+
1345
+ /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/
1346
+ bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);
1347
+
1348
+ s.lookahead -= s.match_length;
1349
+ s.strstart += s.match_length;
1350
+ s.match_length = 0;
1351
+ } else {
1352
+ /* No match, output a literal byte */
1353
+ //Tracevv((stderr,"%c", s->window[s->strstart]));
1354
+ /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
1355
+ bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
1356
+
1357
+ s.lookahead--;
1358
+ s.strstart++;
1359
+ }
1360
+ if (bflush) {
1361
+ /*** FLUSH_BLOCK(s, 0); ***/
1362
+ flush_block_only(s, false);
1363
+ if (s.strm.avail_out === 0) {
1364
+ return BS_NEED_MORE;
1365
+ }
1366
+ /***/
1367
+ }
1368
+ }
1369
+ s.insert = 0;
1370
+ if (flush === Z_FINISH) {
1371
+ /*** FLUSH_BLOCK(s, 1); ***/
1372
+ flush_block_only(s, true);
1373
+ if (s.strm.avail_out === 0) {
1374
+ return BS_FINISH_STARTED;
1375
+ }
1376
+ /***/
1377
+ return BS_FINISH_DONE;
1378
+ }
1379
+ if (s.last_lit) {
1380
+ /*** FLUSH_BLOCK(s, 0); ***/
1381
+ flush_block_only(s, false);
1382
+ if (s.strm.avail_out === 0) {
1383
+ return BS_NEED_MORE;
1384
+ }
1385
+ /***/
1386
+ }
1387
+ return BS_BLOCK_DONE;
1388
+ }
1389
+
1390
+ /* ===========================================================================
1391
+ * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
1392
+ * (It will be regenerated if this run of deflate switches away from Huffman.)
1393
+ */
1394
+ function deflate_huff(s, flush) {
1395
+ var bflush; /* set if current block must be flushed */
1396
+
1397
+ for (;;) {
1398
+ /* Make sure that we have a literal to write. */
1399
+ if (s.lookahead === 0) {
1400
+ fill_window(s);
1401
+ if (s.lookahead === 0) {
1402
+ if (flush === Z_NO_FLUSH) {
1403
+ return BS_NEED_MORE;
1404
+ }
1405
+ break; /* flush the current block */
1406
+ }
1407
+ }
1408
+
1409
+ /* Output a literal byte */
1410
+ s.match_length = 0;
1411
+ //Tracevv((stderr,"%c", s->window[s->strstart]));
1412
+ /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
1413
+ bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
1414
+ s.lookahead--;
1415
+ s.strstart++;
1416
+ if (bflush) {
1417
+ /*** FLUSH_BLOCK(s, 0); ***/
1418
+ flush_block_only(s, false);
1419
+ if (s.strm.avail_out === 0) {
1420
+ return BS_NEED_MORE;
1421
+ }
1422
+ /***/
1423
+ }
1424
+ }
1425
+ s.insert = 0;
1426
+ if (flush === Z_FINISH) {
1427
+ /*** FLUSH_BLOCK(s, 1); ***/
1428
+ flush_block_only(s, true);
1429
+ if (s.strm.avail_out === 0) {
1430
+ return BS_FINISH_STARTED;
1431
+ }
1432
+ /***/
1433
+ return BS_FINISH_DONE;
1434
+ }
1435
+ if (s.last_lit) {
1436
+ /*** FLUSH_BLOCK(s, 0); ***/
1437
+ flush_block_only(s, false);
1438
+ if (s.strm.avail_out === 0) {
1439
+ return BS_NEED_MORE;
1440
+ }
1441
+ /***/
1442
+ }
1443
+ return BS_BLOCK_DONE;
1444
+ }
1445
+
1446
+ /* Values for max_lazy_match, good_match and max_chain_length, depending on
1447
+ * the desired pack level (0..9). The values given below have been tuned to
1448
+ * exclude worst case performance for pathological files. Better values may be
1449
+ * found for specific files.
1450
+ */
1451
+ function Config(good_length, max_lazy, nice_length, max_chain, func) {
1452
+ this.good_length = good_length;
1453
+ this.max_lazy = max_lazy;
1454
+ this.nice_length = nice_length;
1455
+ this.max_chain = max_chain;
1456
+ this.func = func;
1457
+ }
1458
+
1459
+ var configuration_table;
1460
+
1461
+ configuration_table = [
1462
+ /* good lazy nice chain */
1463
+ new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */
1464
+ new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */
1465
+ new Config(4, 5, 16, 8, deflate_fast), /* 2 */
1466
+ new Config(4, 6, 32, 32, deflate_fast), /* 3 */
1467
+
1468
+ new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */
1469
+ new Config(8, 16, 32, 32, deflate_slow), /* 5 */
1470
+ new Config(8, 16, 128, 128, deflate_slow), /* 6 */
1471
+ new Config(8, 32, 128, 256, deflate_slow), /* 7 */
1472
+ new Config(32, 128, 258, 1024, deflate_slow), /* 8 */
1473
+ new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */
1474
+ ];
1475
+
1476
+
1477
+ /* ===========================================================================
1478
+ * Initialize the "longest match" routines for a new zlib stream
1479
+ */
1480
+ function lm_init(s) {
1481
+ s.window_size = 2 * s.w_size;
1482
+
1483
+ /*** CLEAR_HASH(s); ***/
1484
+ zero(s.head); // Fill with NIL (= 0);
1485
+
1486
+ /* Set the default configuration parameters:
1487
+ */
1488
+ s.max_lazy_match = configuration_table[s.level].max_lazy;
1489
+ s.good_match = configuration_table[s.level].good_length;
1490
+ s.nice_match = configuration_table[s.level].nice_length;
1491
+ s.max_chain_length = configuration_table[s.level].max_chain;
1492
+
1493
+ s.strstart = 0;
1494
+ s.block_start = 0;
1495
+ s.lookahead = 0;
1496
+ s.insert = 0;
1497
+ s.match_length = s.prev_length = MIN_MATCH - 1;
1498
+ s.match_available = 0;
1499
+ s.ins_h = 0;
1500
+ }
1501
+
1502
+
1503
+ function DeflateState() {
1504
+ this.strm = null; /* pointer back to this zlib stream */
1505
+ this.status = 0; /* as the name implies */
1506
+ this.pending_buf = null; /* output still pending */
1507
+ this.pending_buf_size = 0; /* size of pending_buf */
1508
+ this.pending_out = 0; /* next pending byte to output to the stream */
1509
+ this.pending = 0; /* nb of bytes in the pending buffer */
1510
+ this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
1511
+ this.gzhead = null; /* gzip header information to write */
1512
+ this.gzindex = 0; /* where in extra, name, or comment */
1513
+ this.method = Z_DEFLATED; /* can only be DEFLATED */
1514
+ this.last_flush = -1; /* value of flush param for previous deflate call */
1515
+
1516
+ this.w_size = 0; /* LZ77 window size (32K by default) */
1517
+ this.w_bits = 0; /* log2(w_size) (8..16) */
1518
+ this.w_mask = 0; /* w_size - 1 */
1519
+
1520
+ this.window = null;
1521
+ /* Sliding window. Input bytes are read into the second half of the window,
1522
+ * and move to the first half later to keep a dictionary of at least wSize
1523
+ * bytes. With this organization, matches are limited to a distance of
1524
+ * wSize-MAX_MATCH bytes, but this ensures that IO is always
1525
+ * performed with a length multiple of the block size.
1526
+ */
1527
+
1528
+ this.window_size = 0;
1529
+ /* Actual size of window: 2*wSize, except when the user input buffer
1530
+ * is directly used as sliding window.
1531
+ */
1532
+
1533
+ this.prev = null;
1534
+ /* Link to older string with same hash index. To limit the size of this
1535
+ * array to 64K, this link is maintained only for the last 32K strings.
1536
+ * An index in this array is thus a window index modulo 32K.
1537
+ */
1538
+
1539
+ this.head = null; /* Heads of the hash chains or NIL. */
1540
+
1541
+ this.ins_h = 0; /* hash index of string to be inserted */
1542
+ this.hash_size = 0; /* number of elements in hash table */
1543
+ this.hash_bits = 0; /* log2(hash_size) */
1544
+ this.hash_mask = 0; /* hash_size-1 */
1545
+
1546
+ this.hash_shift = 0;
1547
+ /* Number of bits by which ins_h must be shifted at each input
1548
+ * step. It must be such that after MIN_MATCH steps, the oldest
1549
+ * byte no longer takes part in the hash key, that is:
1550
+ * hash_shift * MIN_MATCH >= hash_bits
1551
+ */
1552
+
1553
+ this.block_start = 0;
1554
+ /* Window position at the beginning of the current output block. Gets
1555
+ * negative when the window is moved backwards.
1556
+ */
1557
+
1558
+ this.match_length = 0; /* length of best match */
1559
+ this.prev_match = 0; /* previous match */
1560
+ this.match_available = 0; /* set if previous match exists */
1561
+ this.strstart = 0; /* start of string to insert */
1562
+ this.match_start = 0; /* start of matching string */
1563
+ this.lookahead = 0; /* number of valid bytes ahead in window */
1564
+
1565
+ this.prev_length = 0;
1566
+ /* Length of the best match at previous step. Matches not greater than this
1567
+ * are discarded. This is used in the lazy match evaluation.
1568
+ */
1569
+
1570
+ this.max_chain_length = 0;
1571
+ /* To speed up deflation, hash chains are never searched beyond this
1572
+ * length. A higher limit improves compression ratio but degrades the
1573
+ * speed.
1574
+ */
1575
+
1576
+ this.max_lazy_match = 0;
1577
+ /* Attempt to find a better match only when the current match is strictly
1578
+ * smaller than this value. This mechanism is used only for compression
1579
+ * levels >= 4.
1580
+ */
1581
+ // That's alias to max_lazy_match, don't use directly
1582
+ //this.max_insert_length = 0;
1583
+ /* Insert new strings in the hash table only if the match length is not
1584
+ * greater than this length. This saves time but degrades compression.
1585
+ * max_insert_length is used only for compression levels <= 3.
1586
+ */
1587
+
1588
+ this.level = 0; /* compression level (1..9) */
1589
+ this.strategy = 0; /* favor or force Huffman coding*/
1590
+
1591
+ this.good_match = 0;
1592
+ /* Use a faster search when the previous match is longer than this */
1593
+
1594
+ this.nice_match = 0; /* Stop searching when current match exceeds this */
1595
+
1596
+ /* used by trees.c: */
1597
+
1598
+ /* Didn't use ct_data typedef below to suppress compiler warning */
1599
+
1600
+ // struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
1601
+ // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
1602
+ // struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
1603
+
1604
+ // Use flat array of DOUBLE size, with interleaved fata,
1605
+ // because JS does not support effective
1606
+ this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);
1607
+ this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2);
1608
+ this.bl_tree = new utils.Buf16((2 * BL_CODES + 1) * 2);
1609
+ zero(this.dyn_ltree);
1610
+ zero(this.dyn_dtree);
1611
+ zero(this.bl_tree);
1612
+
1613
+ this.l_desc = null; /* desc. for literal tree */
1614
+ this.d_desc = null; /* desc. for distance tree */
1615
+ this.bl_desc = null; /* desc. for bit length tree */
1616
+
1617
+ //ush bl_count[MAX_BITS+1];
1618
+ this.bl_count = new utils.Buf16(MAX_BITS + 1);
1619
+ /* number of codes at each bit length for an optimal tree */
1620
+
1621
+ //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
1622
+ this.heap = new utils.Buf16(2 * L_CODES + 1); /* heap used to build the Huffman trees */
1623
+ zero(this.heap);
1624
+
1625
+ this.heap_len = 0; /* number of elements in the heap */
1626
+ this.heap_max = 0; /* element of largest frequency */
1627
+ /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
1628
+ * The same heap array is used to build all trees.
1629
+ */
1630
+
1631
+ this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1];
1632
+ zero(this.depth);
1633
+ /* Depth of each subtree used as tie breaker for trees of equal frequency
1634
+ */
1635
+
1636
+ this.l_buf = 0; /* buffer index for literals or lengths */
1637
+
1638
+ this.lit_bufsize = 0;
1639
+ /* Size of match buffer for literals/lengths. There are 4 reasons for
1640
+ * limiting lit_bufsize to 64K:
1641
+ * - frequencies can be kept in 16 bit counters
1642
+ * - if compression is not successful for the first block, all input
1643
+ * data is still in the window so we can still emit a stored block even
1644
+ * when input comes from standard input. (This can also be done for
1645
+ * all blocks if lit_bufsize is not greater than 32K.)
1646
+ * - if compression is not successful for a file smaller than 64K, we can
1647
+ * even emit a stored file instead of a stored block (saving 5 bytes).
1648
+ * This is applicable only for zip (not gzip or zlib).
1649
+ * - creating new Huffman trees less frequently may not provide fast
1650
+ * adaptation to changes in the input data statistics. (Take for
1651
+ * example a binary file with poorly compressible code followed by
1652
+ * a highly compressible string table.) Smaller buffer sizes give
1653
+ * fast adaptation but have of course the overhead of transmitting
1654
+ * trees more frequently.
1655
+ * - I can't count above 4
1656
+ */
1657
+
1658
+ this.last_lit = 0; /* running index in l_buf */
1659
+
1660
+ this.d_buf = 0;
1661
+ /* Buffer index for distances. To simplify the code, d_buf and l_buf have
1662
+ * the same number of elements. To use different lengths, an extra flag
1663
+ * array would be necessary.
1664
+ */
1665
+
1666
+ this.opt_len = 0; /* bit length of current block with optimal trees */
1667
+ this.static_len = 0; /* bit length of current block with static trees */
1668
+ this.matches = 0; /* number of string matches in current block */
1669
+ this.insert = 0; /* bytes at end of window left to insert */
1670
+
1671
+
1672
+ this.bi_buf = 0;
1673
+ /* Output buffer. bits are inserted starting at the bottom (least
1674
+ * significant bits).
1675
+ */
1676
+ this.bi_valid = 0;
1677
+ /* Number of valid bits in bi_buf. All bits above the last valid bit
1678
+ * are always zero.
1679
+ */
1680
+
1681
+ // Used for window memory init. We safely ignore it for JS. That makes
1682
+ // sense only for pointers and memory check tools.
1683
+ //this.high_water = 0;
1684
+ /* High water mark offset in window for initialized bytes -- bytes above
1685
+ * this are set to zero in order to avoid memory check warnings when
1686
+ * longest match routines access bytes past the input. This is then
1687
+ * updated to the new high water mark.
1688
+ */
1689
+ }
1690
+
1691
+
1692
+ function deflateResetKeep(strm) {
1693
+ var s;
1694
+
1695
+ if (!strm || !strm.state) {
1696
+ return err(strm, Z_STREAM_ERROR);
1697
+ }
1698
+
1699
+ strm.total_in = strm.total_out = 0;
1700
+ strm.data_type = Z_UNKNOWN;
1701
+
1702
+ s = strm.state;
1703
+ s.pending = 0;
1704
+ s.pending_out = 0;
1705
+
1706
+ if (s.wrap < 0) {
1707
+ s.wrap = -s.wrap;
1708
+ /* was made negative by deflate(..., Z_FINISH); */
1709
+ }
1710
+ s.status = (s.wrap ? INIT_STATE : BUSY_STATE);
1711
+ strm.adler = (s.wrap === 2) ?
1712
+ 0 // crc32(0, Z_NULL, 0)
1713
+ :
1714
+ 1; // adler32(0, Z_NULL, 0)
1715
+ s.last_flush = Z_NO_FLUSH;
1716
+ trees._tr_init(s);
1717
+ return Z_OK;
1718
+ }
1719
+
1720
+
1721
+ function deflateReset(strm) {
1722
+ var ret = deflateResetKeep(strm);
1723
+ if (ret === Z_OK) {
1724
+ lm_init(strm.state);
1725
+ }
1726
+ return ret;
1727
+ }
1728
+
1729
+
1730
+ function deflateSetHeader(strm, head) {
1731
+ if (!strm || !strm.state) { return Z_STREAM_ERROR; }
1732
+ if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; }
1733
+ strm.state.gzhead = head;
1734
+ return Z_OK;
1735
+ }
1736
+
1737
+
1738
+ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
1739
+ if (!strm) { // === Z_NULL
1740
+ return Z_STREAM_ERROR;
1741
+ }
1742
+ var wrap = 1;
1743
+
1744
+ if (level === Z_DEFAULT_COMPRESSION) {
1745
+ level = 6;
1746
+ }
1747
+
1748
+ if (windowBits < 0) { /* suppress zlib wrapper */
1749
+ wrap = 0;
1750
+ windowBits = -windowBits;
1751
+ }
1752
+
1753
+ else if (windowBits > 15) {
1754
+ wrap = 2; /* write gzip wrapper instead */
1755
+ windowBits -= 16;
1756
+ }
1757
+
1758
+
1759
+ if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED ||
1760
+ windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
1761
+ strategy < 0 || strategy > Z_FIXED) {
1762
+ return err(strm, Z_STREAM_ERROR);
1763
+ }
1764
+
1765
+
1766
+ if (windowBits === 8) {
1767
+ windowBits = 9;
1768
+ }
1769
+ /* until 256-byte window bug fixed */
1770
+
1771
+ var s = new DeflateState();
1772
+
1773
+ strm.state = s;
1774
+ s.strm = strm;
1775
+
1776
+ s.wrap = wrap;
1777
+ s.gzhead = null;
1778
+ s.w_bits = windowBits;
1779
+ s.w_size = 1 << s.w_bits;
1780
+ s.w_mask = s.w_size - 1;
1781
+
1782
+ s.hash_bits = memLevel + 7;
1783
+ s.hash_size = 1 << s.hash_bits;
1784
+ s.hash_mask = s.hash_size - 1;
1785
+ s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
1786
+
1787
+ s.window = new utils.Buf8(s.w_size * 2);
1788
+ s.head = new utils.Buf16(s.hash_size);
1789
+ s.prev = new utils.Buf16(s.w_size);
1790
+
1791
+ // Don't need mem init magic for JS.
1792
+ //s.high_water = 0; /* nothing written to s->window yet */
1793
+
1794
+ s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
1795
+
1796
+ s.pending_buf_size = s.lit_bufsize * 4;
1797
+
1798
+ //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
1799
+ //s->pending_buf = (uchf *) overlay;
1800
+ s.pending_buf = new utils.Buf8(s.pending_buf_size);
1801
+
1802
+ // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)
1803
+ //s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
1804
+ s.d_buf = 1 * s.lit_bufsize;
1805
+
1806
+ //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
1807
+ s.l_buf = (1 + 2) * s.lit_bufsize;
1808
+
1809
+ s.level = level;
1810
+ s.strategy = strategy;
1811
+ s.method = method;
1812
+
1813
+ return deflateReset(strm);
1814
+ }
1815
+
1816
+ function deflateInit(strm, level) {
1817
+ return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
1818
+ }
1819
+
1820
+
1821
+ function deflate(strm, flush) {
1822
+ var old_flush, s;
1823
+ var beg, val; // for gzip header write only
1824
+
1825
+ if (!strm || !strm.state ||
1826
+ flush > Z_BLOCK || flush < 0) {
1827
+ return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;
1828
+ }
1829
+
1830
+ s = strm.state;
1831
+
1832
+ if (!strm.output ||
1833
+ (!strm.input && strm.avail_in !== 0) ||
1834
+ (s.status === FINISH_STATE && flush !== Z_FINISH)) {
1835
+ return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR);
1836
+ }
1837
+
1838
+ s.strm = strm; /* just in case */
1839
+ old_flush = s.last_flush;
1840
+ s.last_flush = flush;
1841
+
1842
+ /* Write the header */
1843
+ if (s.status === INIT_STATE) {
1844
+
1845
+ if (s.wrap === 2) { // GZIP header
1846
+ strm.adler = 0; //crc32(0L, Z_NULL, 0);
1847
+ put_byte(s, 31);
1848
+ put_byte(s, 139);
1849
+ put_byte(s, 8);
1850
+ if (!s.gzhead) { // s->gzhead == Z_NULL
1851
+ put_byte(s, 0);
1852
+ put_byte(s, 0);
1853
+ put_byte(s, 0);
1854
+ put_byte(s, 0);
1855
+ put_byte(s, 0);
1856
+ put_byte(s, s.level === 9 ? 2 :
1857
+ (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
1858
+ 4 : 0));
1859
+ put_byte(s, OS_CODE);
1860
+ s.status = BUSY_STATE;
1861
+ }
1862
+ else {
1863
+ put_byte(s, (s.gzhead.text ? 1 : 0) +
1864
+ (s.gzhead.hcrc ? 2 : 0) +
1865
+ (!s.gzhead.extra ? 0 : 4) +
1866
+ (!s.gzhead.name ? 0 : 8) +
1867
+ (!s.gzhead.comment ? 0 : 16)
1868
+ );
1869
+ put_byte(s, s.gzhead.time & 0xff);
1870
+ put_byte(s, (s.gzhead.time >> 8) & 0xff);
1871
+ put_byte(s, (s.gzhead.time >> 16) & 0xff);
1872
+ put_byte(s, (s.gzhead.time >> 24) & 0xff);
1873
+ put_byte(s, s.level === 9 ? 2 :
1874
+ (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
1875
+ 4 : 0));
1876
+ put_byte(s, s.gzhead.os & 0xff);
1877
+ if (s.gzhead.extra && s.gzhead.extra.length) {
1878
+ put_byte(s, s.gzhead.extra.length & 0xff);
1879
+ put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);
1880
+ }
1881
+ if (s.gzhead.hcrc) {
1882
+ strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);
1883
+ }
1884
+ s.gzindex = 0;
1885
+ s.status = EXTRA_STATE;
1886
+ }
1887
+ }
1888
+ else // DEFLATE header
1889
+ {
1890
+ var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;
1891
+ var level_flags = -1;
1892
+
1893
+ if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
1894
+ level_flags = 0;
1895
+ } else if (s.level < 6) {
1896
+ level_flags = 1;
1897
+ } else if (s.level === 6) {
1898
+ level_flags = 2;
1899
+ } else {
1900
+ level_flags = 3;
1901
+ }
1902
+ header |= (level_flags << 6);
1903
+ if (s.strstart !== 0) { header |= PRESET_DICT; }
1904
+ header += 31 - (header % 31);
1905
+
1906
+ s.status = BUSY_STATE;
1907
+ putShortMSB(s, header);
1908
+
1909
+ /* Save the adler32 of the preset dictionary: */
1910
+ if (s.strstart !== 0) {
1911
+ putShortMSB(s, strm.adler >>> 16);
1912
+ putShortMSB(s, strm.adler & 0xffff);
1913
+ }
1914
+ strm.adler = 1; // adler32(0L, Z_NULL, 0);
1915
+ }
1916
+ }
1917
+
1918
+ //#ifdef GZIP
1919
+ if (s.status === EXTRA_STATE) {
1920
+ if (s.gzhead.extra/* != Z_NULL*/) {
1921
+ beg = s.pending; /* start of bytes to update crc */
1922
+
1923
+ while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {
1924
+ if (s.pending === s.pending_buf_size) {
1925
+ if (s.gzhead.hcrc && s.pending > beg) {
1926
+ strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
1927
+ }
1928
+ flush_pending(strm);
1929
+ beg = s.pending;
1930
+ if (s.pending === s.pending_buf_size) {
1931
+ break;
1932
+ }
1933
+ }
1934
+ put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);
1935
+ s.gzindex++;
1936
+ }
1937
+ if (s.gzhead.hcrc && s.pending > beg) {
1938
+ strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
1939
+ }
1940
+ if (s.gzindex === s.gzhead.extra.length) {
1941
+ s.gzindex = 0;
1942
+ s.status = NAME_STATE;
1943
+ }
1944
+ }
1945
+ else {
1946
+ s.status = NAME_STATE;
1947
+ }
1948
+ }
1949
+ if (s.status === NAME_STATE) {
1950
+ if (s.gzhead.name/* != Z_NULL*/) {
1951
+ beg = s.pending; /* start of bytes to update crc */
1952
+ //int val;
1953
+
1954
+ do {
1955
+ if (s.pending === s.pending_buf_size) {
1956
+ if (s.gzhead.hcrc && s.pending > beg) {
1957
+ strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
1958
+ }
1959
+ flush_pending(strm);
1960
+ beg = s.pending;
1961
+ if (s.pending === s.pending_buf_size) {
1962
+ val = 1;
1963
+ break;
1964
+ }
1965
+ }
1966
+ // JS specific: little magic to add zero terminator to end of string
1967
+ if (s.gzindex < s.gzhead.name.length) {
1968
+ val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;
1969
+ } else {
1970
+ val = 0;
1971
+ }
1972
+ put_byte(s, val);
1973
+ } while (val !== 0);
1974
+
1975
+ if (s.gzhead.hcrc && s.pending > beg) {
1976
+ strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
1977
+ }
1978
+ if (val === 0) {
1979
+ s.gzindex = 0;
1980
+ s.status = COMMENT_STATE;
1981
+ }
1982
+ }
1983
+ else {
1984
+ s.status = COMMENT_STATE;
1985
+ }
1986
+ }
1987
+ if (s.status === COMMENT_STATE) {
1988
+ if (s.gzhead.comment/* != Z_NULL*/) {
1989
+ beg = s.pending; /* start of bytes to update crc */
1990
+ //int val;
1991
+
1992
+ do {
1993
+ if (s.pending === s.pending_buf_size) {
1994
+ if (s.gzhead.hcrc && s.pending > beg) {
1995
+ strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
1996
+ }
1997
+ flush_pending(strm);
1998
+ beg = s.pending;
1999
+ if (s.pending === s.pending_buf_size) {
2000
+ val = 1;
2001
+ break;
2002
+ }
2003
+ }
2004
+ // JS specific: little magic to add zero terminator to end of string
2005
+ if (s.gzindex < s.gzhead.comment.length) {
2006
+ val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;
2007
+ } else {
2008
+ val = 0;
2009
+ }
2010
+ put_byte(s, val);
2011
+ } while (val !== 0);
2012
+
2013
+ if (s.gzhead.hcrc && s.pending > beg) {
2014
+ strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
2015
+ }
2016
+ if (val === 0) {
2017
+ s.status = HCRC_STATE;
2018
+ }
2019
+ }
2020
+ else {
2021
+ s.status = HCRC_STATE;
2022
+ }
2023
+ }
2024
+ if (s.status === HCRC_STATE) {
2025
+ if (s.gzhead.hcrc) {
2026
+ if (s.pending + 2 > s.pending_buf_size) {
2027
+ flush_pending(strm);
2028
+ }
2029
+ if (s.pending + 2 <= s.pending_buf_size) {
2030
+ put_byte(s, strm.adler & 0xff);
2031
+ put_byte(s, (strm.adler >> 8) & 0xff);
2032
+ strm.adler = 0; //crc32(0L, Z_NULL, 0);
2033
+ s.status = BUSY_STATE;
2034
+ }
2035
+ }
2036
+ else {
2037
+ s.status = BUSY_STATE;
2038
+ }
2039
+ }
2040
+ //#endif
2041
+
2042
+ /* Flush as much pending output as possible */
2043
+ if (s.pending !== 0) {
2044
+ flush_pending(strm);
2045
+ if (strm.avail_out === 0) {
2046
+ /* Since avail_out is 0, deflate will be called again with
2047
+ * more output space, but possibly with both pending and
2048
+ * avail_in equal to zero. There won't be anything to do,
2049
+ * but this is not an error situation so make sure we
2050
+ * return OK instead of BUF_ERROR at next call of deflate:
2051
+ */
2052
+ s.last_flush = -1;
2053
+ return Z_OK;
2054
+ }
2055
+
2056
+ /* Make sure there is something to do and avoid duplicate consecutive
2057
+ * flushes. For repeated and useless calls with Z_FINISH, we keep
2058
+ * returning Z_STREAM_END instead of Z_BUF_ERROR.
2059
+ */
2060
+ } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
2061
+ flush !== Z_FINISH) {
2062
+ return err(strm, Z_BUF_ERROR);
2063
+ }
2064
+
2065
+ /* User must not provide more input after the first FINISH: */
2066
+ if (s.status === FINISH_STATE && strm.avail_in !== 0) {
2067
+ return err(strm, Z_BUF_ERROR);
2068
+ }
2069
+
2070
+ /* Start a new block or continue the current one.
2071
+ */
2072
+ if (strm.avail_in !== 0 || s.lookahead !== 0 ||
2073
+ (flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) {
2074
+ var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) :
2075
+ (s.strategy === Z_RLE ? deflate_rle(s, flush) :
2076
+ configuration_table[s.level].func(s, flush));
2077
+
2078
+ if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
2079
+ s.status = FINISH_STATE;
2080
+ }
2081
+ if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {
2082
+ if (strm.avail_out === 0) {
2083
+ s.last_flush = -1;
2084
+ /* avoid BUF_ERROR next call, see above */
2085
+ }
2086
+ return Z_OK;
2087
+ /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
2088
+ * of deflate should use the same flush parameter to make sure
2089
+ * that the flush is complete. So we don't have to output an
2090
+ * empty block here, this will be done at next call. This also
2091
+ * ensures that for a very small output buffer, we emit at most
2092
+ * one empty block.
2093
+ */
2094
+ }
2095
+ if (bstate === BS_BLOCK_DONE) {
2096
+ if (flush === Z_PARTIAL_FLUSH) {
2097
+ trees._tr_align(s);
2098
+ }
2099
+ else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
2100
+
2101
+ trees._tr_stored_block(s, 0, 0, false);
2102
+ /* For a full flush, this empty block will be recognized
2103
+ * as a special marker by inflate_sync().
2104
+ */
2105
+ if (flush === Z_FULL_FLUSH) {
2106
+ /*** CLEAR_HASH(s); ***/ /* forget history */
2107
+ zero(s.head); // Fill with NIL (= 0);
2108
+
2109
+ if (s.lookahead === 0) {
2110
+ s.strstart = 0;
2111
+ s.block_start = 0;
2112
+ s.insert = 0;
2113
+ }
2114
+ }
2115
+ }
2116
+ flush_pending(strm);
2117
+ if (strm.avail_out === 0) {
2118
+ s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */
2119
+ return Z_OK;
2120
+ }
2121
+ }
2122
+ }
2123
+ //Assert(strm->avail_out > 0, "bug2");
2124
+ //if (strm.avail_out <= 0) { throw new Error("bug2");}
2125
+
2126
+ if (flush !== Z_FINISH) { return Z_OK; }
2127
+ if (s.wrap <= 0) { return Z_STREAM_END; }
2128
+
2129
+ /* Write the trailer */
2130
+ if (s.wrap === 2) {
2131
+ put_byte(s, strm.adler & 0xff);
2132
+ put_byte(s, (strm.adler >> 8) & 0xff);
2133
+ put_byte(s, (strm.adler >> 16) & 0xff);
2134
+ put_byte(s, (strm.adler >> 24) & 0xff);
2135
+ put_byte(s, strm.total_in & 0xff);
2136
+ put_byte(s, (strm.total_in >> 8) & 0xff);
2137
+ put_byte(s, (strm.total_in >> 16) & 0xff);
2138
+ put_byte(s, (strm.total_in >> 24) & 0xff);
2139
+ }
2140
+ else
2141
+ {
2142
+ putShortMSB(s, strm.adler >>> 16);
2143
+ putShortMSB(s, strm.adler & 0xffff);
2144
+ }
2145
+
2146
+ flush_pending(strm);
2147
+ /* If avail_out is zero, the application will call deflate again
2148
+ * to flush the rest.
2149
+ */
2150
+ if (s.wrap > 0) { s.wrap = -s.wrap; }
2151
+ /* write the trailer only once! */
2152
+ return s.pending !== 0 ? Z_OK : Z_STREAM_END;
2153
+ }
2154
+
2155
+ function deflateEnd(strm) {
2156
+ var status;
2157
+
2158
+ if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
2159
+ return Z_STREAM_ERROR;
2160
+ }
2161
+
2162
+ status = strm.state.status;
2163
+ if (status !== INIT_STATE &&
2164
+ status !== EXTRA_STATE &&
2165
+ status !== NAME_STATE &&
2166
+ status !== COMMENT_STATE &&
2167
+ status !== HCRC_STATE &&
2168
+ status !== BUSY_STATE &&
2169
+ status !== FINISH_STATE
2170
+ ) {
2171
+ return err(strm, Z_STREAM_ERROR);
2172
+ }
2173
+
2174
+ strm.state = null;
2175
+
2176
+ return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
2177
+ }
2178
+
2179
+
2180
+ /* =========================================================================
2181
+ * Initializes the compression dictionary from the given byte
2182
+ * sequence without producing any compressed output.
2183
+ */
2184
+ function deflateSetDictionary(strm, dictionary) {
2185
+ var dictLength = dictionary.length;
2186
+
2187
+ var s;
2188
+ var str, n;
2189
+ var wrap;
2190
+ var avail;
2191
+ var next;
2192
+ var input;
2193
+ var tmpDict;
2194
+
2195
+ if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
2196
+ return Z_STREAM_ERROR;
2197
+ }
2198
+
2199
+ s = strm.state;
2200
+ wrap = s.wrap;
2201
+
2202
+ if (wrap === 2 || (wrap === 1 && s.status !== INIT_STATE) || s.lookahead) {
2203
+ return Z_STREAM_ERROR;
2204
+ }
2205
+
2206
+ /* when using zlib wrappers, compute Adler-32 for provided dictionary */
2207
+ if (wrap === 1) {
2208
+ /* adler32(strm->adler, dictionary, dictLength); */
2209
+ strm.adler = adler32(strm.adler, dictionary, dictLength, 0);
2210
+ }
2211
+
2212
+ s.wrap = 0; /* avoid computing Adler-32 in read_buf */
2213
+
2214
+ /* if dictionary would fill window, just replace the history */
2215
+ if (dictLength >= s.w_size) {
2216
+ if (wrap === 0) { /* already empty otherwise */
2217
+ /*** CLEAR_HASH(s); ***/
2218
+ zero(s.head); // Fill with NIL (= 0);
2219
+ s.strstart = 0;
2220
+ s.block_start = 0;
2221
+ s.insert = 0;
2222
+ }
2223
+ /* use the tail */
2224
+ // dictionary = dictionary.slice(dictLength - s.w_size);
2225
+ tmpDict = new utils.Buf8(s.w_size);
2226
+ utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);
2227
+ dictionary = tmpDict;
2228
+ dictLength = s.w_size;
2229
+ }
2230
+ /* insert dictionary into window and hash */
2231
+ avail = strm.avail_in;
2232
+ next = strm.next_in;
2233
+ input = strm.input;
2234
+ strm.avail_in = dictLength;
2235
+ strm.next_in = 0;
2236
+ strm.input = dictionary;
2237
+ fill_window(s);
2238
+ while (s.lookahead >= MIN_MATCH) {
2239
+ str = s.strstart;
2240
+ n = s.lookahead - (MIN_MATCH - 1);
2241
+ do {
2242
+ /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
2243
+ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
2244
+
2245
+ s.prev[str & s.w_mask] = s.head[s.ins_h];
2246
+
2247
+ s.head[s.ins_h] = str;
2248
+ str++;
2249
+ } while (--n);
2250
+ s.strstart = str;
2251
+ s.lookahead = MIN_MATCH - 1;
2252
+ fill_window(s);
2253
+ }
2254
+ s.strstart += s.lookahead;
2255
+ s.block_start = s.strstart;
2256
+ s.insert = s.lookahead;
2257
+ s.lookahead = 0;
2258
+ s.match_length = s.prev_length = MIN_MATCH - 1;
2259
+ s.match_available = 0;
2260
+ strm.next_in = next;
2261
+ strm.input = input;
2262
+ strm.avail_in = avail;
2263
+ s.wrap = wrap;
2264
+ return Z_OK;
2265
+ }
2266
+
2267
+
2268
+ exports.deflateInit = deflateInit;
2269
+ exports.deflateInit2 = deflateInit2;
2270
+ exports.deflateReset = deflateReset;
2271
+ exports.deflateResetKeep = deflateResetKeep;
2272
+ exports.deflateSetHeader = deflateSetHeader;
2273
+ exports.deflate = deflate;
2274
+ exports.deflateEnd = deflateEnd;
2275
+ exports.deflateSetDictionary = deflateSetDictionary;
2276
+ exports.deflateInfo = 'pako deflate (from Nodeca project)';
2277
+
2278
+ /* Not implemented
2279
+ exports.deflateBound = deflateBound;
2280
+ exports.deflateCopy = deflateCopy;
2281
+ exports.deflateParams = deflateParams;
2282
+ exports.deflatePending = deflatePending;
2283
+ exports.deflatePrime = deflatePrime;
2284
+ exports.deflateTune = deflateTune;
2285
+ */
2286
+
2287
+ },{"../utils/common":1,"./adler32":3,"./crc32":4,"./messages":6,"./trees":7}],6:[function(require,module,exports){
2288
+ 'use strict';
2289
+
2290
+ // (C) 1995-2013 Jean-loup Gailly and Mark Adler
2291
+ // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
2292
+ //
2293
+ // This software is provided 'as-is', without any express or implied
2294
+ // warranty. In no event will the authors be held liable for any damages
2295
+ // arising from the use of this software.
2296
+ //
2297
+ // Permission is granted to anyone to use this software for any purpose,
2298
+ // including commercial applications, and to alter it and redistribute it
2299
+ // freely, subject to the following restrictions:
2300
+ //
2301
+ // 1. The origin of this software must not be misrepresented; you must not
2302
+ // claim that you wrote the original software. If you use this software
2303
+ // in a product, an acknowledgment in the product documentation would be
2304
+ // appreciated but is not required.
2305
+ // 2. Altered source versions must be plainly marked as such, and must not be
2306
+ // misrepresented as being the original software.
2307
+ // 3. This notice may not be removed or altered from any source distribution.
2308
+
2309
+ module.exports = {
2310
+ 2: 'need dictionary', /* Z_NEED_DICT 2 */
2311
+ 1: 'stream end', /* Z_STREAM_END 1 */
2312
+ 0: '', /* Z_OK 0 */
2313
+ '-1': 'file error', /* Z_ERRNO (-1) */
2314
+ '-2': 'stream error', /* Z_STREAM_ERROR (-2) */
2315
+ '-3': 'data error', /* Z_DATA_ERROR (-3) */
2316
+ '-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */
2317
+ '-5': 'buffer error', /* Z_BUF_ERROR (-5) */
2318
+ '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
2319
+ };
2320
+
2321
+ },{}],7:[function(require,module,exports){
2322
+ 'use strict';
2323
+
2324
+ // (C) 1995-2013 Jean-loup Gailly and Mark Adler
2325
+ // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
2326
+ //
2327
+ // This software is provided 'as-is', without any express or implied
2328
+ // warranty. In no event will the authors be held liable for any damages
2329
+ // arising from the use of this software.
2330
+ //
2331
+ // Permission is granted to anyone to use this software for any purpose,
2332
+ // including commercial applications, and to alter it and redistribute it
2333
+ // freely, subject to the following restrictions:
2334
+ //
2335
+ // 1. The origin of this software must not be misrepresented; you must not
2336
+ // claim that you wrote the original software. If you use this software
2337
+ // in a product, an acknowledgment in the product documentation would be
2338
+ // appreciated but is not required.
2339
+ // 2. Altered source versions must be plainly marked as such, and must not be
2340
+ // misrepresented as being the original software.
2341
+ // 3. This notice may not be removed or altered from any source distribution.
2342
+
2343
+ /* eslint-disable space-unary-ops */
2344
+
2345
+ var utils = require('../utils/common');
2346
+
2347
+ /* Public constants ==========================================================*/
2348
+ /* ===========================================================================*/
2349
+
2350
+
2351
+ //var Z_FILTERED = 1;
2352
+ //var Z_HUFFMAN_ONLY = 2;
2353
+ //var Z_RLE = 3;
2354
+ var Z_FIXED = 4;
2355
+ //var Z_DEFAULT_STRATEGY = 0;
2356
+
2357
+ /* Possible values of the data_type field (though see inflate()) */
2358
+ var Z_BINARY = 0;
2359
+ var Z_TEXT = 1;
2360
+ //var Z_ASCII = 1; // = Z_TEXT
2361
+ var Z_UNKNOWN = 2;
2362
+
2363
+ /*============================================================================*/
2364
+
2365
+
2366
+ function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
2367
+
2368
+ // From zutil.h
2369
+
2370
+ var STORED_BLOCK = 0;
2371
+ var STATIC_TREES = 1;
2372
+ var DYN_TREES = 2;
2373
+ /* The three kinds of block type */
2374
+
2375
+ var MIN_MATCH = 3;
2376
+ var MAX_MATCH = 258;
2377
+ /* The minimum and maximum match lengths */
2378
+
2379
+ // From deflate.h
2380
+ /* ===========================================================================
2381
+ * Internal compression state.
2382
+ */
2383
+
2384
+ var LENGTH_CODES = 29;
2385
+ /* number of length codes, not counting the special END_BLOCK code */
2386
+
2387
+ var LITERALS = 256;
2388
+ /* number of literal bytes 0..255 */
2389
+
2390
+ var L_CODES = LITERALS + 1 + LENGTH_CODES;
2391
+ /* number of Literal or Length codes, including the END_BLOCK code */
2392
+
2393
+ var D_CODES = 30;
2394
+ /* number of distance codes */
2395
+
2396
+ var BL_CODES = 19;
2397
+ /* number of codes used to transfer the bit lengths */
2398
+
2399
+ var HEAP_SIZE = 2 * L_CODES + 1;
2400
+ /* maximum heap size */
2401
+
2402
+ var MAX_BITS = 15;
2403
+ /* All codes must not exceed MAX_BITS bits */
2404
+
2405
+ var Buf_size = 16;
2406
+ /* size of bit buffer in bi_buf */
2407
+
2408
+
2409
+ /* ===========================================================================
2410
+ * Constants
2411
+ */
2412
+
2413
+ var MAX_BL_BITS = 7;
2414
+ /* Bit length codes must not exceed MAX_BL_BITS bits */
2415
+
2416
+ var END_BLOCK = 256;
2417
+ /* end of block literal code */
2418
+
2419
+ var REP_3_6 = 16;
2420
+ /* repeat previous bit length 3-6 times (2 bits of repeat count) */
2421
+
2422
+ var REPZ_3_10 = 17;
2423
+ /* repeat a zero length 3-10 times (3 bits of repeat count) */
2424
+
2425
+ var REPZ_11_138 = 18;
2426
+ /* repeat a zero length 11-138 times (7 bits of repeat count) */
2427
+
2428
+ /* eslint-disable comma-spacing,array-bracket-spacing */
2429
+ var extra_lbits = /* extra bits for each length code */
2430
+ [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];
2431
+
2432
+ var extra_dbits = /* extra bits for each distance code */
2433
+ [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,13,13];
2434
+
2435
+ var extra_blbits = /* extra bits for each bit length code */
2436
+ [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];
2437
+
2438
+ var bl_order =
2439
+ [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
2440
+ /* eslint-enable comma-spacing,array-bracket-spacing */
2441
+
2442
+ /* The lengths of the bit length codes are sent in order of decreasing
2443
+ * probability, to avoid transmitting the lengths for unused bit length codes.
2444
+ */
2445
+
2446
+ /* ===========================================================================
2447
+ * Local data. These are initialized only once.
2448
+ */
2449
+
2450
+ // We pre-fill arrays with 0 to avoid uninitialized gaps
2451
+
2452
+ var DIST_CODE_LEN = 512; /* see definition of array dist_code below */
2453
+
2454
+ // !!!! Use flat array instead of structure, Freq = i*2, Len = i*2+1
2455
+ var static_ltree = new Array((L_CODES + 2) * 2);
2456
+ zero(static_ltree);
2457
+ /* The static literal tree. Since the bit lengths are imposed, there is no
2458
+ * need for the L_CODES extra codes used during heap construction. However
2459
+ * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
2460
+ * below).
2461
+ */
2462
+
2463
+ var static_dtree = new Array(D_CODES * 2);
2464
+ zero(static_dtree);
2465
+ /* The static distance tree. (Actually a trivial tree since all codes use
2466
+ * 5 bits.)
2467
+ */
2468
+
2469
+ var _dist_code = new Array(DIST_CODE_LEN);
2470
+ zero(_dist_code);
2471
+ /* Distance codes. The first 256 values correspond to the distances
2472
+ * 3 .. 258, the last 256 values correspond to the top 8 bits of
2473
+ * the 15 bit distances.
2474
+ */
2475
+
2476
+ var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1);
2477
+ zero(_length_code);
2478
+ /* length code for each normalized match length (0 == MIN_MATCH) */
2479
+
2480
+ var base_length = new Array(LENGTH_CODES);
2481
+ zero(base_length);
2482
+ /* First normalized length for each code (0 = MIN_MATCH) */
2483
+
2484
+ var base_dist = new Array(D_CODES);
2485
+ zero(base_dist);
2486
+ /* First normalized distance for each code (0 = distance of 1) */
2487
+
2488
+
2489
+ function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
2490
+
2491
+ this.static_tree = static_tree; /* static tree or NULL */
2492
+ this.extra_bits = extra_bits; /* extra bits for each code or NULL */
2493
+ this.extra_base = extra_base; /* base index for extra_bits */
2494
+ this.elems = elems; /* max number of elements in the tree */
2495
+ this.max_length = max_length; /* max bit length for the codes */
2496
+
2497
+ // show if `static_tree` has data or dummy - needed for monomorphic objects
2498
+ this.has_stree = static_tree && static_tree.length;
2499
+ }
2500
+
2501
+
2502
+ var static_l_desc;
2503
+ var static_d_desc;
2504
+ var static_bl_desc;
2505
+
2506
+
2507
+ function TreeDesc(dyn_tree, stat_desc) {
2508
+ this.dyn_tree = dyn_tree; /* the dynamic tree */
2509
+ this.max_code = 0; /* largest code with non zero frequency */
2510
+ this.stat_desc = stat_desc; /* the corresponding static tree */
2511
+ }
2512
+
2513
+
2514
+
2515
+ function d_code(dist) {
2516
+ return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
2517
+ }
2518
+
2519
+
2520
+ /* ===========================================================================
2521
+ * Output a short LSB first on the stream.
2522
+ * IN assertion: there is enough room in pendingBuf.
2523
+ */
2524
+ function put_short(s, w) {
2525
+ // put_byte(s, (uch)((w) & 0xff));
2526
+ // put_byte(s, (uch)((ush)(w) >> 8));
2527
+ s.pending_buf[s.pending++] = (w) & 0xff;
2528
+ s.pending_buf[s.pending++] = (w >>> 8) & 0xff;
2529
+ }
2530
+
2531
+
2532
+ /* ===========================================================================
2533
+ * Send a value on a given number of bits.
2534
+ * IN assertion: length <= 16 and value fits in length bits.
2535
+ */
2536
+ function send_bits(s, value, length) {
2537
+ if (s.bi_valid > (Buf_size - length)) {
2538
+ s.bi_buf |= (value << s.bi_valid) & 0xffff;
2539
+ put_short(s, s.bi_buf);
2540
+ s.bi_buf = value >> (Buf_size - s.bi_valid);
2541
+ s.bi_valid += length - Buf_size;
2542
+ } else {
2543
+ s.bi_buf |= (value << s.bi_valid) & 0xffff;
2544
+ s.bi_valid += length;
2545
+ }
2546
+ }
2547
+
2548
+
2549
+ function send_code(s, c, tree) {
2550
+ send_bits(s, tree[c * 2]/*.Code*/, tree[c * 2 + 1]/*.Len*/);
2551
+ }
2552
+
2553
+
2554
+ /* ===========================================================================
2555
+ * Reverse the first len bits of a code, using straightforward code (a faster
2556
+ * method would use a table)
2557
+ * IN assertion: 1 <= len <= 15
2558
+ */
2559
+ function bi_reverse(code, len) {
2560
+ var res = 0;
2561
+ do {
2562
+ res |= code & 1;
2563
+ code >>>= 1;
2564
+ res <<= 1;
2565
+ } while (--len > 0);
2566
+ return res >>> 1;
2567
+ }
2568
+
2569
+
2570
+ /* ===========================================================================
2571
+ * Flush the bit buffer, keeping at most 7 bits in it.
2572
+ */
2573
+ function bi_flush(s) {
2574
+ if (s.bi_valid === 16) {
2575
+ put_short(s, s.bi_buf);
2576
+ s.bi_buf = 0;
2577
+ s.bi_valid = 0;
2578
+
2579
+ } else if (s.bi_valid >= 8) {
2580
+ s.pending_buf[s.pending++] = s.bi_buf & 0xff;
2581
+ s.bi_buf >>= 8;
2582
+ s.bi_valid -= 8;
2583
+ }
2584
+ }
2585
+
2586
+
2587
+ /* ===========================================================================
2588
+ * Compute the optimal bit lengths for a tree and update the total bit length
2589
+ * for the current block.
2590
+ * IN assertion: the fields freq and dad are set, heap[heap_max] and
2591
+ * above are the tree nodes sorted by increasing frequency.
2592
+ * OUT assertions: the field len is set to the optimal bit length, the
2593
+ * array bl_count contains the frequencies for each bit length.
2594
+ * The length opt_len is updated; static_len is also updated if stree is
2595
+ * not null.
2596
+ */
2597
+ function gen_bitlen(s, desc)
2598
+ // deflate_state *s;
2599
+ // tree_desc *desc; /* the tree descriptor */
2600
+ {
2601
+ var tree = desc.dyn_tree;
2602
+ var max_code = desc.max_code;
2603
+ var stree = desc.stat_desc.static_tree;
2604
+ var has_stree = desc.stat_desc.has_stree;
2605
+ var extra = desc.stat_desc.extra_bits;
2606
+ var base = desc.stat_desc.extra_base;
2607
+ var max_length = desc.stat_desc.max_length;
2608
+ var h; /* heap index */
2609
+ var n, m; /* iterate over the tree elements */
2610
+ var bits; /* bit length */
2611
+ var xbits; /* extra bits */
2612
+ var f; /* frequency */
2613
+ var overflow = 0; /* number of elements with bit length too large */
2614
+
2615
+ for (bits = 0; bits <= MAX_BITS; bits++) {
2616
+ s.bl_count[bits] = 0;
2617
+ }
2618
+
2619
+ /* In a first pass, compute the optimal bit lengths (which may
2620
+ * overflow in the case of the bit length tree).
2621
+ */
2622
+ tree[s.heap[s.heap_max] * 2 + 1]/*.Len*/ = 0; /* root of the heap */
2623
+
2624
+ for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
2625
+ n = s.heap[h];
2626
+ bits = tree[tree[n * 2 + 1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1;
2627
+ if (bits > max_length) {
2628
+ bits = max_length;
2629
+ overflow++;
2630
+ }
2631
+ tree[n * 2 + 1]/*.Len*/ = bits;
2632
+ /* We overwrite tree[n].Dad which is no longer needed */
2633
+
2634
+ if (n > max_code) { continue; } /* not a leaf node */
2635
+
2636
+ s.bl_count[bits]++;
2637
+ xbits = 0;
2638
+ if (n >= base) {
2639
+ xbits = extra[n - base];
2640
+ }
2641
+ f = tree[n * 2]/*.Freq*/;
2642
+ s.opt_len += f * (bits + xbits);
2643
+ if (has_stree) {
2644
+ s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits);
2645
+ }
2646
+ }
2647
+ if (overflow === 0) { return; }
2648
+
2649
+ // Trace((stderr,"\nbit length overflow\n"));
2650
+ /* This happens for example on obj2 and pic of the Calgary corpus */
2651
+
2652
+ /* Find the first bit length which could increase: */
2653
+ do {
2654
+ bits = max_length - 1;
2655
+ while (s.bl_count[bits] === 0) { bits--; }
2656
+ s.bl_count[bits]--; /* move one leaf down the tree */
2657
+ s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
2658
+ s.bl_count[max_length]--;
2659
+ /* The brother of the overflow item also moves one step up,
2660
+ * but this does not affect bl_count[max_length]
2661
+ */
2662
+ overflow -= 2;
2663
+ } while (overflow > 0);
2664
+
2665
+ /* Now recompute all bit lengths, scanning in increasing frequency.
2666
+ * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
2667
+ * lengths instead of fixing only the wrong ones. This idea is taken
2668
+ * from 'ar' written by Haruhiko Okumura.)
2669
+ */
2670
+ for (bits = max_length; bits !== 0; bits--) {
2671
+ n = s.bl_count[bits];
2672
+ while (n !== 0) {
2673
+ m = s.heap[--h];
2674
+ if (m > max_code) { continue; }
2675
+ if (tree[m * 2 + 1]/*.Len*/ !== bits) {
2676
+ // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
2677
+ s.opt_len += (bits - tree[m * 2 + 1]/*.Len*/) * tree[m * 2]/*.Freq*/;
2678
+ tree[m * 2 + 1]/*.Len*/ = bits;
2679
+ }
2680
+ n--;
2681
+ }
2682
+ }
2683
+ }
2684
+
2685
+
2686
+ /* ===========================================================================
2687
+ * Generate the codes for a given tree and bit counts (which need not be
2688
+ * optimal).
2689
+ * IN assertion: the array bl_count contains the bit length statistics for
2690
+ * the given tree and the field len is set for all tree elements.
2691
+ * OUT assertion: the field code is set for all tree elements of non
2692
+ * zero code length.
2693
+ */
2694
+ function gen_codes(tree, max_code, bl_count)
2695
+ // ct_data *tree; /* the tree to decorate */
2696
+ // int max_code; /* largest code with non zero frequency */
2697
+ // ushf *bl_count; /* number of codes at each bit length */
2698
+ {
2699
+ var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */
2700
+ var code = 0; /* running code value */
2701
+ var bits; /* bit index */
2702
+ var n; /* code index */
2703
+
2704
+ /* The distribution counts are first used to generate the code values
2705
+ * without bit reversal.
2706
+ */
2707
+ for (bits = 1; bits <= MAX_BITS; bits++) {
2708
+ next_code[bits] = code = (code + bl_count[bits - 1]) << 1;
2709
+ }
2710
+ /* Check that the bit counts in bl_count are consistent. The last code
2711
+ * must be all ones.
2712
+ */
2713
+ //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
2714
+ // "inconsistent bit counts");
2715
+ //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
2716
+
2717
+ for (n = 0; n <= max_code; n++) {
2718
+ var len = tree[n * 2 + 1]/*.Len*/;
2719
+ if (len === 0) { continue; }
2720
+ /* Now reverse the bits */
2721
+ tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len);
2722
+
2723
+ //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
2724
+ // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
2725
+ }
2726
+ }
2727
+
2728
+
2729
+ /* ===========================================================================
2730
+ * Initialize the various 'constant' tables.
2731
+ */
2732
+ function tr_static_init() {
2733
+ var n; /* iterates over tree elements */
2734
+ var bits; /* bit counter */
2735
+ var length; /* length value */
2736
+ var code; /* code value */
2737
+ var dist; /* distance index */
2738
+ var bl_count = new Array(MAX_BITS + 1);
2739
+ /* number of codes at each bit length for an optimal tree */
2740
+
2741
+ // do check in _tr_init()
2742
+ //if (static_init_done) return;
2743
+
2744
+ /* For some embedded targets, global variables are not initialized: */
2745
+ /*#ifdef NO_INIT_GLOBAL_POINTERS
2746
+ static_l_desc.static_tree = static_ltree;
2747
+ static_l_desc.extra_bits = extra_lbits;
2748
+ static_d_desc.static_tree = static_dtree;
2749
+ static_d_desc.extra_bits = extra_dbits;
2750
+ static_bl_desc.extra_bits = extra_blbits;
2751
+ #endif*/
2752
+
2753
+ /* Initialize the mapping length (0..255) -> length code (0..28) */
2754
+ length = 0;
2755
+ for (code = 0; code < LENGTH_CODES - 1; code++) {
2756
+ base_length[code] = length;
2757
+ for (n = 0; n < (1 << extra_lbits[code]); n++) {
2758
+ _length_code[length++] = code;
2759
+ }
2760
+ }
2761
+ //Assert (length == 256, "tr_static_init: length != 256");
2762
+ /* Note that the length 255 (match length 258) can be represented
2763
+ * in two different ways: code 284 + 5 bits or code 285, so we
2764
+ * overwrite length_code[255] to use the best encoding:
2765
+ */
2766
+ _length_code[length - 1] = code;
2767
+
2768
+ /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
2769
+ dist = 0;
2770
+ for (code = 0; code < 16; code++) {
2771
+ base_dist[code] = dist;
2772
+ for (n = 0; n < (1 << extra_dbits[code]); n++) {
2773
+ _dist_code[dist++] = code;
2774
+ }
2775
+ }
2776
+ //Assert (dist == 256, "tr_static_init: dist != 256");
2777
+ dist >>= 7; /* from now on, all distances are divided by 128 */
2778
+ for (; code < D_CODES; code++) {
2779
+ base_dist[code] = dist << 7;
2780
+ for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
2781
+ _dist_code[256 + dist++] = code;
2782
+ }
2783
+ }
2784
+ //Assert (dist == 256, "tr_static_init: 256+dist != 512");
2785
+
2786
+ /* Construct the codes of the static literal tree */
2787
+ for (bits = 0; bits <= MAX_BITS; bits++) {
2788
+ bl_count[bits] = 0;
2789
+ }
2790
+
2791
+ n = 0;
2792
+ while (n <= 143) {
2793
+ static_ltree[n * 2 + 1]/*.Len*/ = 8;
2794
+ n++;
2795
+ bl_count[8]++;
2796
+ }
2797
+ while (n <= 255) {
2798
+ static_ltree[n * 2 + 1]/*.Len*/ = 9;
2799
+ n++;
2800
+ bl_count[9]++;
2801
+ }
2802
+ while (n <= 279) {
2803
+ static_ltree[n * 2 + 1]/*.Len*/ = 7;
2804
+ n++;
2805
+ bl_count[7]++;
2806
+ }
2807
+ while (n <= 287) {
2808
+ static_ltree[n * 2 + 1]/*.Len*/ = 8;
2809
+ n++;
2810
+ bl_count[8]++;
2811
+ }
2812
+ /* Codes 286 and 287 do not exist, but we must include them in the
2813
+ * tree construction to get a canonical Huffman tree (longest code
2814
+ * all ones)
2815
+ */
2816
+ gen_codes(static_ltree, L_CODES + 1, bl_count);
2817
+
2818
+ /* The static distance tree is trivial: */
2819
+ for (n = 0; n < D_CODES; n++) {
2820
+ static_dtree[n * 2 + 1]/*.Len*/ = 5;
2821
+ static_dtree[n * 2]/*.Code*/ = bi_reverse(n, 5);
2822
+ }
2823
+
2824
+ // Now data ready and we can init static trees
2825
+ static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
2826
+ static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);
2827
+ static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);
2828
+
2829
+ //static_init_done = true;
2830
+ }
2831
+
2832
+
2833
+ /* ===========================================================================
2834
+ * Initialize a new block.
2835
+ */
2836
+ function init_block(s) {
2837
+ var n; /* iterates over tree elements */
2838
+
2839
+ /* Initialize the trees. */
2840
+ for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n * 2]/*.Freq*/ = 0; }
2841
+ for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n * 2]/*.Freq*/ = 0; }
2842
+ for (n = 0; n < BL_CODES; n++) { s.bl_tree[n * 2]/*.Freq*/ = 0; }
2843
+
2844
+ s.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1;
2845
+ s.opt_len = s.static_len = 0;
2846
+ s.last_lit = s.matches = 0;
2847
+ }
2848
+
2849
+
2850
+ /* ===========================================================================
2851
+ * Flush the bit buffer and align the output on a byte boundary
2852
+ */
2853
+ function bi_windup(s)
2854
+ {
2855
+ if (s.bi_valid > 8) {
2856
+ put_short(s, s.bi_buf);
2857
+ } else if (s.bi_valid > 0) {
2858
+ //put_byte(s, (Byte)s->bi_buf);
2859
+ s.pending_buf[s.pending++] = s.bi_buf;
2860
+ }
2861
+ s.bi_buf = 0;
2862
+ s.bi_valid = 0;
2863
+ }
2864
+
2865
+ /* ===========================================================================
2866
+ * Copy a stored block, storing first the length and its
2867
+ * one's complement if requested.
2868
+ */
2869
+ function copy_block(s, buf, len, header)
2870
+ //DeflateState *s;
2871
+ //charf *buf; /* the input data */
2872
+ //unsigned len; /* its length */
2873
+ //int header; /* true if block header must be written */
2874
+ {
2875
+ bi_windup(s); /* align on byte boundary */
2876
+
2877
+ if (header) {
2878
+ put_short(s, len);
2879
+ put_short(s, ~len);
2880
+ }
2881
+ // while (len--) {
2882
+ // put_byte(s, *buf++);
2883
+ // }
2884
+ utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
2885
+ s.pending += len;
2886
+ }
2887
+
2888
+ /* ===========================================================================
2889
+ * Compares to subtrees, using the tree depth as tie breaker when
2890
+ * the subtrees have equal frequency. This minimizes the worst case length.
2891
+ */
2892
+ function smaller(tree, n, m, depth) {
2893
+ var _n2 = n * 2;
2894
+ var _m2 = m * 2;
2895
+ return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ ||
2896
+ (tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m]));
2897
+ }
2898
+
2899
+ /* ===========================================================================
2900
+ * Restore the heap property by moving down the tree starting at node k,
2901
+ * exchanging a node with the smallest of its two sons if necessary, stopping
2902
+ * when the heap property is re-established (each father smaller than its
2903
+ * two sons).
2904
+ */
2905
+ function pqdownheap(s, tree, k)
2906
+ // deflate_state *s;
2907
+ // ct_data *tree; /* the tree to restore */
2908
+ // int k; /* node to move down */
2909
+ {
2910
+ var v = s.heap[k];
2911
+ var j = k << 1; /* left son of k */
2912
+ while (j <= s.heap_len) {
2913
+ /* Set j to the smallest of the two sons: */
2914
+ if (j < s.heap_len &&
2915
+ smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
2916
+ j++;
2917
+ }
2918
+ /* Exit if v is smaller than both sons */
2919
+ if (smaller(tree, v, s.heap[j], s.depth)) { break; }
2920
+
2921
+ /* Exchange v with the smallest son */
2922
+ s.heap[k] = s.heap[j];
2923
+ k = j;
2924
+
2925
+ /* And continue down the tree, setting j to the left son of k */
2926
+ j <<= 1;
2927
+ }
2928
+ s.heap[k] = v;
2929
+ }
2930
+
2931
+
2932
+ // inlined manually
2933
+ // var SMALLEST = 1;
2934
+
2935
+ /* ===========================================================================
2936
+ * Send the block data compressed using the given Huffman trees
2937
+ */
2938
+ function compress_block(s, ltree, dtree)
2939
+ // deflate_state *s;
2940
+ // const ct_data *ltree; /* literal tree */
2941
+ // const ct_data *dtree; /* distance tree */
2942
+ {
2943
+ var dist; /* distance of matched string */
2944
+ var lc; /* match length or unmatched char (if dist == 0) */
2945
+ var lx = 0; /* running index in l_buf */
2946
+ var code; /* the code to send */
2947
+ var extra; /* number of extra bits to send */
2948
+
2949
+ if (s.last_lit !== 0) {
2950
+ do {
2951
+ dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | (s.pending_buf[s.d_buf + lx * 2 + 1]);
2952
+ lc = s.pending_buf[s.l_buf + lx];
2953
+ lx++;
2954
+
2955
+ if (dist === 0) {
2956
+ send_code(s, lc, ltree); /* send a literal byte */
2957
+ //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
2958
+ } else {
2959
+ /* Here, lc is the match length - MIN_MATCH */
2960
+ code = _length_code[lc];
2961
+ send_code(s, code + LITERALS + 1, ltree); /* send the length code */
2962
+ extra = extra_lbits[code];
2963
+ if (extra !== 0) {
2964
+ lc -= base_length[code];
2965
+ send_bits(s, lc, extra); /* send the extra length bits */
2966
+ }
2967
+ dist--; /* dist is now the match distance - 1 */
2968
+ code = d_code(dist);
2969
+ //Assert (code < D_CODES, "bad d_code");
2970
+
2971
+ send_code(s, code, dtree); /* send the distance code */
2972
+ extra = extra_dbits[code];
2973
+ if (extra !== 0) {
2974
+ dist -= base_dist[code];
2975
+ send_bits(s, dist, extra); /* send the extra distance bits */
2976
+ }
2977
+ } /* literal or match pair ? */
2978
+
2979
+ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
2980
+ //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
2981
+ // "pendingBuf overflow");
2982
+
2983
+ } while (lx < s.last_lit);
2984
+ }
2985
+
2986
+ send_code(s, END_BLOCK, ltree);
2987
+ }
2988
+
2989
+
2990
+ /* ===========================================================================
2991
+ * Construct one Huffman tree and assigns the code bit strings and lengths.
2992
+ * Update the total bit length for the current block.
2993
+ * IN assertion: the field freq is set for all tree elements.
2994
+ * OUT assertions: the fields len and code are set to the optimal bit length
2995
+ * and corresponding code. The length opt_len is updated; static_len is
2996
+ * also updated if stree is not null. The field max_code is set.
2997
+ */
2998
+ function build_tree(s, desc)
2999
+ // deflate_state *s;
3000
+ // tree_desc *desc; /* the tree descriptor */
3001
+ {
3002
+ var tree = desc.dyn_tree;
3003
+ var stree = desc.stat_desc.static_tree;
3004
+ var has_stree = desc.stat_desc.has_stree;
3005
+ var elems = desc.stat_desc.elems;
3006
+ var n, m; /* iterate over heap elements */
3007
+ var max_code = -1; /* largest code with non zero frequency */
3008
+ var node; /* new node being created */
3009
+
3010
+ /* Construct the initial heap, with least frequent element in
3011
+ * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
3012
+ * heap[0] is not used.
3013
+ */
3014
+ s.heap_len = 0;
3015
+ s.heap_max = HEAP_SIZE;
3016
+
3017
+ for (n = 0; n < elems; n++) {
3018
+ if (tree[n * 2]/*.Freq*/ !== 0) {
3019
+ s.heap[++s.heap_len] = max_code = n;
3020
+ s.depth[n] = 0;
3021
+
3022
+ } else {
3023
+ tree[n * 2 + 1]/*.Len*/ = 0;
3024
+ }
3025
+ }
3026
+
3027
+ /* The pkzip format requires that at least one distance code exists,
3028
+ * and that at least one bit should be sent even if there is only one
3029
+ * possible code. So to avoid special checks later on we force at least
3030
+ * two codes of non zero frequency.
3031
+ */
3032
+ while (s.heap_len < 2) {
3033
+ node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);
3034
+ tree[node * 2]/*.Freq*/ = 1;
3035
+ s.depth[node] = 0;
3036
+ s.opt_len--;
3037
+
3038
+ if (has_stree) {
3039
+ s.static_len -= stree[node * 2 + 1]/*.Len*/;
3040
+ }
3041
+ /* node is 0 or 1 so it does not have extra bits */
3042
+ }
3043
+ desc.max_code = max_code;
3044
+
3045
+ /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
3046
+ * establish sub-heaps of increasing lengths:
3047
+ */
3048
+ for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }
3049
+
3050
+ /* Construct the Huffman tree by repeatedly combining the least two
3051
+ * frequent nodes.
3052
+ */
3053
+ node = elems; /* next internal node of the tree */
3054
+ do {
3055
+ //pqremove(s, tree, n); /* n = node of least frequency */
3056
+ /*** pqremove ***/
3057
+ n = s.heap[1/*SMALLEST*/];
3058
+ s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--];
3059
+ pqdownheap(s, tree, 1/*SMALLEST*/);
3060
+ /***/
3061
+
3062
+ m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */
3063
+
3064
+ s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */
3065
+ s.heap[--s.heap_max] = m;
3066
+
3067
+ /* Create a new node father of n and m */
3068
+ tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/;
3069
+ s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
3070
+ tree[n * 2 + 1]/*.Dad*/ = tree[m * 2 + 1]/*.Dad*/ = node;
3071
+
3072
+ /* and insert the new node in the heap */
3073
+ s.heap[1/*SMALLEST*/] = node++;
3074
+ pqdownheap(s, tree, 1/*SMALLEST*/);
3075
+
3076
+ } while (s.heap_len >= 2);
3077
+
3078
+ s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/];
3079
+
3080
+ /* At this point, the fields freq and dad are set. We can now
3081
+ * generate the bit lengths.
3082
+ */
3083
+ gen_bitlen(s, desc);
3084
+
3085
+ /* The field len is now set, we can generate the bit codes */
3086
+ gen_codes(tree, max_code, s.bl_count);
3087
+ }
3088
+
3089
+
3090
+ /* ===========================================================================
3091
+ * Scan a literal or distance tree to determine the frequencies of the codes
3092
+ * in the bit length tree.
3093
+ */
3094
+ function scan_tree(s, tree, max_code)
3095
+ // deflate_state *s;
3096
+ // ct_data *tree; /* the tree to be scanned */
3097
+ // int max_code; /* and its largest code of non zero frequency */
3098
+ {
3099
+ var n; /* iterates over all tree elements */
3100
+ var prevlen = -1; /* last emitted length */
3101
+ var curlen; /* length of current code */
3102
+
3103
+ var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
3104
+
3105
+ var count = 0; /* repeat count of the current code */
3106
+ var max_count = 7; /* max repeat count */
3107
+ var min_count = 4; /* min repeat count */
3108
+
3109
+ if (nextlen === 0) {
3110
+ max_count = 138;
3111
+ min_count = 3;
3112
+ }
3113
+ tree[(max_code + 1) * 2 + 1]/*.Len*/ = 0xffff; /* guard */
3114
+
3115
+ for (n = 0; n <= max_code; n++) {
3116
+ curlen = nextlen;
3117
+ nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
3118
+
3119
+ if (++count < max_count && curlen === nextlen) {
3120
+ continue;
3121
+
3122
+ } else if (count < min_count) {
3123
+ s.bl_tree[curlen * 2]/*.Freq*/ += count;
3124
+
3125
+ } else if (curlen !== 0) {
3126
+
3127
+ if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }
3128
+ s.bl_tree[REP_3_6 * 2]/*.Freq*/++;
3129
+
3130
+ } else if (count <= 10) {
3131
+ s.bl_tree[REPZ_3_10 * 2]/*.Freq*/++;
3132
+
3133
+ } else {
3134
+ s.bl_tree[REPZ_11_138 * 2]/*.Freq*/++;
3135
+ }
3136
+
3137
+ count = 0;
3138
+ prevlen = curlen;
3139
+
3140
+ if (nextlen === 0) {
3141
+ max_count = 138;
3142
+ min_count = 3;
3143
+
3144
+ } else if (curlen === nextlen) {
3145
+ max_count = 6;
3146
+ min_count = 3;
3147
+
3148
+ } else {
3149
+ max_count = 7;
3150
+ min_count = 4;
3151
+ }
3152
+ }
3153
+ }
3154
+
3155
+
3156
+ /* ===========================================================================
3157
+ * Send a literal or distance tree in compressed form, using the codes in
3158
+ * bl_tree.
3159
+ */
3160
+ function send_tree(s, tree, max_code)
3161
+ // deflate_state *s;
3162
+ // ct_data *tree; /* the tree to be scanned */
3163
+ // int max_code; /* and its largest code of non zero frequency */
3164
+ {
3165
+ var n; /* iterates over all tree elements */
3166
+ var prevlen = -1; /* last emitted length */
3167
+ var curlen; /* length of current code */
3168
+
3169
+ var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
3170
+
3171
+ var count = 0; /* repeat count of the current code */
3172
+ var max_count = 7; /* max repeat count */
3173
+ var min_count = 4; /* min repeat count */
3174
+
3175
+ /* tree[max_code+1].Len = -1; */ /* guard already set */
3176
+ if (nextlen === 0) {
3177
+ max_count = 138;
3178
+ min_count = 3;
3179
+ }
3180
+
3181
+ for (n = 0; n <= max_code; n++) {
3182
+ curlen = nextlen;
3183
+ nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
3184
+
3185
+ if (++count < max_count && curlen === nextlen) {
3186
+ continue;
3187
+
3188
+ } else if (count < min_count) {
3189
+ do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);
3190
+
3191
+ } else if (curlen !== 0) {
3192
+ if (curlen !== prevlen) {
3193
+ send_code(s, curlen, s.bl_tree);
3194
+ count--;
3195
+ }
3196
+ //Assert(count >= 3 && count <= 6, " 3_6?");
3197
+ send_code(s, REP_3_6, s.bl_tree);
3198
+ send_bits(s, count - 3, 2);
3199
+
3200
+ } else if (count <= 10) {
3201
+ send_code(s, REPZ_3_10, s.bl_tree);
3202
+ send_bits(s, count - 3, 3);
3203
+
3204
+ } else {
3205
+ send_code(s, REPZ_11_138, s.bl_tree);
3206
+ send_bits(s, count - 11, 7);
3207
+ }
3208
+
3209
+ count = 0;
3210
+ prevlen = curlen;
3211
+ if (nextlen === 0) {
3212
+ max_count = 138;
3213
+ min_count = 3;
3214
+
3215
+ } else if (curlen === nextlen) {
3216
+ max_count = 6;
3217
+ min_count = 3;
3218
+
3219
+ } else {
3220
+ max_count = 7;
3221
+ min_count = 4;
3222
+ }
3223
+ }
3224
+ }
3225
+
3226
+
3227
+ /* ===========================================================================
3228
+ * Construct the Huffman tree for the bit lengths and return the index in
3229
+ * bl_order of the last bit length code to send.
3230
+ */
3231
+ function build_bl_tree(s) {
3232
+ var max_blindex; /* index of last bit length code of non zero freq */
3233
+
3234
+ /* Determine the bit length frequencies for literal and distance trees */
3235
+ scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
3236
+ scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
3237
+
3238
+ /* Build the bit length tree: */
3239
+ build_tree(s, s.bl_desc);
3240
+ /* opt_len now includes the length of the tree representations, except
3241
+ * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
3242
+ */
3243
+
3244
+ /* Determine the number of bit length codes to send. The pkzip format
3245
+ * requires that at least 4 bit length codes be sent. (appnote.txt says
3246
+ * 3 but the actual value used is 4.)
3247
+ */
3248
+ for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
3249
+ if (s.bl_tree[bl_order[max_blindex] * 2 + 1]/*.Len*/ !== 0) {
3250
+ break;
3251
+ }
3252
+ }
3253
+ /* Update opt_len to include the bit length tree and counts */
3254
+ s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
3255
+ //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
3256
+ // s->opt_len, s->static_len));
3257
+
3258
+ return max_blindex;
3259
+ }
3260
+
3261
+
3262
+ /* ===========================================================================
3263
+ * Send the header for a block using dynamic Huffman trees: the counts, the
3264
+ * lengths of the bit length codes, the literal tree and the distance tree.
3265
+ * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
3266
+ */
3267
+ function send_all_trees(s, lcodes, dcodes, blcodes)
3268
+ // deflate_state *s;
3269
+ // int lcodes, dcodes, blcodes; /* number of codes for each tree */
3270
+ {
3271
+ var rank; /* index in bl_order */
3272
+
3273
+ //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
3274
+ //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
3275
+ // "too many codes");
3276
+ //Tracev((stderr, "\nbl counts: "));
3277
+ send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */
3278
+ send_bits(s, dcodes - 1, 5);
3279
+ send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */
3280
+ for (rank = 0; rank < blcodes; rank++) {
3281
+ //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
3282
+ send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]/*.Len*/, 3);
3283
+ }
3284
+ //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
3285
+
3286
+ send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */
3287
+ //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
3288
+
3289
+ send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */
3290
+ //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
3291
+ }
3292
+
3293
+
3294
+ /* ===========================================================================
3295
+ * Check if the data type is TEXT or BINARY, using the following algorithm:
3296
+ * - TEXT if the two conditions below are satisfied:
3297
+ * a) There are no non-portable control characters belonging to the
3298
+ * "black list" (0..6, 14..25, 28..31).
3299
+ * b) There is at least one printable character belonging to the
3300
+ * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
3301
+ * - BINARY otherwise.
3302
+ * - The following partially-portable control characters form a
3303
+ * "gray list" that is ignored in this detection algorithm:
3304
+ * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
3305
+ * IN assertion: the fields Freq of dyn_ltree are set.
3306
+ */
3307
+ function detect_data_type(s) {
3308
+ /* black_mask is the bit mask of black-listed bytes
3309
+ * set bits 0..6, 14..25, and 28..31
3310
+ * 0xf3ffc07f = binary 11110011111111111100000001111111
3311
+ */
3312
+ var black_mask = 0xf3ffc07f;
3313
+ var n;
3314
+
3315
+ /* Check for non-textual ("black-listed") bytes. */
3316
+ for (n = 0; n <= 31; n++, black_mask >>>= 1) {
3317
+ if ((black_mask & 1) && (s.dyn_ltree[n * 2]/*.Freq*/ !== 0)) {
3318
+ return Z_BINARY;
3319
+ }
3320
+ }
3321
+
3322
+ /* Check for textual ("white-listed") bytes. */
3323
+ if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||
3324
+ s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {
3325
+ return Z_TEXT;
3326
+ }
3327
+ for (n = 32; n < LITERALS; n++) {
3328
+ if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) {
3329
+ return Z_TEXT;
3330
+ }
3331
+ }
3332
+
3333
+ /* There are no "black-listed" or "white-listed" bytes:
3334
+ * this stream either is empty or has tolerated ("gray-listed") bytes only.
3335
+ */
3336
+ return Z_BINARY;
3337
+ }
3338
+
3339
+
3340
+ var static_init_done = false;
3341
+
3342
+ /* ===========================================================================
3343
+ * Initialize the tree data structures for a new zlib stream.
3344
+ */
3345
+ function _tr_init(s)
3346
+ {
3347
+
3348
+ if (!static_init_done) {
3349
+ tr_static_init();
3350
+ static_init_done = true;
3351
+ }
3352
+
3353
+ s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
3354
+ s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
3355
+ s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
3356
+
3357
+ s.bi_buf = 0;
3358
+ s.bi_valid = 0;
3359
+
3360
+ /* Initialize the first block of the first file: */
3361
+ init_block(s);
3362
+ }
3363
+
3364
+
3365
+ /* ===========================================================================
3366
+ * Send a stored block
3367
+ */
3368
+ function _tr_stored_block(s, buf, stored_len, last)
3369
+ //DeflateState *s;
3370
+ //charf *buf; /* input block */
3371
+ //ulg stored_len; /* length of input block */
3372
+ //int last; /* one if this is the last block for a file */
3373
+ {
3374
+ send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */
3375
+ copy_block(s, buf, stored_len, true); /* with header */
3376
+ }
3377
+
3378
+
3379
+ /* ===========================================================================
3380
+ * Send one empty static block to give enough lookahead for inflate.
3381
+ * This takes 10 bits, of which 7 may remain in the bit buffer.
3382
+ */
3383
+ function _tr_align(s) {
3384
+ send_bits(s, STATIC_TREES << 1, 3);
3385
+ send_code(s, END_BLOCK, static_ltree);
3386
+ bi_flush(s);
3387
+ }
3388
+
3389
+
3390
+ /* ===========================================================================
3391
+ * Determine the best encoding for the current block: dynamic trees, static
3392
+ * trees or store, and output the encoded block to the zip file.
3393
+ */
3394
+ function _tr_flush_block(s, buf, stored_len, last)
3395
+ //DeflateState *s;
3396
+ //charf *buf; /* input block, or NULL if too old */
3397
+ //ulg stored_len; /* length of input block */
3398
+ //int last; /* one if this is the last block for a file */
3399
+ {
3400
+ var opt_lenb, static_lenb; /* opt_len and static_len in bytes */
3401
+ var max_blindex = 0; /* index of last bit length code of non zero freq */
3402
+
3403
+ /* Build the Huffman trees unless a stored block is forced */
3404
+ if (s.level > 0) {
3405
+
3406
+ /* Check if the file is binary or text */
3407
+ if (s.strm.data_type === Z_UNKNOWN) {
3408
+ s.strm.data_type = detect_data_type(s);
3409
+ }
3410
+
3411
+ /* Construct the literal and distance trees */
3412
+ build_tree(s, s.l_desc);
3413
+ // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
3414
+ // s->static_len));
3415
+
3416
+ build_tree(s, s.d_desc);
3417
+ // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
3418
+ // s->static_len));
3419
+ /* At this point, opt_len and static_len are the total bit lengths of
3420
+ * the compressed block data, excluding the tree representations.
3421
+ */
3422
+
3423
+ /* Build the bit length tree for the above two trees, and get the index
3424
+ * in bl_order of the last bit length code to send.
3425
+ */
3426
+ max_blindex = build_bl_tree(s);
3427
+
3428
+ /* Determine the best encoding. Compute the block lengths in bytes. */
3429
+ opt_lenb = (s.opt_len + 3 + 7) >>> 3;
3430
+ static_lenb = (s.static_len + 3 + 7) >>> 3;
3431
+
3432
+ // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
3433
+ // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
3434
+ // s->last_lit));
3435
+
3436
+ if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
3437
+
3438
+ } else {
3439
+ // Assert(buf != (char*)0, "lost buf");
3440
+ opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
3441
+ }
3442
+
3443
+ if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) {
3444
+ /* 4: two words for the lengths */
3445
+
3446
+ /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
3447
+ * Otherwise we can't have processed more than WSIZE input bytes since
3448
+ * the last block flush, because compression would have been
3449
+ * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
3450
+ * transform a block into a stored block.
3451
+ */
3452
+ _tr_stored_block(s, buf, stored_len, last);
3453
+
3454
+ } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
3455
+
3456
+ send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
3457
+ compress_block(s, static_ltree, static_dtree);
3458
+
3459
+ } else {
3460
+ send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
3461
+ send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
3462
+ compress_block(s, s.dyn_ltree, s.dyn_dtree);
3463
+ }
3464
+ // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
3465
+ /* The above check is made mod 2^32, for files larger than 512 MB
3466
+ * and uLong implemented on 32 bits.
3467
+ */
3468
+ init_block(s);
3469
+
3470
+ if (last) {
3471
+ bi_windup(s);
3472
+ }
3473
+ // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
3474
+ // s->compressed_len-7*last));
3475
+ }
3476
+
3477
+ /* ===========================================================================
3478
+ * Save the match info and tally the frequency counts. Return true if
3479
+ * the current block must be flushed.
3480
+ */
3481
+ function _tr_tally(s, dist, lc)
3482
+ // deflate_state *s;
3483
+ // unsigned dist; /* distance of matched string */
3484
+ // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
3485
+ {
3486
+ //var out_length, in_length, dcode;
3487
+
3488
+ s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff;
3489
+ s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
3490
+
3491
+ s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
3492
+ s.last_lit++;
3493
+
3494
+ if (dist === 0) {
3495
+ /* lc is the unmatched char */
3496
+ s.dyn_ltree[lc * 2]/*.Freq*/++;
3497
+ } else {
3498
+ s.matches++;
3499
+ /* Here, lc is the match length - MIN_MATCH */
3500
+ dist--; /* dist = match distance - 1 */
3501
+ //Assert((ush)dist < (ush)MAX_DIST(s) &&
3502
+ // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
3503
+ // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
3504
+
3505
+ s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]/*.Freq*/++;
3506
+ s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;
3507
+ }
3508
+
3509
+ // (!) This block is disabled in zlib defaults,
3510
+ // don't enable it for binary compatibility
3511
+
3512
+ //#ifdef TRUNCATE_BLOCK
3513
+ // /* Try to guess if it is profitable to stop the current block here */
3514
+ // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
3515
+ // /* Compute an upper bound for the compressed length */
3516
+ // out_length = s.last_lit*8;
3517
+ // in_length = s.strstart - s.block_start;
3518
+ //
3519
+ // for (dcode = 0; dcode < D_CODES; dcode++) {
3520
+ // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
3521
+ // }
3522
+ // out_length >>>= 3;
3523
+ // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
3524
+ // // s->last_lit, in_length, out_length,
3525
+ // // 100L - out_length*100L/in_length));
3526
+ // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
3527
+ // return true;
3528
+ // }
3529
+ // }
3530
+ //#endif
3531
+
3532
+ return (s.last_lit === s.lit_bufsize - 1);
3533
+ /* We avoid equality with lit_bufsize because of wraparound at 64K
3534
+ * on 16 bit machines and because stored blocks are restricted to
3535
+ * 64K-1 bytes.
3536
+ */
3537
+ }
3538
+
3539
+ exports._tr_init = _tr_init;
3540
+ exports._tr_stored_block = _tr_stored_block;
3541
+ exports._tr_flush_block = _tr_flush_block;
3542
+ exports._tr_tally = _tr_tally;
3543
+ exports._tr_align = _tr_align;
3544
+
3545
+ },{"../utils/common":1}],8:[function(require,module,exports){
3546
+ 'use strict';
3547
+
3548
+ // (C) 1995-2013 Jean-loup Gailly and Mark Adler
3549
+ // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
3550
+ //
3551
+ // This software is provided 'as-is', without any express or implied
3552
+ // warranty. In no event will the authors be held liable for any damages
3553
+ // arising from the use of this software.
3554
+ //
3555
+ // Permission is granted to anyone to use this software for any purpose,
3556
+ // including commercial applications, and to alter it and redistribute it
3557
+ // freely, subject to the following restrictions:
3558
+ //
3559
+ // 1. The origin of this software must not be misrepresented; you must not
3560
+ // claim that you wrote the original software. If you use this software
3561
+ // in a product, an acknowledgment in the product documentation would be
3562
+ // appreciated but is not required.
3563
+ // 2. Altered source versions must be plainly marked as such, and must not be
3564
+ // misrepresented as being the original software.
3565
+ // 3. This notice may not be removed or altered from any source distribution.
3566
+
3567
+ function ZStream() {
3568
+ /* next input byte */
3569
+ this.input = null; // JS specific, because we have no pointers
3570
+ this.next_in = 0;
3571
+ /* number of bytes available at input */
3572
+ this.avail_in = 0;
3573
+ /* total number of input bytes read so far */
3574
+ this.total_in = 0;
3575
+ /* next output byte should be put there */
3576
+ this.output = null; // JS specific, because we have no pointers
3577
+ this.next_out = 0;
3578
+ /* remaining free space at output */
3579
+ this.avail_out = 0;
3580
+ /* total number of bytes output so far */
3581
+ this.total_out = 0;
3582
+ /* last error message, NULL if no error */
3583
+ this.msg = ''/*Z_NULL*/;
3584
+ /* not visible by applications */
3585
+ this.state = null;
3586
+ /* best guess about the data type: binary or text */
3587
+ this.data_type = 2/*Z_UNKNOWN*/;
3588
+ /* adler32 value of the uncompressed data */
3589
+ this.adler = 0;
3590
+ }
3591
+
3592
+ module.exports = ZStream;
3593
+
3594
+ },{}],"/lib/deflate.js":[function(require,module,exports){
3595
+ 'use strict';
3596
+
3597
+
3598
+ var zlib_deflate = require('./zlib/deflate');
3599
+ var utils = require('./utils/common');
3600
+ var strings = require('./utils/strings');
3601
+ var msg = require('./zlib/messages');
3602
+ var ZStream = require('./zlib/zstream');
3603
+
3604
+ var toString = Object.prototype.toString;
3605
+
3606
+ /* Public constants ==========================================================*/
3607
+ /* ===========================================================================*/
3608
+
3609
+ var Z_NO_FLUSH = 0;
3610
+ var Z_FINISH = 4;
3611
+
3612
+ var Z_OK = 0;
3613
+ var Z_STREAM_END = 1;
3614
+ var Z_SYNC_FLUSH = 2;
3615
+
3616
+ var Z_DEFAULT_COMPRESSION = -1;
3617
+
3618
+ var Z_DEFAULT_STRATEGY = 0;
3619
+
3620
+ var Z_DEFLATED = 8;
3621
+
3622
+ /* ===========================================================================*/
3623
+
3624
+
3625
+ /**
3626
+ * class Deflate
3627
+ *
3628
+ * Generic JS-style wrapper for zlib calls. If you don't need
3629
+ * streaming behaviour - use more simple functions: [[deflate]],
3630
+ * [[deflateRaw]] and [[gzip]].
3631
+ **/
3632
+
3633
+ /* internal
3634
+ * Deflate.chunks -> Array
3635
+ *
3636
+ * Chunks of output data, if [[Deflate#onData]] not overridden.
3637
+ **/
3638
+
3639
+ /**
3640
+ * Deflate.result -> Uint8Array|Array
3641
+ *
3642
+ * Compressed result, generated by default [[Deflate#onData]]
3643
+ * and [[Deflate#onEnd]] handlers. Filled after you push last chunk
3644
+ * (call [[Deflate#push]] with `Z_FINISH` / `true` param) or if you
3645
+ * push a chunk with explicit flush (call [[Deflate#push]] with
3646
+ * `Z_SYNC_FLUSH` param).
3647
+ **/
3648
+
3649
+ /**
3650
+ * Deflate.err -> Number
3651
+ *
3652
+ * Error code after deflate finished. 0 (Z_OK) on success.
3653
+ * You will not need it in real life, because deflate errors
3654
+ * are possible only on wrong options or bad `onData` / `onEnd`
3655
+ * custom handlers.
3656
+ **/
3657
+
3658
+ /**
3659
+ * Deflate.msg -> String
3660
+ *
3661
+ * Error message, if [[Deflate.err]] != 0
3662
+ **/
3663
+
3664
+
3665
+ /**
3666
+ * new Deflate(options)
3667
+ * - options (Object): zlib deflate options.
3668
+ *
3669
+ * Creates new deflator instance with specified params. Throws exception
3670
+ * on bad params. Supported options:
3671
+ *
3672
+ * - `level`
3673
+ * - `windowBits`
3674
+ * - `memLevel`
3675
+ * - `strategy`
3676
+ * - `dictionary`
3677
+ *
3678
+ * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
3679
+ * for more information on these.
3680
+ *
3681
+ * Additional options, for internal needs:
3682
+ *
3683
+ * - `chunkSize` - size of generated data chunks (16K by default)
3684
+ * - `raw` (Boolean) - do raw deflate
3685
+ * - `gzip` (Boolean) - create gzip wrapper
3686
+ * - `to` (String) - if equal to 'string', then result will be "binary string"
3687
+ * (each char code [0..255])
3688
+ * - `header` (Object) - custom header for gzip
3689
+ * - `text` (Boolean) - true if compressed data believed to be text
3690
+ * - `time` (Number) - modification time, unix timestamp
3691
+ * - `os` (Number) - operation system code
3692
+ * - `extra` (Array) - array of bytes with extra data (max 65536)
3693
+ * - `name` (String) - file name (binary string)
3694
+ * - `comment` (String) - comment (binary string)
3695
+ * - `hcrc` (Boolean) - true if header crc should be added
3696
+ *
3697
+ * ##### Example:
3698
+ *
3699
+ * ```javascript
3700
+ * var pako = require('pako')
3701
+ * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
3702
+ * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
3703
+ *
3704
+ * var deflate = new pako.Deflate({ level: 3});
3705
+ *
3706
+ * deflate.push(chunk1, false);
3707
+ * deflate.push(chunk2, true); // true -> last chunk
3708
+ *
3709
+ * if (deflate.err) { throw new Error(deflate.err); }
3710
+ *
3711
+ * console.log(deflate.result);
3712
+ * ```
3713
+ **/
3714
+ function Deflate(options) {
3715
+ if (!(this instanceof Deflate)) return new Deflate(options);
3716
+
3717
+ this.options = utils.assign({
3718
+ level: Z_DEFAULT_COMPRESSION,
3719
+ method: Z_DEFLATED,
3720
+ chunkSize: 16384,
3721
+ windowBits: 15,
3722
+ memLevel: 8,
3723
+ strategy: Z_DEFAULT_STRATEGY,
3724
+ to: ''
3725
+ }, options || {});
3726
+
3727
+ var opt = this.options;
3728
+
3729
+ if (opt.raw && (opt.windowBits > 0)) {
3730
+ opt.windowBits = -opt.windowBits;
3731
+ }
3732
+
3733
+ else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {
3734
+ opt.windowBits += 16;
3735
+ }
3736
+
3737
+ this.err = 0; // error code, if happens (0 = Z_OK)
3738
+ this.msg = ''; // error message
3739
+ this.ended = false; // used to avoid multiple onEnd() calls
3740
+ this.chunks = []; // chunks of compressed data
3741
+
3742
+ this.strm = new ZStream();
3743
+ this.strm.avail_out = 0;
3744
+
3745
+ var status = zlib_deflate.deflateInit2(
3746
+ this.strm,
3747
+ opt.level,
3748
+ opt.method,
3749
+ opt.windowBits,
3750
+ opt.memLevel,
3751
+ opt.strategy
3752
+ );
3753
+
3754
+ if (status !== Z_OK) {
3755
+ throw new Error(msg[status]);
3756
+ }
3757
+
3758
+ if (opt.header) {
3759
+ zlib_deflate.deflateSetHeader(this.strm, opt.header);
3760
+ }
3761
+
3762
+ if (opt.dictionary) {
3763
+ var dict;
3764
+ // Convert data if needed
3765
+ if (typeof opt.dictionary === 'string') {
3766
+ // If we need to compress text, change encoding to utf8.
3767
+ dict = strings.string2buf(opt.dictionary);
3768
+ } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
3769
+ dict = new Uint8Array(opt.dictionary);
3770
+ } else {
3771
+ dict = opt.dictionary;
3772
+ }
3773
+
3774
+ status = zlib_deflate.deflateSetDictionary(this.strm, dict);
3775
+
3776
+ if (status !== Z_OK) {
3777
+ throw new Error(msg[status]);
3778
+ }
3779
+
3780
+ this._dict_set = true;
3781
+ }
3782
+ }
3783
+
3784
+ /**
3785
+ * Deflate#push(data[, mode]) -> Boolean
3786
+ * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be
3787
+ * converted to utf8 byte sequence.
3788
+ * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
3789
+ * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
3790
+ *
3791
+ * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
3792
+ * new compressed chunks. Returns `true` on success. The last data block must have
3793
+ * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
3794
+ * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) you
3795
+ * can use mode Z_SYNC_FLUSH, keeping the compression context.
3796
+ *
3797
+ * On fail call [[Deflate#onEnd]] with error code and return false.
3798
+ *
3799
+ * We strongly recommend to use `Uint8Array` on input for best speed (output
3800
+ * array format is detected automatically). Also, don't skip last param and always
3801
+ * use the same type in your code (boolean or number). That will improve JS speed.
3802
+ *
3803
+ * For regular `Array`-s make sure all elements are [0..255].
3804
+ *
3805
+ * ##### Example
3806
+ *
3807
+ * ```javascript
3808
+ * push(chunk, false); // push one of data chunks
3809
+ * ...
3810
+ * push(chunk, true); // push last chunk
3811
+ * ```
3812
+ **/
3813
+ Deflate.prototype.push = function (data, mode) {
3814
+ var strm = this.strm;
3815
+ var chunkSize = this.options.chunkSize;
3816
+ var status, _mode;
3817
+
3818
+ if (this.ended) { return false; }
3819
+
3820
+ _mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);
3821
+
3822
+ // Convert data if needed
3823
+ if (typeof data === 'string') {
3824
+ // If we need to compress text, change encoding to utf8.
3825
+ strm.input = strings.string2buf(data);
3826
+ } else if (toString.call(data) === '[object ArrayBuffer]') {
3827
+ strm.input = new Uint8Array(data);
3828
+ } else {
3829
+ strm.input = data;
3830
+ }
3831
+
3832
+ strm.next_in = 0;
3833
+ strm.avail_in = strm.input.length;
3834
+
3835
+ do {
3836
+ if (strm.avail_out === 0) {
3837
+ strm.output = new utils.Buf8(chunkSize);
3838
+ strm.next_out = 0;
3839
+ strm.avail_out = chunkSize;
3840
+ }
3841
+ status = zlib_deflate.deflate(strm, _mode); /* no bad return value */
3842
+
3843
+ if (status !== Z_STREAM_END && status !== Z_OK) {
3844
+ this.onEnd(status);
3845
+ this.ended = true;
3846
+ return false;
3847
+ }
3848
+ if (strm.avail_out === 0 || (strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH))) {
3849
+ if (this.options.to === 'string') {
3850
+ this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
3851
+ } else {
3852
+ this.onData(utils.shrinkBuf(strm.output, strm.next_out));
3853
+ }
3854
+ }
3855
+ } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);
3856
+
3857
+ // Finalize on the last chunk.
3858
+ if (_mode === Z_FINISH) {
3859
+ status = zlib_deflate.deflateEnd(this.strm);
3860
+ this.onEnd(status);
3861
+ this.ended = true;
3862
+ return status === Z_OK;
3863
+ }
3864
+
3865
+ // callback interim results if Z_SYNC_FLUSH.
3866
+ if (_mode === Z_SYNC_FLUSH) {
3867
+ this.onEnd(Z_OK);
3868
+ strm.avail_out = 0;
3869
+ return true;
3870
+ }
3871
+
3872
+ return true;
3873
+ };
3874
+
3875
+
3876
+ /**
3877
+ * Deflate#onData(chunk) -> Void
3878
+ * - chunk (Uint8Array|Array|String): output data. Type of array depends
3879
+ * on js engine support. When string output requested, each chunk
3880
+ * will be string.
3881
+ *
3882
+ * By default, stores data blocks in `chunks[]` property and glue
3883
+ * those in `onEnd`. Override this handler, if you need another behaviour.
3884
+ **/
3885
+ Deflate.prototype.onData = function (chunk) {
3886
+ this.chunks.push(chunk);
3887
+ };
3888
+
3889
+
3890
+ /**
3891
+ * Deflate#onEnd(status) -> Void
3892
+ * - status (Number): deflate status. 0 (Z_OK) on success,
3893
+ * other if not.
3894
+ *
3895
+ * Called once after you tell deflate that the input stream is
3896
+ * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
3897
+ * or if an error happened. By default - join collected chunks,
3898
+ * free memory and fill `results` / `err` properties.
3899
+ **/
3900
+ Deflate.prototype.onEnd = function (status) {
3901
+ // On success - join
3902
+ if (status === Z_OK) {
3903
+ if (this.options.to === 'string') {
3904
+ this.result = this.chunks.join('');
3905
+ } else {
3906
+ this.result = utils.flattenChunks(this.chunks);
3907
+ }
3908
+ }
3909
+ this.chunks = [];
3910
+ this.err = status;
3911
+ this.msg = this.strm.msg;
3912
+ };
3913
+
3914
+
3915
+ /**
3916
+ * deflate(data[, options]) -> Uint8Array|Array|String
3917
+ * - data (Uint8Array|Array|String): input data to compress.
3918
+ * - options (Object): zlib deflate options.
3919
+ *
3920
+ * Compress `data` with deflate algorithm and `options`.
3921
+ *
3922
+ * Supported options are:
3923
+ *
3924
+ * - level
3925
+ * - windowBits
3926
+ * - memLevel
3927
+ * - strategy
3928
+ * - dictionary
3929
+ *
3930
+ * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
3931
+ * for more information on these.
3932
+ *
3933
+ * Sugar (options):
3934
+ *
3935
+ * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
3936
+ * negative windowBits implicitly.
3937
+ * - `to` (String) - if equal to 'string', then result will be "binary string"
3938
+ * (each char code [0..255])
3939
+ *
3940
+ * ##### Example:
3941
+ *
3942
+ * ```javascript
3943
+ * var pako = require('pako')
3944
+ * , data = Uint8Array([1,2,3,4,5,6,7,8,9]);
3945
+ *
3946
+ * console.log(pako.deflate(data));
3947
+ * ```
3948
+ **/
3949
+ function deflate(input, options) {
3950
+ var deflator = new Deflate(options);
3951
+
3952
+ deflator.push(input, true);
3953
+
3954
+ // That will never happens, if you don't cheat with options :)
3955
+ if (deflator.err) { throw deflator.msg || msg[deflator.err]; }
3956
+
3957
+ return deflator.result;
3958
+ }
3959
+
3960
+
3961
+ /**
3962
+ * deflateRaw(data[, options]) -> Uint8Array|Array|String
3963
+ * - data (Uint8Array|Array|String): input data to compress.
3964
+ * - options (Object): zlib deflate options.
3965
+ *
3966
+ * The same as [[deflate]], but creates raw data, without wrapper
3967
+ * (header and adler32 crc).
3968
+ **/
3969
+ function deflateRaw(input, options) {
3970
+ options = options || {};
3971
+ options.raw = true;
3972
+ return deflate(input, options);
3973
+ }
3974
+
3975
+
3976
+ /**
3977
+ * gzip(data[, options]) -> Uint8Array|Array|String
3978
+ * - data (Uint8Array|Array|String): input data to compress.
3979
+ * - options (Object): zlib deflate options.
3980
+ *
3981
+ * The same as [[deflate]], but create gzip wrapper instead of
3982
+ * deflate one.
3983
+ **/
3984
+ function gzip(input, options) {
3985
+ options = options || {};
3986
+ options.gzip = true;
3987
+ return deflate(input, options);
3988
+ }
3989
+
3990
+
3991
+ exports.Deflate = Deflate;
3992
+ exports.deflate = deflate;
3993
+ exports.deflateRaw = deflateRaw;
3994
+ exports.gzip = gzip;
3995
+
3996
+ },{"./utils/common":1,"./utils/strings":2,"./zlib/deflate":5,"./zlib/messages":6,"./zlib/zstream":8}]},{},[])("/lib/deflate.js")
3997
+ });