ext_yarn 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (347) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +41 -47
  3. data/README.md +10 -0
  4. data/bin/yarn_after +12 -0
  5. data/lib/ext_yarn/version.rb +1 -1
  6. data/package.json +14 -13
  7. data/vendor/.yarn-integrity +35 -39
  8. data/vendor/bootswatch-sass/package.json +1 -1
  9. data/vendor/chart.js/dist/Chart.bundle.js +5754 -5711
  10. data/vendor/chart.js/dist/Chart.js +2118 -2046
  11. data/vendor/chart.js/package.json +1 -1
  12. data/vendor/chartkick/LICENSE.txt +1 -1
  13. data/vendor/chartkick/dist/chartkick.js +2239 -0
  14. data/vendor/chartkick/package.json +18 -8
  15. data/vendor/file-saver/dist/FileSaver.js +180 -0
  16. data/vendor/file-saver/package.json +16 -4
  17. data/vendor/jquery/dist/jquery.js +453 -342
  18. data/vendor/jquery/dist/jquery.slim.js +428 -319
  19. data/vendor/jquery/package.json +32 -21
  20. data/vendor/{tempusdominus-bootstrap-4 → jquery-touch-events}/LICENSE +21 -21
  21. data/vendor/jquery-touch-events/package.json +32 -0
  22. data/vendor/jquery-touch-events/src/jquery.mobile-events.js +920 -0
  23. data/vendor/jquery-ui-touch-punch-zoom-fork/jquery.ui.touch-punch.js +186 -0
  24. data/vendor/jquery-ujs/package.json +1 -1
  25. data/vendor/jquery-ujs/src/rails.js +14 -4
  26. data/vendor/{bootswatch → jquery.iframe-transport}/LICENSE +2 -2
  27. data/vendor/jquery.iframe-transport/jquery.iframe-transport.js +247 -0
  28. data/vendor/jquery.iframe-transport/package.json +28 -0
  29. data/vendor/jstz/dist/jstz.js +9 -1
  30. data/vendor/jstz/package.json +6 -4
  31. data/vendor/lazysizes/LICENSE +22 -0
  32. data/vendor/lazysizes/lazysizes-umd.js +706 -0
  33. data/vendor/lazysizes/lazysizes.js +703 -0
  34. data/vendor/lazysizes/package.json +65 -0
  35. data/vendor/lazysizes/plugins/artdirect/ls.artdirect.js +160 -0
  36. data/vendor/lazysizes/plugins/aspectratio/ls.aspectratio.js +209 -0
  37. data/vendor/lazysizes/plugins/attrchange/ls.attrchange.js +129 -0
  38. data/vendor/lazysizes/plugins/bgset/ls.bgset.js +198 -0
  39. data/vendor/lazysizes/plugins/blur-up/ls.blur-up.js +191 -0
  40. data/vendor/lazysizes/plugins/custommedia/ls.custommedia.js +75 -0
  41. data/vendor/lazysizes/plugins/fix-ios-sizes/fix-ios-sizes.js +80 -0
  42. data/vendor/lazysizes/plugins/include/ls.include.js +589 -0
  43. data/vendor/lazysizes/plugins/noscript/ls.noscript.js +87 -0
  44. data/vendor/lazysizes/plugins/object-fit/ls.object-fit.js +149 -0
  45. data/vendor/lazysizes/plugins/optimumx/ls.optimumx.js +273 -0
  46. data/vendor/lazysizes/plugins/parent-fit/ls.parent-fit.js +157 -0
  47. data/vendor/lazysizes/plugins/print/ls.print.js +51 -0
  48. data/vendor/lazysizes/plugins/progressive/ls.progressive.js +49 -0
  49. data/vendor/lazysizes/plugins/respimg/ls.respimg.js +314 -0
  50. data/vendor/lazysizes/plugins/rias/ls.rias.js +391 -0
  51. data/vendor/lazysizes/plugins/static-gecko-picture/ls.static-gecko-picture.js +82 -0
  52. data/vendor/lazysizes/plugins/twitter/ls.twitter.js +63 -0
  53. data/vendor/lazysizes/plugins/unload/ls.unload.js +155 -0
  54. data/vendor/lazysizes/plugins/unveilhooks/ls.unveilhooks.js +145 -0
  55. data/vendor/lazysizes/plugins/video-embed/ls.video-embed.js +114 -0
  56. data/vendor/lodash/core.js +75 -57
  57. data/vendor/lodash/lodash.js +105 -82
  58. data/vendor/lodash/package.json +2 -2
  59. data/vendor/moment/locale/af.js +58 -60
  60. data/vendor/moment/locale/ar-dz.js +45 -47
  61. data/vendor/moment/locale/ar-kw.js +45 -47
  62. data/vendor/moment/locale/ar-ly.js +106 -112
  63. data/vendor/moment/locale/ar-ma.js +45 -48
  64. data/vendor/moment/locale/ar-sa.js +88 -91
  65. data/vendor/moment/locale/ar-tn.js +45 -47
  66. data/vendor/moment/locale/ar.js +119 -128
  67. data/vendor/moment/locale/az.js +89 -91
  68. data/vendor/moment/locale/be.js +111 -115
  69. data/vendor/moment/locale/bg.js +73 -75
  70. data/vendor/moment/locale/bm.js +44 -47
  71. data/vendor/moment/locale/bn.js +103 -105
  72. data/vendor/moment/locale/bo.js +103 -105
  73. data/vendor/moment/locale/br.js +88 -90
  74. data/vendor/moment/locale/bs.js +133 -136
  75. data/vendor/moment/locale/ca.js +68 -70
  76. data/vendor/moment/locale/cs.js +160 -162
  77. data/vendor/moment/locale/cv.js +48 -50
  78. data/vendor/moment/locale/cy.js +64 -67
  79. data/vendor/moment/locale/da.js +46 -48
  80. data/vendor/moment/locale/de-at.js +61 -66
  81. data/vendor/moment/locale/de-ch.js +61 -65
  82. data/vendor/moment/locale/de.js +61 -65
  83. data/vendor/moment/locale/dv.js +82 -85
  84. data/vendor/moment/locale/el.js +82 -84
  85. data/vendor/moment/locale/en-au.js +53 -55
  86. data/vendor/moment/locale/en-ca.js +49 -51
  87. data/vendor/moment/locale/en-gb.js +53 -55
  88. data/vendor/moment/locale/en-ie.js +53 -55
  89. data/vendor/moment/locale/en-il.js +61 -0
  90. data/vendor/moment/locale/en-nz.js +53 -55
  91. data/vendor/moment/locale/eo.js +56 -60
  92. data/vendor/moment/locale/es-do.js +72 -73
  93. data/vendor/moment/locale/es-us.js +64 -66
  94. data/vendor/moment/locale/es.js +72 -74
  95. data/vendor/moment/locale/et.js +64 -67
  96. data/vendor/moment/locale/eu.js +52 -54
  97. data/vendor/moment/locale/fa.js +90 -93
  98. data/vendor/moment/locale/fi.js +93 -95
  99. data/vendor/moment/locale/fo.js +46 -48
  100. data/vendor/moment/locale/fr-ca.js +58 -60
  101. data/vendor/moment/locale/fr-ch.js +62 -64
  102. data/vendor/moment/locale/fr.js +66 -68
  103. data/vendor/moment/locale/fy.js +59 -61
  104. data/vendor/moment/locale/gd.js +57 -59
  105. data/vendor/moment/locale/gl.js +60 -62
  106. data/vendor/moment/locale/gom-latn.js +107 -109
  107. data/vendor/moment/locale/gu.js +108 -110
  108. data/vendor/moment/locale/he.js +77 -81
  109. data/vendor/moment/locale/hi.js +108 -110
  110. data/vendor/moment/locale/hr.js +136 -138
  111. data/vendor/moment/locale/hu.js +92 -94
  112. data/vendor/moment/locale/hy-am.js +78 -80
  113. data/vendor/moment/locale/id.js +67 -70
  114. data/vendor/moment/locale/is.js +110 -112
  115. data/vendor/moment/locale/it.js +53 -56
  116. data/vendor/moment/locale/ja.js +77 -67
  117. data/vendor/moment/locale/jv.js +67 -70
  118. data/vendor/moment/locale/ka.js +70 -72
  119. data/vendor/moment/locale/kk.js +72 -74
  120. data/vendor/moment/locale/km.js +96 -46
  121. data/vendor/moment/locale/kn.js +110 -112
  122. data/vendor/moment/locale/ko.js +66 -69
  123. data/vendor/moment/locale/ky.js +72 -75
  124. data/vendor/moment/locale/lb.js +113 -116
  125. data/vendor/moment/locale/lo.js +55 -57
  126. data/vendor/moment/locale/lt.js +100 -102
  127. data/vendor/moment/locale/lv.js +81 -84
  128. data/vendor/moment/locale/me.js +93 -95
  129. data/vendor/moment/locale/mi.js +50 -52
  130. data/vendor/moment/locale/mk.js +73 -75
  131. data/vendor/moment/locale/ml.js +66 -68
  132. data/vendor/moment/locale/mn.js +103 -0
  133. data/vendor/moment/locale/mr.js +140 -143
  134. data/vendor/moment/locale/ms-my.js +67 -70
  135. data/vendor/moment/locale/ms.js +67 -69
  136. data/vendor/moment/locale/mt.js +46 -48
  137. data/vendor/moment/locale/my.js +77 -82
  138. data/vendor/moment/locale/nb.js +48 -51
  139. data/vendor/moment/locale/ne.js +107 -109
  140. data/vendor/moment/locale/nl-be.js +68 -71
  141. data/vendor/moment/locale/nl.js +68 -71
  142. data/vendor/moment/locale/nn.js +46 -48
  143. data/vendor/moment/locale/pa-in.js +108 -110
  144. data/vendor/moment/locale/pl.js +104 -106
  145. data/vendor/moment/locale/pt-br.js +46 -48
  146. data/vendor/moment/locale/pt.js +50 -52
  147. data/vendor/moment/locale/ro.js +59 -62
  148. data/vendor/moment/locale/ru.js +153 -157
  149. data/vendor/moment/locale/sd.js +82 -84
  150. data/vendor/moment/locale/se.js +46 -49
  151. data/vendor/moment/locale/si.js +56 -58
  152. data/vendor/moment/locale/sk.js +138 -141
  153. data/vendor/moment/locale/sl.js +154 -156
  154. data/vendor/moment/locale/sq.js +54 -58
  155. data/vendor/moment/locale/sr-cyrl.js +93 -95
  156. data/vendor/moment/locale/sr.js +93 -95
  157. data/vendor/moment/locale/ss.js +72 -75
  158. data/vendor/moment/locale/sv.js +55 -57
  159. data/vendor/moment/locale/sw.js +45 -47
  160. data/vendor/moment/locale/ta.js +113 -116
  161. data/vendor/moment/locale/te.js +74 -76
  162. data/vendor/moment/locale/tet.js +53 -56
  163. data/vendor/moment/locale/tg.js +115 -0
  164. data/vendor/moment/locale/th.js +52 -54
  165. data/vendor/moment/locale/tl-ph.js +48 -50
  166. data/vendor/moment/locale/tlh.js +101 -103
  167. data/vendor/moment/locale/tr.js +80 -78
  168. data/vendor/moment/locale/tzl.js +75 -78
  169. data/vendor/moment/locale/tzm-latn.js +44 -46
  170. data/vendor/moment/locale/tzm.js +44 -46
  171. data/vendor/moment/locale/ug-cn.js +118 -0
  172. data/vendor/moment/locale/uk.js +129 -132
  173. data/vendor/moment/locale/ur.js +82 -85
  174. data/vendor/moment/locale/uz-latn.js +44 -46
  175. data/vendor/moment/locale/uz.js +44 -46
  176. data/vendor/moment/locale/vi.js +64 -66
  177. data/vendor/moment/locale/x-pseudo.js +54 -56
  178. data/vendor/moment/locale/yo.js +46 -48
  179. data/vendor/moment/locale/zh-cn.js +95 -98
  180. data/vendor/moment/locale/zh-hk.js +88 -92
  181. data/vendor/moment/locale/zh-tw.js +88 -91
  182. data/vendor/moment/min/locales.js +9701 -9581
  183. data/vendor/moment/min/moment-with-locales.js +13426 -13335
  184. data/vendor/moment/moment.js +3780 -3809
  185. data/vendor/moment/package.json +10 -10
  186. data/vendor/moment-timezone/builds/moment-timezone-with-data-2012-2022.js +43 -35
  187. data/vendor/moment-timezone/builds/moment-timezone-with-data.js +290 -282
  188. data/vendor/moment-timezone/moment-timezone-utils.js +12 -10
  189. data/vendor/moment-timezone/moment-timezone.js +15 -7
  190. data/vendor/moment-timezone/package.json +5 -3
  191. data/vendor/{bootstrap → pako}/LICENSE +2 -3
  192. data/vendor/pako/dist/pako.js +6811 -0
  193. data/vendor/pako/dist/pako_deflate.js +3995 -0
  194. data/vendor/pako/dist/pako_inflate.js +3295 -0
  195. data/vendor/pako/package.json +48 -0
  196. data/yarn.lock +51 -78
  197. metadata +45 -155
  198. data/vendor/bootstrap/dist/js/bootstrap.bundle.js +0 -6461
  199. data/vendor/bootstrap/dist/js/bootstrap.js +0 -3944
  200. data/vendor/bootstrap/js/dist/alert.js +0 -204
  201. data/vendor/bootstrap/js/dist/button.js +0 -192
  202. data/vendor/bootstrap/js/dist/carousel.js +0 -567
  203. data/vendor/bootstrap/js/dist/collapse.js +0 -431
  204. data/vendor/bootstrap/js/dist/dropdown.js +0 -552
  205. data/vendor/bootstrap/js/dist/index.js +0 -23
  206. data/vendor/bootstrap/js/dist/modal.js +0 -634
  207. data/vendor/bootstrap/js/dist/popover.js +0 -266
  208. data/vendor/bootstrap/js/dist/scrollspy.js +0 -379
  209. data/vendor/bootstrap/js/dist/tab.js +0 -278
  210. data/vendor/bootstrap/js/dist/tooltip.js +0 -734
  211. data/vendor/bootstrap/js/dist/util.js +0 -144
  212. data/vendor/bootstrap/package.json +0 -217
  213. data/vendor/bootstrap/scss/_alert.scss +0 -51
  214. data/vendor/bootstrap/scss/_badge.scss +0 -47
  215. data/vendor/bootstrap/scss/_breadcrumb.scss +0 -41
  216. data/vendor/bootstrap/scss/_button-group.scss +0 -172
  217. data/vendor/bootstrap/scss/_buttons.scss +0 -143
  218. data/vendor/bootstrap/scss/_card.scss +0 -301
  219. data/vendor/bootstrap/scss/_carousel.scss +0 -236
  220. data/vendor/bootstrap/scss/_close.scss +0 -35
  221. data/vendor/bootstrap/scss/_code.scss +0 -48
  222. data/vendor/bootstrap/scss/_custom-forms.scss +0 -433
  223. data/vendor/bootstrap/scss/_dropdown.scss +0 -166
  224. data/vendor/bootstrap/scss/_forms.scss +0 -333
  225. data/vendor/bootstrap/scss/_functions.scss +0 -86
  226. data/vendor/bootstrap/scss/_grid.scss +0 -52
  227. data/vendor/bootstrap/scss/_images.scss +0 -42
  228. data/vendor/bootstrap/scss/_input-group.scss +0 -173
  229. data/vendor/bootstrap/scss/_jumbotron.scss +0 -16
  230. data/vendor/bootstrap/scss/_list-group.scss +0 -115
  231. data/vendor/bootstrap/scss/_media.scss +0 -8
  232. data/vendor/bootstrap/scss/_mixins.scss +0 -41
  233. data/vendor/bootstrap/scss/_modal.scss +0 -180
  234. data/vendor/bootstrap/scss/_nav.scss +0 -118
  235. data/vendor/bootstrap/scss/_navbar.scss +0 -299
  236. data/vendor/bootstrap/scss/_pagination.scss +0 -78
  237. data/vendor/bootstrap/scss/_popover.scss +0 -183
  238. data/vendor/bootstrap/scss/_print.scss +0 -141
  239. data/vendor/bootstrap/scss/_progress.scss +0 -34
  240. data/vendor/bootstrap/scss/_reboot.scss +0 -483
  241. data/vendor/bootstrap/scss/_root.scss +0 -19
  242. data/vendor/bootstrap/scss/_tables.scss +0 -187
  243. data/vendor/bootstrap/scss/_tooltip.scss +0 -115
  244. data/vendor/bootstrap/scss/_transitions.scss +0 -22
  245. data/vendor/bootstrap/scss/_type.scss +0 -125
  246. data/vendor/bootstrap/scss/_utilities.scss +0 -15
  247. data/vendor/bootstrap/scss/_variables.scss +0 -952
  248. data/vendor/bootstrap/scss/bootstrap-grid.scss +0 -32
  249. data/vendor/bootstrap/scss/bootstrap-reboot.scss +0 -12
  250. data/vendor/bootstrap/scss/bootstrap.scss +0 -42
  251. data/vendor/bootstrap/scss/mixins/_alert.scss +0 -13
  252. data/vendor/bootstrap/scss/mixins/_background-variant.scss +0 -21
  253. data/vendor/bootstrap/scss/mixins/_badge.scss +0 -12
  254. data/vendor/bootstrap/scss/mixins/_border-radius.scss +0 -35
  255. data/vendor/bootstrap/scss/mixins/_box-shadow.scss +0 -5
  256. data/vendor/bootstrap/scss/mixins/_breakpoints.scss +0 -123
  257. data/vendor/bootstrap/scss/mixins/_buttons.scss +0 -109
  258. data/vendor/bootstrap/scss/mixins/_caret.scss +0 -66
  259. data/vendor/bootstrap/scss/mixins/_clearfix.scss +0 -7
  260. data/vendor/bootstrap/scss/mixins/_float.scss +0 -11
  261. data/vendor/bootstrap/scss/mixins/_forms.scss +0 -147
  262. data/vendor/bootstrap/scss/mixins/_gradients.scss +0 -45
  263. data/vendor/bootstrap/scss/mixins/_grid-framework.scss +0 -67
  264. data/vendor/bootstrap/scss/mixins/_grid.scss +0 -52
  265. data/vendor/bootstrap/scss/mixins/_hover.scss +0 -37
  266. data/vendor/bootstrap/scss/mixins/_image.scss +0 -36
  267. data/vendor/bootstrap/scss/mixins/_list-group.scss +0 -21
  268. data/vendor/bootstrap/scss/mixins/_lists.scss +0 -7
  269. data/vendor/bootstrap/scss/mixins/_nav-divider.scss +0 -10
  270. data/vendor/bootstrap/scss/mixins/_pagination.scss +0 -22
  271. data/vendor/bootstrap/scss/mixins/_reset-text.scss +0 -17
  272. data/vendor/bootstrap/scss/mixins/_resize.scss +0 -6
  273. data/vendor/bootstrap/scss/mixins/_screen-reader.scss +0 -33
  274. data/vendor/bootstrap/scss/mixins/_size.scss +0 -6
  275. data/vendor/bootstrap/scss/mixins/_table-row.scss +0 -30
  276. data/vendor/bootstrap/scss/mixins/_text-emphasis.scss +0 -14
  277. data/vendor/bootstrap/scss/mixins/_text-hide.scss +0 -13
  278. data/vendor/bootstrap/scss/mixins/_text-truncate.scss +0 -8
  279. data/vendor/bootstrap/scss/mixins/_transition.scss +0 -13
  280. data/vendor/bootstrap/scss/mixins/_visibility.scss +0 -7
  281. data/vendor/bootstrap/scss/utilities/_align.scss +0 -8
  282. data/vendor/bootstrap/scss/utilities/_background.scss +0 -19
  283. data/vendor/bootstrap/scss/utilities/_borders.scss +0 -59
  284. data/vendor/bootstrap/scss/utilities/_clearfix.scss +0 -3
  285. data/vendor/bootstrap/scss/utilities/_display.scss +0 -38
  286. data/vendor/bootstrap/scss/utilities/_embed.scss +0 -52
  287. data/vendor/bootstrap/scss/utilities/_flex.scss +0 -51
  288. data/vendor/bootstrap/scss/utilities/_float.scss +0 -9
  289. data/vendor/bootstrap/scss/utilities/_position.scss +0 -37
  290. data/vendor/bootstrap/scss/utilities/_screenreaders.scss +0 -11
  291. data/vendor/bootstrap/scss/utilities/_shadows.scss +0 -6
  292. data/vendor/bootstrap/scss/utilities/_sizing.scss +0 -12
  293. data/vendor/bootstrap/scss/utilities/_spacing.scss +0 -51
  294. data/vendor/bootstrap/scss/utilities/_text.scss +0 -58
  295. data/vendor/bootstrap/scss/utilities/_visibility.scss +0 -11
  296. data/vendor/bootswatch/dist/cerulean/_bootswatch.scss +0 -99
  297. data/vendor/bootswatch/dist/cerulean/_variables.scss +0 -57
  298. data/vendor/bootswatch/dist/cosmo/_bootswatch.scss +0 -38
  299. data/vendor/bootswatch/dist/cosmo/_variables.scss +0 -68
  300. data/vendor/bootswatch/dist/cyborg/_bootswatch.scss +0 -230
  301. data/vendor/bootswatch/dist/cyborg/_variables.scss +0 -173
  302. data/vendor/bootswatch/dist/darkly/_bootswatch.scss +0 -186
  303. data/vendor/bootswatch/dist/darkly/_variables.scss +0 -178
  304. data/vendor/bootswatch/dist/flatly/_bootswatch.scss +0 -185
  305. data/vendor/bootswatch/dist/flatly/_variables.scss +0 -113
  306. data/vendor/bootswatch/dist/journal/_bootswatch.scss +0 -73
  307. data/vendor/bootswatch/dist/journal/_variables.scss +0 -60
  308. data/vendor/bootswatch/dist/litera/_bootswatch.scss +0 -212
  309. data/vendor/bootswatch/dist/litera/_variables.scss +0 -77
  310. data/vendor/bootswatch/dist/lumen/_bootswatch.scss +0 -429
  311. data/vendor/bootswatch/dist/lumen/_variables.scss +0 -82
  312. data/vendor/bootswatch/dist/lux/_bootswatch.scss +0 -157
  313. data/vendor/bootswatch/dist/lux/_variables.scss +0 -120
  314. data/vendor/bootswatch/dist/materia/_bootswatch.scss +0 -677
  315. data/vendor/bootswatch/dist/materia/_variables.scss +0 -131
  316. data/vendor/bootswatch/dist/minty/_bootswatch.scss +0 -258
  317. data/vendor/bootswatch/dist/minty/_variables.scss +0 -97
  318. data/vendor/bootswatch/dist/pulse/_bootswatch.scss +0 -154
  319. data/vendor/bootswatch/dist/pulse/_variables.scss +0 -100
  320. data/vendor/bootswatch/dist/sandstone/_bootswatch.scss +0 -235
  321. data/vendor/bootswatch/dist/sandstone/_variables.scss +0 -143
  322. data/vendor/bootswatch/dist/simplex/_bootswatch.scss +0 -130
  323. data/vendor/bootswatch/dist/simplex/_variables.scss +0 -108
  324. data/vendor/bootswatch/dist/sketchy/_bootswatch.scss +0 -411
  325. data/vendor/bootswatch/dist/sketchy/_variables.scss +0 -164
  326. data/vendor/bootswatch/dist/slate/_bootswatch.scss +0 -425
  327. data/vendor/bootswatch/dist/slate/_variables.scss +0 -160
  328. data/vendor/bootswatch/dist/solar/_bootswatch.scss +0 -119
  329. data/vendor/bootswatch/dist/solar/_variables.scss +0 -175
  330. data/vendor/bootswatch/dist/spacelab/_bootswatch.scss +0 -167
  331. data/vendor/bootswatch/dist/spacelab/_variables.scss +0 -63
  332. data/vendor/bootswatch/dist/superhero/_bootswatch.scss +0 -200
  333. data/vendor/bootswatch/dist/superhero/_variables.scss +0 -148
  334. data/vendor/bootswatch/dist/united/_bootswatch.scss +0 -26
  335. data/vendor/bootswatch/dist/united/_variables.scss +0 -53
  336. data/vendor/bootswatch/dist/yeti/_bootswatch.scss +0 -468
  337. data/vendor/bootswatch/dist/yeti/_variables.scss +0 -110
  338. data/vendor/bootswatch/package.json +0 -38
  339. data/vendor/chartkick/chartkick.js +0 -1872
  340. data/vendor/file-saver/FileSaver.js +0 -188
  341. data/vendor/popper.js/dist/umd/popper-utils.js +0 -1133
  342. data/vendor/popper.js/dist/umd/popper.js +0 -2540
  343. data/vendor/popper.js/package.json +0 -54
  344. data/vendor/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.js +0 -2779
  345. data/vendor/tempusdominus-bootstrap-4/package.json +0 -79
  346. data/vendor/tempusdominus-bootstrap-4/src/sass/_tempusdominus-bootstrap-4.scss +0 -342
  347. data/vendor/tempusdominus-bootstrap-4/src/sass/tempusdominus-bootstrap-4-build.scss +0 -12
@@ -0,0 +1,3995 @@
1
+ /* pako 1.0.7 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
+ var utils = require('../utils/common');
2344
+
2345
+ /* Public constants ==========================================================*/
2346
+ /* ===========================================================================*/
2347
+
2348
+
2349
+ //var Z_FILTERED = 1;
2350
+ //var Z_HUFFMAN_ONLY = 2;
2351
+ //var Z_RLE = 3;
2352
+ var Z_FIXED = 4;
2353
+ //var Z_DEFAULT_STRATEGY = 0;
2354
+
2355
+ /* Possible values of the data_type field (though see inflate()) */
2356
+ var Z_BINARY = 0;
2357
+ var Z_TEXT = 1;
2358
+ //var Z_ASCII = 1; // = Z_TEXT
2359
+ var Z_UNKNOWN = 2;
2360
+
2361
+ /*============================================================================*/
2362
+
2363
+
2364
+ function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
2365
+
2366
+ // From zutil.h
2367
+
2368
+ var STORED_BLOCK = 0;
2369
+ var STATIC_TREES = 1;
2370
+ var DYN_TREES = 2;
2371
+ /* The three kinds of block type */
2372
+
2373
+ var MIN_MATCH = 3;
2374
+ var MAX_MATCH = 258;
2375
+ /* The minimum and maximum match lengths */
2376
+
2377
+ // From deflate.h
2378
+ /* ===========================================================================
2379
+ * Internal compression state.
2380
+ */
2381
+
2382
+ var LENGTH_CODES = 29;
2383
+ /* number of length codes, not counting the special END_BLOCK code */
2384
+
2385
+ var LITERALS = 256;
2386
+ /* number of literal bytes 0..255 */
2387
+
2388
+ var L_CODES = LITERALS + 1 + LENGTH_CODES;
2389
+ /* number of Literal or Length codes, including the END_BLOCK code */
2390
+
2391
+ var D_CODES = 30;
2392
+ /* number of distance codes */
2393
+
2394
+ var BL_CODES = 19;
2395
+ /* number of codes used to transfer the bit lengths */
2396
+
2397
+ var HEAP_SIZE = 2 * L_CODES + 1;
2398
+ /* maximum heap size */
2399
+
2400
+ var MAX_BITS = 15;
2401
+ /* All codes must not exceed MAX_BITS bits */
2402
+
2403
+ var Buf_size = 16;
2404
+ /* size of bit buffer in bi_buf */
2405
+
2406
+
2407
+ /* ===========================================================================
2408
+ * Constants
2409
+ */
2410
+
2411
+ var MAX_BL_BITS = 7;
2412
+ /* Bit length codes must not exceed MAX_BL_BITS bits */
2413
+
2414
+ var END_BLOCK = 256;
2415
+ /* end of block literal code */
2416
+
2417
+ var REP_3_6 = 16;
2418
+ /* repeat previous bit length 3-6 times (2 bits of repeat count) */
2419
+
2420
+ var REPZ_3_10 = 17;
2421
+ /* repeat a zero length 3-10 times (3 bits of repeat count) */
2422
+
2423
+ var REPZ_11_138 = 18;
2424
+ /* repeat a zero length 11-138 times (7 bits of repeat count) */
2425
+
2426
+ /* eslint-disable comma-spacing,array-bracket-spacing */
2427
+ var extra_lbits = /* extra bits for each length code */
2428
+ [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];
2429
+
2430
+ var extra_dbits = /* extra bits for each distance code */
2431
+ [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];
2432
+
2433
+ var extra_blbits = /* extra bits for each bit length code */
2434
+ [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];
2435
+
2436
+ var bl_order =
2437
+ [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
2438
+ /* eslint-enable comma-spacing,array-bracket-spacing */
2439
+
2440
+ /* The lengths of the bit length codes are sent in order of decreasing
2441
+ * probability, to avoid transmitting the lengths for unused bit length codes.
2442
+ */
2443
+
2444
+ /* ===========================================================================
2445
+ * Local data. These are initialized only once.
2446
+ */
2447
+
2448
+ // We pre-fill arrays with 0 to avoid uninitialized gaps
2449
+
2450
+ var DIST_CODE_LEN = 512; /* see definition of array dist_code below */
2451
+
2452
+ // !!!! Use flat array instead of structure, Freq = i*2, Len = i*2+1
2453
+ var static_ltree = new Array((L_CODES + 2) * 2);
2454
+ zero(static_ltree);
2455
+ /* The static literal tree. Since the bit lengths are imposed, there is no
2456
+ * need for the L_CODES extra codes used during heap construction. However
2457
+ * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
2458
+ * below).
2459
+ */
2460
+
2461
+ var static_dtree = new Array(D_CODES * 2);
2462
+ zero(static_dtree);
2463
+ /* The static distance tree. (Actually a trivial tree since all codes use
2464
+ * 5 bits.)
2465
+ */
2466
+
2467
+ var _dist_code = new Array(DIST_CODE_LEN);
2468
+ zero(_dist_code);
2469
+ /* Distance codes. The first 256 values correspond to the distances
2470
+ * 3 .. 258, the last 256 values correspond to the top 8 bits of
2471
+ * the 15 bit distances.
2472
+ */
2473
+
2474
+ var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1);
2475
+ zero(_length_code);
2476
+ /* length code for each normalized match length (0 == MIN_MATCH) */
2477
+
2478
+ var base_length = new Array(LENGTH_CODES);
2479
+ zero(base_length);
2480
+ /* First normalized length for each code (0 = MIN_MATCH) */
2481
+
2482
+ var base_dist = new Array(D_CODES);
2483
+ zero(base_dist);
2484
+ /* First normalized distance for each code (0 = distance of 1) */
2485
+
2486
+
2487
+ function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
2488
+
2489
+ this.static_tree = static_tree; /* static tree or NULL */
2490
+ this.extra_bits = extra_bits; /* extra bits for each code or NULL */
2491
+ this.extra_base = extra_base; /* base index for extra_bits */
2492
+ this.elems = elems; /* max number of elements in the tree */
2493
+ this.max_length = max_length; /* max bit length for the codes */
2494
+
2495
+ // show if `static_tree` has data or dummy - needed for monomorphic objects
2496
+ this.has_stree = static_tree && static_tree.length;
2497
+ }
2498
+
2499
+
2500
+ var static_l_desc;
2501
+ var static_d_desc;
2502
+ var static_bl_desc;
2503
+
2504
+
2505
+ function TreeDesc(dyn_tree, stat_desc) {
2506
+ this.dyn_tree = dyn_tree; /* the dynamic tree */
2507
+ this.max_code = 0; /* largest code with non zero frequency */
2508
+ this.stat_desc = stat_desc; /* the corresponding static tree */
2509
+ }
2510
+
2511
+
2512
+
2513
+ function d_code(dist) {
2514
+ return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
2515
+ }
2516
+
2517
+
2518
+ /* ===========================================================================
2519
+ * Output a short LSB first on the stream.
2520
+ * IN assertion: there is enough room in pendingBuf.
2521
+ */
2522
+ function put_short(s, w) {
2523
+ // put_byte(s, (uch)((w) & 0xff));
2524
+ // put_byte(s, (uch)((ush)(w) >> 8));
2525
+ s.pending_buf[s.pending++] = (w) & 0xff;
2526
+ s.pending_buf[s.pending++] = (w >>> 8) & 0xff;
2527
+ }
2528
+
2529
+
2530
+ /* ===========================================================================
2531
+ * Send a value on a given number of bits.
2532
+ * IN assertion: length <= 16 and value fits in length bits.
2533
+ */
2534
+ function send_bits(s, value, length) {
2535
+ if (s.bi_valid > (Buf_size - length)) {
2536
+ s.bi_buf |= (value << s.bi_valid) & 0xffff;
2537
+ put_short(s, s.bi_buf);
2538
+ s.bi_buf = value >> (Buf_size - s.bi_valid);
2539
+ s.bi_valid += length - Buf_size;
2540
+ } else {
2541
+ s.bi_buf |= (value << s.bi_valid) & 0xffff;
2542
+ s.bi_valid += length;
2543
+ }
2544
+ }
2545
+
2546
+
2547
+ function send_code(s, c, tree) {
2548
+ send_bits(s, tree[c * 2]/*.Code*/, tree[c * 2 + 1]/*.Len*/);
2549
+ }
2550
+
2551
+
2552
+ /* ===========================================================================
2553
+ * Reverse the first len bits of a code, using straightforward code (a faster
2554
+ * method would use a table)
2555
+ * IN assertion: 1 <= len <= 15
2556
+ */
2557
+ function bi_reverse(code, len) {
2558
+ var res = 0;
2559
+ do {
2560
+ res |= code & 1;
2561
+ code >>>= 1;
2562
+ res <<= 1;
2563
+ } while (--len > 0);
2564
+ return res >>> 1;
2565
+ }
2566
+
2567
+
2568
+ /* ===========================================================================
2569
+ * Flush the bit buffer, keeping at most 7 bits in it.
2570
+ */
2571
+ function bi_flush(s) {
2572
+ if (s.bi_valid === 16) {
2573
+ put_short(s, s.bi_buf);
2574
+ s.bi_buf = 0;
2575
+ s.bi_valid = 0;
2576
+
2577
+ } else if (s.bi_valid >= 8) {
2578
+ s.pending_buf[s.pending++] = s.bi_buf & 0xff;
2579
+ s.bi_buf >>= 8;
2580
+ s.bi_valid -= 8;
2581
+ }
2582
+ }
2583
+
2584
+
2585
+ /* ===========================================================================
2586
+ * Compute the optimal bit lengths for a tree and update the total bit length
2587
+ * for the current block.
2588
+ * IN assertion: the fields freq and dad are set, heap[heap_max] and
2589
+ * above are the tree nodes sorted by increasing frequency.
2590
+ * OUT assertions: the field len is set to the optimal bit length, the
2591
+ * array bl_count contains the frequencies for each bit length.
2592
+ * The length opt_len is updated; static_len is also updated if stree is
2593
+ * not null.
2594
+ */
2595
+ function gen_bitlen(s, desc)
2596
+ // deflate_state *s;
2597
+ // tree_desc *desc; /* the tree descriptor */
2598
+ {
2599
+ var tree = desc.dyn_tree;
2600
+ var max_code = desc.max_code;
2601
+ var stree = desc.stat_desc.static_tree;
2602
+ var has_stree = desc.stat_desc.has_stree;
2603
+ var extra = desc.stat_desc.extra_bits;
2604
+ var base = desc.stat_desc.extra_base;
2605
+ var max_length = desc.stat_desc.max_length;
2606
+ var h; /* heap index */
2607
+ var n, m; /* iterate over the tree elements */
2608
+ var bits; /* bit length */
2609
+ var xbits; /* extra bits */
2610
+ var f; /* frequency */
2611
+ var overflow = 0; /* number of elements with bit length too large */
2612
+
2613
+ for (bits = 0; bits <= MAX_BITS; bits++) {
2614
+ s.bl_count[bits] = 0;
2615
+ }
2616
+
2617
+ /* In a first pass, compute the optimal bit lengths (which may
2618
+ * overflow in the case of the bit length tree).
2619
+ */
2620
+ tree[s.heap[s.heap_max] * 2 + 1]/*.Len*/ = 0; /* root of the heap */
2621
+
2622
+ for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
2623
+ n = s.heap[h];
2624
+ bits = tree[tree[n * 2 + 1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1;
2625
+ if (bits > max_length) {
2626
+ bits = max_length;
2627
+ overflow++;
2628
+ }
2629
+ tree[n * 2 + 1]/*.Len*/ = bits;
2630
+ /* We overwrite tree[n].Dad which is no longer needed */
2631
+
2632
+ if (n > max_code) { continue; } /* not a leaf node */
2633
+
2634
+ s.bl_count[bits]++;
2635
+ xbits = 0;
2636
+ if (n >= base) {
2637
+ xbits = extra[n - base];
2638
+ }
2639
+ f = tree[n * 2]/*.Freq*/;
2640
+ s.opt_len += f * (bits + xbits);
2641
+ if (has_stree) {
2642
+ s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits);
2643
+ }
2644
+ }
2645
+ if (overflow === 0) { return; }
2646
+
2647
+ // Trace((stderr,"\nbit length overflow\n"));
2648
+ /* This happens for example on obj2 and pic of the Calgary corpus */
2649
+
2650
+ /* Find the first bit length which could increase: */
2651
+ do {
2652
+ bits = max_length - 1;
2653
+ while (s.bl_count[bits] === 0) { bits--; }
2654
+ s.bl_count[bits]--; /* move one leaf down the tree */
2655
+ s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
2656
+ s.bl_count[max_length]--;
2657
+ /* The brother of the overflow item also moves one step up,
2658
+ * but this does not affect bl_count[max_length]
2659
+ */
2660
+ overflow -= 2;
2661
+ } while (overflow > 0);
2662
+
2663
+ /* Now recompute all bit lengths, scanning in increasing frequency.
2664
+ * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
2665
+ * lengths instead of fixing only the wrong ones. This idea is taken
2666
+ * from 'ar' written by Haruhiko Okumura.)
2667
+ */
2668
+ for (bits = max_length; bits !== 0; bits--) {
2669
+ n = s.bl_count[bits];
2670
+ while (n !== 0) {
2671
+ m = s.heap[--h];
2672
+ if (m > max_code) { continue; }
2673
+ if (tree[m * 2 + 1]/*.Len*/ !== bits) {
2674
+ // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
2675
+ s.opt_len += (bits - tree[m * 2 + 1]/*.Len*/) * tree[m * 2]/*.Freq*/;
2676
+ tree[m * 2 + 1]/*.Len*/ = bits;
2677
+ }
2678
+ n--;
2679
+ }
2680
+ }
2681
+ }
2682
+
2683
+
2684
+ /* ===========================================================================
2685
+ * Generate the codes for a given tree and bit counts (which need not be
2686
+ * optimal).
2687
+ * IN assertion: the array bl_count contains the bit length statistics for
2688
+ * the given tree and the field len is set for all tree elements.
2689
+ * OUT assertion: the field code is set for all tree elements of non
2690
+ * zero code length.
2691
+ */
2692
+ function gen_codes(tree, max_code, bl_count)
2693
+ // ct_data *tree; /* the tree to decorate */
2694
+ // int max_code; /* largest code with non zero frequency */
2695
+ // ushf *bl_count; /* number of codes at each bit length */
2696
+ {
2697
+ var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */
2698
+ var code = 0; /* running code value */
2699
+ var bits; /* bit index */
2700
+ var n; /* code index */
2701
+
2702
+ /* The distribution counts are first used to generate the code values
2703
+ * without bit reversal.
2704
+ */
2705
+ for (bits = 1; bits <= MAX_BITS; bits++) {
2706
+ next_code[bits] = code = (code + bl_count[bits - 1]) << 1;
2707
+ }
2708
+ /* Check that the bit counts in bl_count are consistent. The last code
2709
+ * must be all ones.
2710
+ */
2711
+ //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
2712
+ // "inconsistent bit counts");
2713
+ //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
2714
+
2715
+ for (n = 0; n <= max_code; n++) {
2716
+ var len = tree[n * 2 + 1]/*.Len*/;
2717
+ if (len === 0) { continue; }
2718
+ /* Now reverse the bits */
2719
+ tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len);
2720
+
2721
+ //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
2722
+ // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
2723
+ }
2724
+ }
2725
+
2726
+
2727
+ /* ===========================================================================
2728
+ * Initialize the various 'constant' tables.
2729
+ */
2730
+ function tr_static_init() {
2731
+ var n; /* iterates over tree elements */
2732
+ var bits; /* bit counter */
2733
+ var length; /* length value */
2734
+ var code; /* code value */
2735
+ var dist; /* distance index */
2736
+ var bl_count = new Array(MAX_BITS + 1);
2737
+ /* number of codes at each bit length for an optimal tree */
2738
+
2739
+ // do check in _tr_init()
2740
+ //if (static_init_done) return;
2741
+
2742
+ /* For some embedded targets, global variables are not initialized: */
2743
+ /*#ifdef NO_INIT_GLOBAL_POINTERS
2744
+ static_l_desc.static_tree = static_ltree;
2745
+ static_l_desc.extra_bits = extra_lbits;
2746
+ static_d_desc.static_tree = static_dtree;
2747
+ static_d_desc.extra_bits = extra_dbits;
2748
+ static_bl_desc.extra_bits = extra_blbits;
2749
+ #endif*/
2750
+
2751
+ /* Initialize the mapping length (0..255) -> length code (0..28) */
2752
+ length = 0;
2753
+ for (code = 0; code < LENGTH_CODES - 1; code++) {
2754
+ base_length[code] = length;
2755
+ for (n = 0; n < (1 << extra_lbits[code]); n++) {
2756
+ _length_code[length++] = code;
2757
+ }
2758
+ }
2759
+ //Assert (length == 256, "tr_static_init: length != 256");
2760
+ /* Note that the length 255 (match length 258) can be represented
2761
+ * in two different ways: code 284 + 5 bits or code 285, so we
2762
+ * overwrite length_code[255] to use the best encoding:
2763
+ */
2764
+ _length_code[length - 1] = code;
2765
+
2766
+ /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
2767
+ dist = 0;
2768
+ for (code = 0; code < 16; code++) {
2769
+ base_dist[code] = dist;
2770
+ for (n = 0; n < (1 << extra_dbits[code]); n++) {
2771
+ _dist_code[dist++] = code;
2772
+ }
2773
+ }
2774
+ //Assert (dist == 256, "tr_static_init: dist != 256");
2775
+ dist >>= 7; /* from now on, all distances are divided by 128 */
2776
+ for (; code < D_CODES; code++) {
2777
+ base_dist[code] = dist << 7;
2778
+ for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
2779
+ _dist_code[256 + dist++] = code;
2780
+ }
2781
+ }
2782
+ //Assert (dist == 256, "tr_static_init: 256+dist != 512");
2783
+
2784
+ /* Construct the codes of the static literal tree */
2785
+ for (bits = 0; bits <= MAX_BITS; bits++) {
2786
+ bl_count[bits] = 0;
2787
+ }
2788
+
2789
+ n = 0;
2790
+ while (n <= 143) {
2791
+ static_ltree[n * 2 + 1]/*.Len*/ = 8;
2792
+ n++;
2793
+ bl_count[8]++;
2794
+ }
2795
+ while (n <= 255) {
2796
+ static_ltree[n * 2 + 1]/*.Len*/ = 9;
2797
+ n++;
2798
+ bl_count[9]++;
2799
+ }
2800
+ while (n <= 279) {
2801
+ static_ltree[n * 2 + 1]/*.Len*/ = 7;
2802
+ n++;
2803
+ bl_count[7]++;
2804
+ }
2805
+ while (n <= 287) {
2806
+ static_ltree[n * 2 + 1]/*.Len*/ = 8;
2807
+ n++;
2808
+ bl_count[8]++;
2809
+ }
2810
+ /* Codes 286 and 287 do not exist, but we must include them in the
2811
+ * tree construction to get a canonical Huffman tree (longest code
2812
+ * all ones)
2813
+ */
2814
+ gen_codes(static_ltree, L_CODES + 1, bl_count);
2815
+
2816
+ /* The static distance tree is trivial: */
2817
+ for (n = 0; n < D_CODES; n++) {
2818
+ static_dtree[n * 2 + 1]/*.Len*/ = 5;
2819
+ static_dtree[n * 2]/*.Code*/ = bi_reverse(n, 5);
2820
+ }
2821
+
2822
+ // Now data ready and we can init static trees
2823
+ static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
2824
+ static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);
2825
+ static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);
2826
+
2827
+ //static_init_done = true;
2828
+ }
2829
+
2830
+
2831
+ /* ===========================================================================
2832
+ * Initialize a new block.
2833
+ */
2834
+ function init_block(s) {
2835
+ var n; /* iterates over tree elements */
2836
+
2837
+ /* Initialize the trees. */
2838
+ for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n * 2]/*.Freq*/ = 0; }
2839
+ for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n * 2]/*.Freq*/ = 0; }
2840
+ for (n = 0; n < BL_CODES; n++) { s.bl_tree[n * 2]/*.Freq*/ = 0; }
2841
+
2842
+ s.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1;
2843
+ s.opt_len = s.static_len = 0;
2844
+ s.last_lit = s.matches = 0;
2845
+ }
2846
+
2847
+
2848
+ /* ===========================================================================
2849
+ * Flush the bit buffer and align the output on a byte boundary
2850
+ */
2851
+ function bi_windup(s)
2852
+ {
2853
+ if (s.bi_valid > 8) {
2854
+ put_short(s, s.bi_buf);
2855
+ } else if (s.bi_valid > 0) {
2856
+ //put_byte(s, (Byte)s->bi_buf);
2857
+ s.pending_buf[s.pending++] = s.bi_buf;
2858
+ }
2859
+ s.bi_buf = 0;
2860
+ s.bi_valid = 0;
2861
+ }
2862
+
2863
+ /* ===========================================================================
2864
+ * Copy a stored block, storing first the length and its
2865
+ * one's complement if requested.
2866
+ */
2867
+ function copy_block(s, buf, len, header)
2868
+ //DeflateState *s;
2869
+ //charf *buf; /* the input data */
2870
+ //unsigned len; /* its length */
2871
+ //int header; /* true if block header must be written */
2872
+ {
2873
+ bi_windup(s); /* align on byte boundary */
2874
+
2875
+ if (header) {
2876
+ put_short(s, len);
2877
+ put_short(s, ~len);
2878
+ }
2879
+ // while (len--) {
2880
+ // put_byte(s, *buf++);
2881
+ // }
2882
+ utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
2883
+ s.pending += len;
2884
+ }
2885
+
2886
+ /* ===========================================================================
2887
+ * Compares to subtrees, using the tree depth as tie breaker when
2888
+ * the subtrees have equal frequency. This minimizes the worst case length.
2889
+ */
2890
+ function smaller(tree, n, m, depth) {
2891
+ var _n2 = n * 2;
2892
+ var _m2 = m * 2;
2893
+ return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ ||
2894
+ (tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m]));
2895
+ }
2896
+
2897
+ /* ===========================================================================
2898
+ * Restore the heap property by moving down the tree starting at node k,
2899
+ * exchanging a node with the smallest of its two sons if necessary, stopping
2900
+ * when the heap property is re-established (each father smaller than its
2901
+ * two sons).
2902
+ */
2903
+ function pqdownheap(s, tree, k)
2904
+ // deflate_state *s;
2905
+ // ct_data *tree; /* the tree to restore */
2906
+ // int k; /* node to move down */
2907
+ {
2908
+ var v = s.heap[k];
2909
+ var j = k << 1; /* left son of k */
2910
+ while (j <= s.heap_len) {
2911
+ /* Set j to the smallest of the two sons: */
2912
+ if (j < s.heap_len &&
2913
+ smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
2914
+ j++;
2915
+ }
2916
+ /* Exit if v is smaller than both sons */
2917
+ if (smaller(tree, v, s.heap[j], s.depth)) { break; }
2918
+
2919
+ /* Exchange v with the smallest son */
2920
+ s.heap[k] = s.heap[j];
2921
+ k = j;
2922
+
2923
+ /* And continue down the tree, setting j to the left son of k */
2924
+ j <<= 1;
2925
+ }
2926
+ s.heap[k] = v;
2927
+ }
2928
+
2929
+
2930
+ // inlined manually
2931
+ // var SMALLEST = 1;
2932
+
2933
+ /* ===========================================================================
2934
+ * Send the block data compressed using the given Huffman trees
2935
+ */
2936
+ function compress_block(s, ltree, dtree)
2937
+ // deflate_state *s;
2938
+ // const ct_data *ltree; /* literal tree */
2939
+ // const ct_data *dtree; /* distance tree */
2940
+ {
2941
+ var dist; /* distance of matched string */
2942
+ var lc; /* match length or unmatched char (if dist == 0) */
2943
+ var lx = 0; /* running index in l_buf */
2944
+ var code; /* the code to send */
2945
+ var extra; /* number of extra bits to send */
2946
+
2947
+ if (s.last_lit !== 0) {
2948
+ do {
2949
+ dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | (s.pending_buf[s.d_buf + lx * 2 + 1]);
2950
+ lc = s.pending_buf[s.l_buf + lx];
2951
+ lx++;
2952
+
2953
+ if (dist === 0) {
2954
+ send_code(s, lc, ltree); /* send a literal byte */
2955
+ //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
2956
+ } else {
2957
+ /* Here, lc is the match length - MIN_MATCH */
2958
+ code = _length_code[lc];
2959
+ send_code(s, code + LITERALS + 1, ltree); /* send the length code */
2960
+ extra = extra_lbits[code];
2961
+ if (extra !== 0) {
2962
+ lc -= base_length[code];
2963
+ send_bits(s, lc, extra); /* send the extra length bits */
2964
+ }
2965
+ dist--; /* dist is now the match distance - 1 */
2966
+ code = d_code(dist);
2967
+ //Assert (code < D_CODES, "bad d_code");
2968
+
2969
+ send_code(s, code, dtree); /* send the distance code */
2970
+ extra = extra_dbits[code];
2971
+ if (extra !== 0) {
2972
+ dist -= base_dist[code];
2973
+ send_bits(s, dist, extra); /* send the extra distance bits */
2974
+ }
2975
+ } /* literal or match pair ? */
2976
+
2977
+ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
2978
+ //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
2979
+ // "pendingBuf overflow");
2980
+
2981
+ } while (lx < s.last_lit);
2982
+ }
2983
+
2984
+ send_code(s, END_BLOCK, ltree);
2985
+ }
2986
+
2987
+
2988
+ /* ===========================================================================
2989
+ * Construct one Huffman tree and assigns the code bit strings and lengths.
2990
+ * Update the total bit length for the current block.
2991
+ * IN assertion: the field freq is set for all tree elements.
2992
+ * OUT assertions: the fields len and code are set to the optimal bit length
2993
+ * and corresponding code. The length opt_len is updated; static_len is
2994
+ * also updated if stree is not null. The field max_code is set.
2995
+ */
2996
+ function build_tree(s, desc)
2997
+ // deflate_state *s;
2998
+ // tree_desc *desc; /* the tree descriptor */
2999
+ {
3000
+ var tree = desc.dyn_tree;
3001
+ var stree = desc.stat_desc.static_tree;
3002
+ var has_stree = desc.stat_desc.has_stree;
3003
+ var elems = desc.stat_desc.elems;
3004
+ var n, m; /* iterate over heap elements */
3005
+ var max_code = -1; /* largest code with non zero frequency */
3006
+ var node; /* new node being created */
3007
+
3008
+ /* Construct the initial heap, with least frequent element in
3009
+ * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
3010
+ * heap[0] is not used.
3011
+ */
3012
+ s.heap_len = 0;
3013
+ s.heap_max = HEAP_SIZE;
3014
+
3015
+ for (n = 0; n < elems; n++) {
3016
+ if (tree[n * 2]/*.Freq*/ !== 0) {
3017
+ s.heap[++s.heap_len] = max_code = n;
3018
+ s.depth[n] = 0;
3019
+
3020
+ } else {
3021
+ tree[n * 2 + 1]/*.Len*/ = 0;
3022
+ }
3023
+ }
3024
+
3025
+ /* The pkzip format requires that at least one distance code exists,
3026
+ * and that at least one bit should be sent even if there is only one
3027
+ * possible code. So to avoid special checks later on we force at least
3028
+ * two codes of non zero frequency.
3029
+ */
3030
+ while (s.heap_len < 2) {
3031
+ node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);
3032
+ tree[node * 2]/*.Freq*/ = 1;
3033
+ s.depth[node] = 0;
3034
+ s.opt_len--;
3035
+
3036
+ if (has_stree) {
3037
+ s.static_len -= stree[node * 2 + 1]/*.Len*/;
3038
+ }
3039
+ /* node is 0 or 1 so it does not have extra bits */
3040
+ }
3041
+ desc.max_code = max_code;
3042
+
3043
+ /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
3044
+ * establish sub-heaps of increasing lengths:
3045
+ */
3046
+ for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }
3047
+
3048
+ /* Construct the Huffman tree by repeatedly combining the least two
3049
+ * frequent nodes.
3050
+ */
3051
+ node = elems; /* next internal node of the tree */
3052
+ do {
3053
+ //pqremove(s, tree, n); /* n = node of least frequency */
3054
+ /*** pqremove ***/
3055
+ n = s.heap[1/*SMALLEST*/];
3056
+ s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--];
3057
+ pqdownheap(s, tree, 1/*SMALLEST*/);
3058
+ /***/
3059
+
3060
+ m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */
3061
+
3062
+ s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */
3063
+ s.heap[--s.heap_max] = m;
3064
+
3065
+ /* Create a new node father of n and m */
3066
+ tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/;
3067
+ s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
3068
+ tree[n * 2 + 1]/*.Dad*/ = tree[m * 2 + 1]/*.Dad*/ = node;
3069
+
3070
+ /* and insert the new node in the heap */
3071
+ s.heap[1/*SMALLEST*/] = node++;
3072
+ pqdownheap(s, tree, 1/*SMALLEST*/);
3073
+
3074
+ } while (s.heap_len >= 2);
3075
+
3076
+ s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/];
3077
+
3078
+ /* At this point, the fields freq and dad are set. We can now
3079
+ * generate the bit lengths.
3080
+ */
3081
+ gen_bitlen(s, desc);
3082
+
3083
+ /* The field len is now set, we can generate the bit codes */
3084
+ gen_codes(tree, max_code, s.bl_count);
3085
+ }
3086
+
3087
+
3088
+ /* ===========================================================================
3089
+ * Scan a literal or distance tree to determine the frequencies of the codes
3090
+ * in the bit length tree.
3091
+ */
3092
+ function scan_tree(s, tree, max_code)
3093
+ // deflate_state *s;
3094
+ // ct_data *tree; /* the tree to be scanned */
3095
+ // int max_code; /* and its largest code of non zero frequency */
3096
+ {
3097
+ var n; /* iterates over all tree elements */
3098
+ var prevlen = -1; /* last emitted length */
3099
+ var curlen; /* length of current code */
3100
+
3101
+ var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
3102
+
3103
+ var count = 0; /* repeat count of the current code */
3104
+ var max_count = 7; /* max repeat count */
3105
+ var min_count = 4; /* min repeat count */
3106
+
3107
+ if (nextlen === 0) {
3108
+ max_count = 138;
3109
+ min_count = 3;
3110
+ }
3111
+ tree[(max_code + 1) * 2 + 1]/*.Len*/ = 0xffff; /* guard */
3112
+
3113
+ for (n = 0; n <= max_code; n++) {
3114
+ curlen = nextlen;
3115
+ nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
3116
+
3117
+ if (++count < max_count && curlen === nextlen) {
3118
+ continue;
3119
+
3120
+ } else if (count < min_count) {
3121
+ s.bl_tree[curlen * 2]/*.Freq*/ += count;
3122
+
3123
+ } else if (curlen !== 0) {
3124
+
3125
+ if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }
3126
+ s.bl_tree[REP_3_6 * 2]/*.Freq*/++;
3127
+
3128
+ } else if (count <= 10) {
3129
+ s.bl_tree[REPZ_3_10 * 2]/*.Freq*/++;
3130
+
3131
+ } else {
3132
+ s.bl_tree[REPZ_11_138 * 2]/*.Freq*/++;
3133
+ }
3134
+
3135
+ count = 0;
3136
+ prevlen = curlen;
3137
+
3138
+ if (nextlen === 0) {
3139
+ max_count = 138;
3140
+ min_count = 3;
3141
+
3142
+ } else if (curlen === nextlen) {
3143
+ max_count = 6;
3144
+ min_count = 3;
3145
+
3146
+ } else {
3147
+ max_count = 7;
3148
+ min_count = 4;
3149
+ }
3150
+ }
3151
+ }
3152
+
3153
+
3154
+ /* ===========================================================================
3155
+ * Send a literal or distance tree in compressed form, using the codes in
3156
+ * bl_tree.
3157
+ */
3158
+ function send_tree(s, tree, max_code)
3159
+ // deflate_state *s;
3160
+ // ct_data *tree; /* the tree to be scanned */
3161
+ // int max_code; /* and its largest code of non zero frequency */
3162
+ {
3163
+ var n; /* iterates over all tree elements */
3164
+ var prevlen = -1; /* last emitted length */
3165
+ var curlen; /* length of current code */
3166
+
3167
+ var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
3168
+
3169
+ var count = 0; /* repeat count of the current code */
3170
+ var max_count = 7; /* max repeat count */
3171
+ var min_count = 4; /* min repeat count */
3172
+
3173
+ /* tree[max_code+1].Len = -1; */ /* guard already set */
3174
+ if (nextlen === 0) {
3175
+ max_count = 138;
3176
+ min_count = 3;
3177
+ }
3178
+
3179
+ for (n = 0; n <= max_code; n++) {
3180
+ curlen = nextlen;
3181
+ nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
3182
+
3183
+ if (++count < max_count && curlen === nextlen) {
3184
+ continue;
3185
+
3186
+ } else if (count < min_count) {
3187
+ do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);
3188
+
3189
+ } else if (curlen !== 0) {
3190
+ if (curlen !== prevlen) {
3191
+ send_code(s, curlen, s.bl_tree);
3192
+ count--;
3193
+ }
3194
+ //Assert(count >= 3 && count <= 6, " 3_6?");
3195
+ send_code(s, REP_3_6, s.bl_tree);
3196
+ send_bits(s, count - 3, 2);
3197
+
3198
+ } else if (count <= 10) {
3199
+ send_code(s, REPZ_3_10, s.bl_tree);
3200
+ send_bits(s, count - 3, 3);
3201
+
3202
+ } else {
3203
+ send_code(s, REPZ_11_138, s.bl_tree);
3204
+ send_bits(s, count - 11, 7);
3205
+ }
3206
+
3207
+ count = 0;
3208
+ prevlen = curlen;
3209
+ if (nextlen === 0) {
3210
+ max_count = 138;
3211
+ min_count = 3;
3212
+
3213
+ } else if (curlen === nextlen) {
3214
+ max_count = 6;
3215
+ min_count = 3;
3216
+
3217
+ } else {
3218
+ max_count = 7;
3219
+ min_count = 4;
3220
+ }
3221
+ }
3222
+ }
3223
+
3224
+
3225
+ /* ===========================================================================
3226
+ * Construct the Huffman tree for the bit lengths and return the index in
3227
+ * bl_order of the last bit length code to send.
3228
+ */
3229
+ function build_bl_tree(s) {
3230
+ var max_blindex; /* index of last bit length code of non zero freq */
3231
+
3232
+ /* Determine the bit length frequencies for literal and distance trees */
3233
+ scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
3234
+ scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
3235
+
3236
+ /* Build the bit length tree: */
3237
+ build_tree(s, s.bl_desc);
3238
+ /* opt_len now includes the length of the tree representations, except
3239
+ * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
3240
+ */
3241
+
3242
+ /* Determine the number of bit length codes to send. The pkzip format
3243
+ * requires that at least 4 bit length codes be sent. (appnote.txt says
3244
+ * 3 but the actual value used is 4.)
3245
+ */
3246
+ for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
3247
+ if (s.bl_tree[bl_order[max_blindex] * 2 + 1]/*.Len*/ !== 0) {
3248
+ break;
3249
+ }
3250
+ }
3251
+ /* Update opt_len to include the bit length tree and counts */
3252
+ s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
3253
+ //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
3254
+ // s->opt_len, s->static_len));
3255
+
3256
+ return max_blindex;
3257
+ }
3258
+
3259
+
3260
+ /* ===========================================================================
3261
+ * Send the header for a block using dynamic Huffman trees: the counts, the
3262
+ * lengths of the bit length codes, the literal tree and the distance tree.
3263
+ * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
3264
+ */
3265
+ function send_all_trees(s, lcodes, dcodes, blcodes)
3266
+ // deflate_state *s;
3267
+ // int lcodes, dcodes, blcodes; /* number of codes for each tree */
3268
+ {
3269
+ var rank; /* index in bl_order */
3270
+
3271
+ //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
3272
+ //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
3273
+ // "too many codes");
3274
+ //Tracev((stderr, "\nbl counts: "));
3275
+ send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */
3276
+ send_bits(s, dcodes - 1, 5);
3277
+ send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */
3278
+ for (rank = 0; rank < blcodes; rank++) {
3279
+ //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
3280
+ send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]/*.Len*/, 3);
3281
+ }
3282
+ //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
3283
+
3284
+ send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */
3285
+ //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
3286
+
3287
+ send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */
3288
+ //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
3289
+ }
3290
+
3291
+
3292
+ /* ===========================================================================
3293
+ * Check if the data type is TEXT or BINARY, using the following algorithm:
3294
+ * - TEXT if the two conditions below are satisfied:
3295
+ * a) There are no non-portable control characters belonging to the
3296
+ * "black list" (0..6, 14..25, 28..31).
3297
+ * b) There is at least one printable character belonging to the
3298
+ * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
3299
+ * - BINARY otherwise.
3300
+ * - The following partially-portable control characters form a
3301
+ * "gray list" that is ignored in this detection algorithm:
3302
+ * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
3303
+ * IN assertion: the fields Freq of dyn_ltree are set.
3304
+ */
3305
+ function detect_data_type(s) {
3306
+ /* black_mask is the bit mask of black-listed bytes
3307
+ * set bits 0..6, 14..25, and 28..31
3308
+ * 0xf3ffc07f = binary 11110011111111111100000001111111
3309
+ */
3310
+ var black_mask = 0xf3ffc07f;
3311
+ var n;
3312
+
3313
+ /* Check for non-textual ("black-listed") bytes. */
3314
+ for (n = 0; n <= 31; n++, black_mask >>>= 1) {
3315
+ if ((black_mask & 1) && (s.dyn_ltree[n * 2]/*.Freq*/ !== 0)) {
3316
+ return Z_BINARY;
3317
+ }
3318
+ }
3319
+
3320
+ /* Check for textual ("white-listed") bytes. */
3321
+ if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||
3322
+ s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {
3323
+ return Z_TEXT;
3324
+ }
3325
+ for (n = 32; n < LITERALS; n++) {
3326
+ if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) {
3327
+ return Z_TEXT;
3328
+ }
3329
+ }
3330
+
3331
+ /* There are no "black-listed" or "white-listed" bytes:
3332
+ * this stream either is empty or has tolerated ("gray-listed") bytes only.
3333
+ */
3334
+ return Z_BINARY;
3335
+ }
3336
+
3337
+
3338
+ var static_init_done = false;
3339
+
3340
+ /* ===========================================================================
3341
+ * Initialize the tree data structures for a new zlib stream.
3342
+ */
3343
+ function _tr_init(s)
3344
+ {
3345
+
3346
+ if (!static_init_done) {
3347
+ tr_static_init();
3348
+ static_init_done = true;
3349
+ }
3350
+
3351
+ s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
3352
+ s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
3353
+ s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
3354
+
3355
+ s.bi_buf = 0;
3356
+ s.bi_valid = 0;
3357
+
3358
+ /* Initialize the first block of the first file: */
3359
+ init_block(s);
3360
+ }
3361
+
3362
+
3363
+ /* ===========================================================================
3364
+ * Send a stored block
3365
+ */
3366
+ function _tr_stored_block(s, buf, stored_len, last)
3367
+ //DeflateState *s;
3368
+ //charf *buf; /* input block */
3369
+ //ulg stored_len; /* length of input block */
3370
+ //int last; /* one if this is the last block for a file */
3371
+ {
3372
+ send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */
3373
+ copy_block(s, buf, stored_len, true); /* with header */
3374
+ }
3375
+
3376
+
3377
+ /* ===========================================================================
3378
+ * Send one empty static block to give enough lookahead for inflate.
3379
+ * This takes 10 bits, of which 7 may remain in the bit buffer.
3380
+ */
3381
+ function _tr_align(s) {
3382
+ send_bits(s, STATIC_TREES << 1, 3);
3383
+ send_code(s, END_BLOCK, static_ltree);
3384
+ bi_flush(s);
3385
+ }
3386
+
3387
+
3388
+ /* ===========================================================================
3389
+ * Determine the best encoding for the current block: dynamic trees, static
3390
+ * trees or store, and output the encoded block to the zip file.
3391
+ */
3392
+ function _tr_flush_block(s, buf, stored_len, last)
3393
+ //DeflateState *s;
3394
+ //charf *buf; /* input block, or NULL if too old */
3395
+ //ulg stored_len; /* length of input block */
3396
+ //int last; /* one if this is the last block for a file */
3397
+ {
3398
+ var opt_lenb, static_lenb; /* opt_len and static_len in bytes */
3399
+ var max_blindex = 0; /* index of last bit length code of non zero freq */
3400
+
3401
+ /* Build the Huffman trees unless a stored block is forced */
3402
+ if (s.level > 0) {
3403
+
3404
+ /* Check if the file is binary or text */
3405
+ if (s.strm.data_type === Z_UNKNOWN) {
3406
+ s.strm.data_type = detect_data_type(s);
3407
+ }
3408
+
3409
+ /* Construct the literal and distance trees */
3410
+ build_tree(s, s.l_desc);
3411
+ // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
3412
+ // s->static_len));
3413
+
3414
+ build_tree(s, s.d_desc);
3415
+ // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
3416
+ // s->static_len));
3417
+ /* At this point, opt_len and static_len are the total bit lengths of
3418
+ * the compressed block data, excluding the tree representations.
3419
+ */
3420
+
3421
+ /* Build the bit length tree for the above two trees, and get the index
3422
+ * in bl_order of the last bit length code to send.
3423
+ */
3424
+ max_blindex = build_bl_tree(s);
3425
+
3426
+ /* Determine the best encoding. Compute the block lengths in bytes. */
3427
+ opt_lenb = (s.opt_len + 3 + 7) >>> 3;
3428
+ static_lenb = (s.static_len + 3 + 7) >>> 3;
3429
+
3430
+ // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
3431
+ // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
3432
+ // s->last_lit));
3433
+
3434
+ if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
3435
+
3436
+ } else {
3437
+ // Assert(buf != (char*)0, "lost buf");
3438
+ opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
3439
+ }
3440
+
3441
+ if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) {
3442
+ /* 4: two words for the lengths */
3443
+
3444
+ /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
3445
+ * Otherwise we can't have processed more than WSIZE input bytes since
3446
+ * the last block flush, because compression would have been
3447
+ * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
3448
+ * transform a block into a stored block.
3449
+ */
3450
+ _tr_stored_block(s, buf, stored_len, last);
3451
+
3452
+ } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
3453
+
3454
+ send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
3455
+ compress_block(s, static_ltree, static_dtree);
3456
+
3457
+ } else {
3458
+ send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
3459
+ send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
3460
+ compress_block(s, s.dyn_ltree, s.dyn_dtree);
3461
+ }
3462
+ // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
3463
+ /* The above check is made mod 2^32, for files larger than 512 MB
3464
+ * and uLong implemented on 32 bits.
3465
+ */
3466
+ init_block(s);
3467
+
3468
+ if (last) {
3469
+ bi_windup(s);
3470
+ }
3471
+ // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
3472
+ // s->compressed_len-7*last));
3473
+ }
3474
+
3475
+ /* ===========================================================================
3476
+ * Save the match info and tally the frequency counts. Return true if
3477
+ * the current block must be flushed.
3478
+ */
3479
+ function _tr_tally(s, dist, lc)
3480
+ // deflate_state *s;
3481
+ // unsigned dist; /* distance of matched string */
3482
+ // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
3483
+ {
3484
+ //var out_length, in_length, dcode;
3485
+
3486
+ s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff;
3487
+ s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
3488
+
3489
+ s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
3490
+ s.last_lit++;
3491
+
3492
+ if (dist === 0) {
3493
+ /* lc is the unmatched char */
3494
+ s.dyn_ltree[lc * 2]/*.Freq*/++;
3495
+ } else {
3496
+ s.matches++;
3497
+ /* Here, lc is the match length - MIN_MATCH */
3498
+ dist--; /* dist = match distance - 1 */
3499
+ //Assert((ush)dist < (ush)MAX_DIST(s) &&
3500
+ // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
3501
+ // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
3502
+
3503
+ s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]/*.Freq*/++;
3504
+ s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;
3505
+ }
3506
+
3507
+ // (!) This block is disabled in zlib defaults,
3508
+ // don't enable it for binary compatibility
3509
+
3510
+ //#ifdef TRUNCATE_BLOCK
3511
+ // /* Try to guess if it is profitable to stop the current block here */
3512
+ // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
3513
+ // /* Compute an upper bound for the compressed length */
3514
+ // out_length = s.last_lit*8;
3515
+ // in_length = s.strstart - s.block_start;
3516
+ //
3517
+ // for (dcode = 0; dcode < D_CODES; dcode++) {
3518
+ // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
3519
+ // }
3520
+ // out_length >>>= 3;
3521
+ // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
3522
+ // // s->last_lit, in_length, out_length,
3523
+ // // 100L - out_length*100L/in_length));
3524
+ // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
3525
+ // return true;
3526
+ // }
3527
+ // }
3528
+ //#endif
3529
+
3530
+ return (s.last_lit === s.lit_bufsize - 1);
3531
+ /* We avoid equality with lit_bufsize because of wraparound at 64K
3532
+ * on 16 bit machines and because stored blocks are restricted to
3533
+ * 64K-1 bytes.
3534
+ */
3535
+ }
3536
+
3537
+ exports._tr_init = _tr_init;
3538
+ exports._tr_stored_block = _tr_stored_block;
3539
+ exports._tr_flush_block = _tr_flush_block;
3540
+ exports._tr_tally = _tr_tally;
3541
+ exports._tr_align = _tr_align;
3542
+
3543
+ },{"../utils/common":1}],8:[function(require,module,exports){
3544
+ 'use strict';
3545
+
3546
+ // (C) 1995-2013 Jean-loup Gailly and Mark Adler
3547
+ // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
3548
+ //
3549
+ // This software is provided 'as-is', without any express or implied
3550
+ // warranty. In no event will the authors be held liable for any damages
3551
+ // arising from the use of this software.
3552
+ //
3553
+ // Permission is granted to anyone to use this software for any purpose,
3554
+ // including commercial applications, and to alter it and redistribute it
3555
+ // freely, subject to the following restrictions:
3556
+ //
3557
+ // 1. The origin of this software must not be misrepresented; you must not
3558
+ // claim that you wrote the original software. If you use this software
3559
+ // in a product, an acknowledgment in the product documentation would be
3560
+ // appreciated but is not required.
3561
+ // 2. Altered source versions must be plainly marked as such, and must not be
3562
+ // misrepresented as being the original software.
3563
+ // 3. This notice may not be removed or altered from any source distribution.
3564
+
3565
+ function ZStream() {
3566
+ /* next input byte */
3567
+ this.input = null; // JS specific, because we have no pointers
3568
+ this.next_in = 0;
3569
+ /* number of bytes available at input */
3570
+ this.avail_in = 0;
3571
+ /* total number of input bytes read so far */
3572
+ this.total_in = 0;
3573
+ /* next output byte should be put there */
3574
+ this.output = null; // JS specific, because we have no pointers
3575
+ this.next_out = 0;
3576
+ /* remaining free space at output */
3577
+ this.avail_out = 0;
3578
+ /* total number of bytes output so far */
3579
+ this.total_out = 0;
3580
+ /* last error message, NULL if no error */
3581
+ this.msg = ''/*Z_NULL*/;
3582
+ /* not visible by applications */
3583
+ this.state = null;
3584
+ /* best guess about the data type: binary or text */
3585
+ this.data_type = 2/*Z_UNKNOWN*/;
3586
+ /* adler32 value of the uncompressed data */
3587
+ this.adler = 0;
3588
+ }
3589
+
3590
+ module.exports = ZStream;
3591
+
3592
+ },{}],"/lib/deflate.js":[function(require,module,exports){
3593
+ 'use strict';
3594
+
3595
+
3596
+ var zlib_deflate = require('./zlib/deflate');
3597
+ var utils = require('./utils/common');
3598
+ var strings = require('./utils/strings');
3599
+ var msg = require('./zlib/messages');
3600
+ var ZStream = require('./zlib/zstream');
3601
+
3602
+ var toString = Object.prototype.toString;
3603
+
3604
+ /* Public constants ==========================================================*/
3605
+ /* ===========================================================================*/
3606
+
3607
+ var Z_NO_FLUSH = 0;
3608
+ var Z_FINISH = 4;
3609
+
3610
+ var Z_OK = 0;
3611
+ var Z_STREAM_END = 1;
3612
+ var Z_SYNC_FLUSH = 2;
3613
+
3614
+ var Z_DEFAULT_COMPRESSION = -1;
3615
+
3616
+ var Z_DEFAULT_STRATEGY = 0;
3617
+
3618
+ var Z_DEFLATED = 8;
3619
+
3620
+ /* ===========================================================================*/
3621
+
3622
+
3623
+ /**
3624
+ * class Deflate
3625
+ *
3626
+ * Generic JS-style wrapper for zlib calls. If you don't need
3627
+ * streaming behaviour - use more simple functions: [[deflate]],
3628
+ * [[deflateRaw]] and [[gzip]].
3629
+ **/
3630
+
3631
+ /* internal
3632
+ * Deflate.chunks -> Array
3633
+ *
3634
+ * Chunks of output data, if [[Deflate#onData]] not overridden.
3635
+ **/
3636
+
3637
+ /**
3638
+ * Deflate.result -> Uint8Array|Array
3639
+ *
3640
+ * Compressed result, generated by default [[Deflate#onData]]
3641
+ * and [[Deflate#onEnd]] handlers. Filled after you push last chunk
3642
+ * (call [[Deflate#push]] with `Z_FINISH` / `true` param) or if you
3643
+ * push a chunk with explicit flush (call [[Deflate#push]] with
3644
+ * `Z_SYNC_FLUSH` param).
3645
+ **/
3646
+
3647
+ /**
3648
+ * Deflate.err -> Number
3649
+ *
3650
+ * Error code after deflate finished. 0 (Z_OK) on success.
3651
+ * You will not need it in real life, because deflate errors
3652
+ * are possible only on wrong options or bad `onData` / `onEnd`
3653
+ * custom handlers.
3654
+ **/
3655
+
3656
+ /**
3657
+ * Deflate.msg -> String
3658
+ *
3659
+ * Error message, if [[Deflate.err]] != 0
3660
+ **/
3661
+
3662
+
3663
+ /**
3664
+ * new Deflate(options)
3665
+ * - options (Object): zlib deflate options.
3666
+ *
3667
+ * Creates new deflator instance with specified params. Throws exception
3668
+ * on bad params. Supported options:
3669
+ *
3670
+ * - `level`
3671
+ * - `windowBits`
3672
+ * - `memLevel`
3673
+ * - `strategy`
3674
+ * - `dictionary`
3675
+ *
3676
+ * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
3677
+ * for more information on these.
3678
+ *
3679
+ * Additional options, for internal needs:
3680
+ *
3681
+ * - `chunkSize` - size of generated data chunks (16K by default)
3682
+ * - `raw` (Boolean) - do raw deflate
3683
+ * - `gzip` (Boolean) - create gzip wrapper
3684
+ * - `to` (String) - if equal to 'string', then result will be "binary string"
3685
+ * (each char code [0..255])
3686
+ * - `header` (Object) - custom header for gzip
3687
+ * - `text` (Boolean) - true if compressed data believed to be text
3688
+ * - `time` (Number) - modification time, unix timestamp
3689
+ * - `os` (Number) - operation system code
3690
+ * - `extra` (Array) - array of bytes with extra data (max 65536)
3691
+ * - `name` (String) - file name (binary string)
3692
+ * - `comment` (String) - comment (binary string)
3693
+ * - `hcrc` (Boolean) - true if header crc should be added
3694
+ *
3695
+ * ##### Example:
3696
+ *
3697
+ * ```javascript
3698
+ * var pako = require('pako')
3699
+ * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
3700
+ * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
3701
+ *
3702
+ * var deflate = new pako.Deflate({ level: 3});
3703
+ *
3704
+ * deflate.push(chunk1, false);
3705
+ * deflate.push(chunk2, true); // true -> last chunk
3706
+ *
3707
+ * if (deflate.err) { throw new Error(deflate.err); }
3708
+ *
3709
+ * console.log(deflate.result);
3710
+ * ```
3711
+ **/
3712
+ function Deflate(options) {
3713
+ if (!(this instanceof Deflate)) return new Deflate(options);
3714
+
3715
+ this.options = utils.assign({
3716
+ level: Z_DEFAULT_COMPRESSION,
3717
+ method: Z_DEFLATED,
3718
+ chunkSize: 16384,
3719
+ windowBits: 15,
3720
+ memLevel: 8,
3721
+ strategy: Z_DEFAULT_STRATEGY,
3722
+ to: ''
3723
+ }, options || {});
3724
+
3725
+ var opt = this.options;
3726
+
3727
+ if (opt.raw && (opt.windowBits > 0)) {
3728
+ opt.windowBits = -opt.windowBits;
3729
+ }
3730
+
3731
+ else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {
3732
+ opt.windowBits += 16;
3733
+ }
3734
+
3735
+ this.err = 0; // error code, if happens (0 = Z_OK)
3736
+ this.msg = ''; // error message
3737
+ this.ended = false; // used to avoid multiple onEnd() calls
3738
+ this.chunks = []; // chunks of compressed data
3739
+
3740
+ this.strm = new ZStream();
3741
+ this.strm.avail_out = 0;
3742
+
3743
+ var status = zlib_deflate.deflateInit2(
3744
+ this.strm,
3745
+ opt.level,
3746
+ opt.method,
3747
+ opt.windowBits,
3748
+ opt.memLevel,
3749
+ opt.strategy
3750
+ );
3751
+
3752
+ if (status !== Z_OK) {
3753
+ throw new Error(msg[status]);
3754
+ }
3755
+
3756
+ if (opt.header) {
3757
+ zlib_deflate.deflateSetHeader(this.strm, opt.header);
3758
+ }
3759
+
3760
+ if (opt.dictionary) {
3761
+ var dict;
3762
+ // Convert data if needed
3763
+ if (typeof opt.dictionary === 'string') {
3764
+ // If we need to compress text, change encoding to utf8.
3765
+ dict = strings.string2buf(opt.dictionary);
3766
+ } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
3767
+ dict = new Uint8Array(opt.dictionary);
3768
+ } else {
3769
+ dict = opt.dictionary;
3770
+ }
3771
+
3772
+ status = zlib_deflate.deflateSetDictionary(this.strm, dict);
3773
+
3774
+ if (status !== Z_OK) {
3775
+ throw new Error(msg[status]);
3776
+ }
3777
+
3778
+ this._dict_set = true;
3779
+ }
3780
+ }
3781
+
3782
+ /**
3783
+ * Deflate#push(data[, mode]) -> Boolean
3784
+ * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be
3785
+ * converted to utf8 byte sequence.
3786
+ * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
3787
+ * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
3788
+ *
3789
+ * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
3790
+ * new compressed chunks. Returns `true` on success. The last data block must have
3791
+ * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
3792
+ * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) you
3793
+ * can use mode Z_SYNC_FLUSH, keeping the compression context.
3794
+ *
3795
+ * On fail call [[Deflate#onEnd]] with error code and return false.
3796
+ *
3797
+ * We strongly recommend to use `Uint8Array` on input for best speed (output
3798
+ * array format is detected automatically). Also, don't skip last param and always
3799
+ * use the same type in your code (boolean or number). That will improve JS speed.
3800
+ *
3801
+ * For regular `Array`-s make sure all elements are [0..255].
3802
+ *
3803
+ * ##### Example
3804
+ *
3805
+ * ```javascript
3806
+ * push(chunk, false); // push one of data chunks
3807
+ * ...
3808
+ * push(chunk, true); // push last chunk
3809
+ * ```
3810
+ **/
3811
+ Deflate.prototype.push = function (data, mode) {
3812
+ var strm = this.strm;
3813
+ var chunkSize = this.options.chunkSize;
3814
+ var status, _mode;
3815
+
3816
+ if (this.ended) { return false; }
3817
+
3818
+ _mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);
3819
+
3820
+ // Convert data if needed
3821
+ if (typeof data === 'string') {
3822
+ // If we need to compress text, change encoding to utf8.
3823
+ strm.input = strings.string2buf(data);
3824
+ } else if (toString.call(data) === '[object ArrayBuffer]') {
3825
+ strm.input = new Uint8Array(data);
3826
+ } else {
3827
+ strm.input = data;
3828
+ }
3829
+
3830
+ strm.next_in = 0;
3831
+ strm.avail_in = strm.input.length;
3832
+
3833
+ do {
3834
+ if (strm.avail_out === 0) {
3835
+ strm.output = new utils.Buf8(chunkSize);
3836
+ strm.next_out = 0;
3837
+ strm.avail_out = chunkSize;
3838
+ }
3839
+ status = zlib_deflate.deflate(strm, _mode); /* no bad return value */
3840
+
3841
+ if (status !== Z_STREAM_END && status !== Z_OK) {
3842
+ this.onEnd(status);
3843
+ this.ended = true;
3844
+ return false;
3845
+ }
3846
+ if (strm.avail_out === 0 || (strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH))) {
3847
+ if (this.options.to === 'string') {
3848
+ this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
3849
+ } else {
3850
+ this.onData(utils.shrinkBuf(strm.output, strm.next_out));
3851
+ }
3852
+ }
3853
+ } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);
3854
+
3855
+ // Finalize on the last chunk.
3856
+ if (_mode === Z_FINISH) {
3857
+ status = zlib_deflate.deflateEnd(this.strm);
3858
+ this.onEnd(status);
3859
+ this.ended = true;
3860
+ return status === Z_OK;
3861
+ }
3862
+
3863
+ // callback interim results if Z_SYNC_FLUSH.
3864
+ if (_mode === Z_SYNC_FLUSH) {
3865
+ this.onEnd(Z_OK);
3866
+ strm.avail_out = 0;
3867
+ return true;
3868
+ }
3869
+
3870
+ return true;
3871
+ };
3872
+
3873
+
3874
+ /**
3875
+ * Deflate#onData(chunk) -> Void
3876
+ * - chunk (Uint8Array|Array|String): output data. Type of array depends
3877
+ * on js engine support. When string output requested, each chunk
3878
+ * will be string.
3879
+ *
3880
+ * By default, stores data blocks in `chunks[]` property and glue
3881
+ * those in `onEnd`. Override this handler, if you need another behaviour.
3882
+ **/
3883
+ Deflate.prototype.onData = function (chunk) {
3884
+ this.chunks.push(chunk);
3885
+ };
3886
+
3887
+
3888
+ /**
3889
+ * Deflate#onEnd(status) -> Void
3890
+ * - status (Number): deflate status. 0 (Z_OK) on success,
3891
+ * other if not.
3892
+ *
3893
+ * Called once after you tell deflate that the input stream is
3894
+ * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
3895
+ * or if an error happened. By default - join collected chunks,
3896
+ * free memory and fill `results` / `err` properties.
3897
+ **/
3898
+ Deflate.prototype.onEnd = function (status) {
3899
+ // On success - join
3900
+ if (status === Z_OK) {
3901
+ if (this.options.to === 'string') {
3902
+ this.result = this.chunks.join('');
3903
+ } else {
3904
+ this.result = utils.flattenChunks(this.chunks);
3905
+ }
3906
+ }
3907
+ this.chunks = [];
3908
+ this.err = status;
3909
+ this.msg = this.strm.msg;
3910
+ };
3911
+
3912
+
3913
+ /**
3914
+ * deflate(data[, options]) -> Uint8Array|Array|String
3915
+ * - data (Uint8Array|Array|String): input data to compress.
3916
+ * - options (Object): zlib deflate options.
3917
+ *
3918
+ * Compress `data` with deflate algorithm and `options`.
3919
+ *
3920
+ * Supported options are:
3921
+ *
3922
+ * - level
3923
+ * - windowBits
3924
+ * - memLevel
3925
+ * - strategy
3926
+ * - dictionary
3927
+ *
3928
+ * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
3929
+ * for more information on these.
3930
+ *
3931
+ * Sugar (options):
3932
+ *
3933
+ * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
3934
+ * negative windowBits implicitly.
3935
+ * - `to` (String) - if equal to 'string', then result will be "binary string"
3936
+ * (each char code [0..255])
3937
+ *
3938
+ * ##### Example:
3939
+ *
3940
+ * ```javascript
3941
+ * var pako = require('pako')
3942
+ * , data = Uint8Array([1,2,3,4,5,6,7,8,9]);
3943
+ *
3944
+ * console.log(pako.deflate(data));
3945
+ * ```
3946
+ **/
3947
+ function deflate(input, options) {
3948
+ var deflator = new Deflate(options);
3949
+
3950
+ deflator.push(input, true);
3951
+
3952
+ // That will never happens, if you don't cheat with options :)
3953
+ if (deflator.err) { throw deflator.msg || msg[deflator.err]; }
3954
+
3955
+ return deflator.result;
3956
+ }
3957
+
3958
+
3959
+ /**
3960
+ * deflateRaw(data[, options]) -> Uint8Array|Array|String
3961
+ * - data (Uint8Array|Array|String): input data to compress.
3962
+ * - options (Object): zlib deflate options.
3963
+ *
3964
+ * The same as [[deflate]], but creates raw data, without wrapper
3965
+ * (header and adler32 crc).
3966
+ **/
3967
+ function deflateRaw(input, options) {
3968
+ options = options || {};
3969
+ options.raw = true;
3970
+ return deflate(input, options);
3971
+ }
3972
+
3973
+
3974
+ /**
3975
+ * gzip(data[, options]) -> Uint8Array|Array|String
3976
+ * - data (Uint8Array|Array|String): input data to compress.
3977
+ * - options (Object): zlib deflate options.
3978
+ *
3979
+ * The same as [[deflate]], but create gzip wrapper instead of
3980
+ * deflate one.
3981
+ **/
3982
+ function gzip(input, options) {
3983
+ options = options || {};
3984
+ options.gzip = true;
3985
+ return deflate(input, options);
3986
+ }
3987
+
3988
+
3989
+ exports.Deflate = Deflate;
3990
+ exports.deflate = deflate;
3991
+ exports.deflateRaw = deflateRaw;
3992
+ exports.gzip = gzip;
3993
+
3994
+ },{"./utils/common":1,"./utils/strings":2,"./zlib/deflate":5,"./zlib/messages":6,"./zlib/zstream":8}]},{},[])("/lib/deflate.js")
3995
+ });