libarchive-static 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. checksums.yaml +4 -4
  2. data/ext/extconf.rb +2 -9
  3. data/ext/libarchive-0.1.1/ext/archive_read_support_compression.c +6 -6
  4. data/ext/libarchive-0.1.1/ext/archive_read_support_compression.o +0 -0
  5. data/ext/libarchive-0.1.1/ext/archive_read_support_format.o +0 -0
  6. data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.c +1 -1
  7. data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.o +0 -0
  8. data/ext/libarchive-0.1.1/ext/archive_write_set_compression.c +5 -5
  9. data/ext/libarchive-0.1.1/ext/archive_write_set_compression.o +0 -0
  10. data/ext/libarchive-0.1.1/ext/config.h +23 -0
  11. data/ext/libarchive-0.1.1/ext/config.log +230 -0
  12. data/ext/libarchive-0.1.1/ext/config.status +671 -0
  13. data/ext/libarchive-0.1.1/ext/libarchive.c +1 -1
  14. data/ext/libarchive-0.1.1/ext/libarchive.o +0 -0
  15. data/ext/libarchive-0.1.1/ext/libarchive_archive.c +7 -7
  16. data/ext/libarchive-0.1.1/ext/libarchive_archive.o +0 -0
  17. data/ext/libarchive-0.1.1/ext/libarchive_entry.c +6 -0
  18. data/ext/libarchive-0.1.1/ext/libarchive_entry.o +0 -0
  19. data/ext/libarchive-0.1.1/ext/libarchive_reader.c +6 -4
  20. data/ext/libarchive-0.1.1/ext/libarchive_reader.o +0 -0
  21. data/ext/libarchive-0.1.1/ext/libarchive_ruby.so +0 -0
  22. data/ext/libarchive-0.1.1/ext/libarchive_win32.h +1 -1
  23. data/ext/libarchive-0.1.1/ext/libarchive_writer.c +2 -2
  24. data/ext/libarchive-0.1.1/ext/libarchive_writer.o +0 -0
  25. data/ext/libarchive-3.6.2/Makefile.in +16892 -0
  26. data/ext/libarchive-3.6.2/build/autoconf/ax_append_compile_flags.m4 +67 -0
  27. data/ext/libarchive-3.6.2/build/autoconf/ax_append_flag.m4 +71 -0
  28. data/ext/libarchive-3.6.2/build/autoconf/ax_check_compile_flag.m4 +74 -0
  29. data/ext/libarchive-3.6.2/build/autoconf/ax_require_defined.m4 +37 -0
  30. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/build/autoconf/check_stdcall_func.m4 +0 -0
  31. data/ext/libarchive-3.6.2/build/autoconf/compile +348 -0
  32. data/ext/libarchive-3.6.2/build/autoconf/config.guess +1754 -0
  33. data/ext/libarchive-3.6.2/build/autoconf/config.rpath +696 -0
  34. data/ext/libarchive-3.6.2/build/autoconf/config.sub +1890 -0
  35. data/ext/libarchive-3.6.2/build/autoconf/depcomp +791 -0
  36. data/ext/libarchive-3.6.2/build/autoconf/iconv.m4 +271 -0
  37. data/ext/libarchive-3.6.2/build/autoconf/install-sh +541 -0
  38. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/build/autoconf/la_uid_t.m4 +0 -0
  39. data/ext/libarchive-3.6.2/build/autoconf/lib-ld.m4 +109 -0
  40. data/ext/libarchive-3.6.2/build/autoconf/lib-link.m4 +777 -0
  41. data/ext/libarchive-3.6.2/build/autoconf/lib-prefix.m4 +224 -0
  42. data/ext/libarchive-3.6.2/build/autoconf/ltmain.sh +11251 -0
  43. data/ext/libarchive-3.6.2/build/autoconf/m4_ax_compile_check_sizeof.m4 +115 -0
  44. data/ext/libarchive-3.6.2/build/autoconf/missing +215 -0
  45. data/ext/libarchive-3.6.2/build/autoconf/test-driver +153 -0
  46. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/build/pkgconfig/libarchive.pc.in +4 -1
  47. data/ext/libarchive-3.6.2/config.h.in +1504 -0
  48. data/ext/libarchive-3.6.2/configure +25558 -0
  49. data/ext/libarchive-3.6.2/libarchive/archive.h +1212 -0
  50. data/ext/libarchive-3.6.2/libarchive/archive_acl.c +2097 -0
  51. data/ext/libarchive-3.6.2/libarchive/archive_acl_private.h +83 -0
  52. data/ext/libarchive-3.6.2/libarchive/archive_blake2.h +197 -0
  53. data/ext/libarchive-3.6.2/libarchive/archive_blake2_impl.h +161 -0
  54. data/ext/libarchive-3.6.2/libarchive/archive_blake2s_ref.c +369 -0
  55. data/ext/libarchive-3.6.2/libarchive/archive_blake2sp_ref.c +361 -0
  56. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_check_magic.c +63 -22
  57. data/ext/libarchive-3.6.2/libarchive/archive_cmdline.c +227 -0
  58. data/ext/libarchive-3.6.2/libarchive/archive_cmdline_private.h +47 -0
  59. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_crc32.h +17 -0
  60. data/ext/libarchive-3.6.2/libarchive/archive_cryptor.c +534 -0
  61. data/ext/libarchive-3.6.2/libarchive/archive_cryptor_private.h +188 -0
  62. data/ext/libarchive-3.6.2/libarchive/archive_digest.c +1505 -0
  63. data/ext/libarchive-3.6.2/libarchive/archive_digest_private.h +416 -0
  64. data/ext/libarchive-3.6.2/libarchive/archive_disk_acl_darwin.c +559 -0
  65. data/ext/libarchive-3.6.2/libarchive/archive_disk_acl_freebsd.c +712 -0
  66. data/ext/libarchive-3.6.2/libarchive/archive_disk_acl_linux.c +760 -0
  67. data/ext/libarchive-3.6.2/libarchive/archive_disk_acl_sunos.c +824 -0
  68. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_endian.h +48 -15
  69. data/ext/libarchive-3.6.2/libarchive/archive_entry.c +2149 -0
  70. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry.h +305 -106
  71. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_copy_bhfi.c +5 -4
  72. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_copy_stat.c +9 -3
  73. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_link_resolver.c +104 -62
  74. data/ext/libarchive-3.6.2/libarchive/archive_entry_locale.h +92 -0
  75. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_private.h +65 -49
  76. data/ext/libarchive-3.6.2/libarchive/archive_entry_sparse.c +156 -0
  77. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_stat.c +6 -6
  78. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_strmode.c +1 -1
  79. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_xattr.c +4 -6
  80. data/ext/libarchive-3.6.2/libarchive/archive_getdate.c +1165 -0
  81. data/ext/libarchive-3.6.2/libarchive/archive_getdate.h +39 -0
  82. data/ext/libarchive-3.6.2/libarchive/archive_hmac.c +334 -0
  83. data/ext/libarchive-3.6.2/libarchive/archive_hmac_private.h +117 -0
  84. data/ext/libarchive-3.6.2/libarchive/archive_match.c +1875 -0
  85. data/ext/libarchive-3.6.2/libarchive/archive_openssl_evp_private.h +53 -0
  86. data/ext/libarchive-3.6.2/libarchive/archive_openssl_hmac_private.h +54 -0
  87. data/ext/libarchive-3.6.2/libarchive/archive_options.c +218 -0
  88. data/ext/libarchive-3.6.2/libarchive/archive_options_private.h +51 -0
  89. data/ext/libarchive-3.6.2/libarchive/archive_pack_dev.c +337 -0
  90. data/ext/libarchive-3.6.2/libarchive/archive_pack_dev.h +49 -0
  91. data/ext/libarchive-3.6.2/libarchive/archive_pathmatch.c +463 -0
  92. data/ext/libarchive-3.6.2/libarchive/archive_pathmatch.h +52 -0
  93. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_platform.h +77 -9
  94. data/ext/libarchive-3.6.2/libarchive/archive_platform_acl.h +55 -0
  95. data/ext/libarchive-3.6.2/libarchive/archive_platform_xattr.h +47 -0
  96. data/ext/libarchive-3.6.2/libarchive/archive_ppmd7.c +1168 -0
  97. data/ext/libarchive-3.6.2/libarchive/archive_ppmd7_private.h +119 -0
  98. data/ext/libarchive-3.6.2/libarchive/archive_ppmd8.c +1287 -0
  99. data/ext/libarchive-3.6.2/libarchive/archive_ppmd8_private.h +148 -0
  100. data/ext/libarchive-3.6.2/libarchive/archive_ppmd_private.h +151 -0
  101. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_private.h +74 -18
  102. data/ext/libarchive-3.6.2/libarchive/archive_random.c +272 -0
  103. data/ext/libarchive-3.6.2/libarchive/archive_random_private.h +36 -0
  104. data/ext/libarchive-3.6.2/libarchive/archive_rb.c +709 -0
  105. data/ext/libarchive-3.6.2/libarchive/archive_rb.h +113 -0
  106. data/ext/libarchive-3.6.2/libarchive/archive_read.c +1756 -0
  107. data/ext/libarchive-3.6.2/libarchive/archive_read_add_passphrase.c +190 -0
  108. data/ext/libarchive-3.6.2/libarchive/archive_read_append_filter.c +204 -0
  109. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_data_into_fd.c +64 -18
  110. data/ext/libarchive-3.6.2/libarchive/archive_read_disk_entry_from_file.c +1086 -0
  111. data/ext/libarchive-3.6.2/libarchive/archive_read_disk_posix.c +2732 -0
  112. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_disk_private.h +40 -4
  113. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_disk_set_standard_lookup.c +21 -11
  114. data/ext/libarchive-3.6.2/libarchive/archive_read_disk_windows.c +2479 -0
  115. data/ext/libarchive-3.6.2/libarchive/archive_read_extract.c +60 -0
  116. data/ext/{libarchive-2.8.4/libarchive/archive_read_extract.c → libarchive-3.6.2/libarchive/archive_read_extract2.c} +34 -61
  117. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_open_fd.c +70 -49
  118. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_open_file.c +38 -23
  119. data/ext/libarchive-3.6.2/libarchive/archive_read_open_filename.c +586 -0
  120. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_open_memory.c +58 -28
  121. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_private.h +127 -59
  122. data/ext/libarchive-3.6.2/libarchive/archive_read_set_format.c +117 -0
  123. data/ext/libarchive-3.6.2/libarchive/archive_read_set_options.c +133 -0
  124. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_all.c → libarchive-3.6.2/libarchive/archive_read_support_filter_all.c} +35 -10
  125. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_by_code.c +83 -0
  126. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_bzip2.c → libarchive-3.6.2/libarchive/archive_read_support_filter_bzip2.c} +38 -26
  127. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_compress.c → libarchive-3.6.2/libarchive/archive_read_support_filter_compress.c} +52 -44
  128. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_grzip.c +112 -0
  129. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_gzip.c → libarchive-3.6.2/libarchive/archive_read_support_filter_gzip.c} +108 -37
  130. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_lrzip.c +122 -0
  131. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_lz4.c +742 -0
  132. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_lzop.c +499 -0
  133. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_none.c → libarchive-3.6.2/libarchive/archive_read_support_filter_none.c} +15 -3
  134. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_program.c → libarchive-3.6.2/libarchive/archive_read_support_filter_program.c} +114 -77
  135. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_rpm.c → libarchive-3.6.2/libarchive/archive_read_support_filter_rpm.c} +31 -31
  136. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_uu.c → libarchive-3.6.2/libarchive/archive_read_support_filter_uu.c} +141 -85
  137. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_xz.c → libarchive-3.6.2/libarchive/archive_read_support_filter_xz.c} +369 -284
  138. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_zstd.c +297 -0
  139. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_7zip.c +3900 -0
  140. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_all.c +89 -0
  141. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_ar.c +126 -72
  142. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_by_code.c +92 -0
  143. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_cab.c +3228 -0
  144. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_cpio.c +1104 -0
  145. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_empty.c +14 -11
  146. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_iso9660.c +990 -541
  147. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_lha.c +2916 -0
  148. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_mtree.c +2150 -0
  149. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_rar.c +3797 -0
  150. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_rar5.c +4251 -0
  151. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_raw.c +38 -31
  152. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_tar.c +1157 -629
  153. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_warc.c +848 -0
  154. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_xar.c +439 -258
  155. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_zip.c +4270 -0
  156. data/ext/libarchive-3.6.2/libarchive/archive_string.c +4240 -0
  157. data/ext/libarchive-3.6.2/libarchive/archive_string.h +243 -0
  158. data/ext/libarchive-3.6.2/libarchive/archive_string_composition.h +2292 -0
  159. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_string_sprintf.c +44 -16
  160. data/ext/libarchive-3.6.2/libarchive/archive_util.c +655 -0
  161. data/ext/libarchive-3.6.2/libarchive/archive_version_details.c +151 -0
  162. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_virtual.c +85 -16
  163. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_windows.c +214 -541
  164. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_windows.h +74 -106
  165. data/ext/libarchive-3.6.2/libarchive/archive_write.c +828 -0
  166. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter.c +72 -0
  167. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_b64encode.c +304 -0
  168. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_by_name.c +77 -0
  169. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_bzip2.c +401 -0
  170. data/ext/{libarchive-2.8.4/libarchive/archive_write_set_compression_compress.c → libarchive-3.6.2/libarchive/archive_write_add_filter_compress.c} +86 -131
  171. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_grzip.c +135 -0
  172. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_gzip.c +442 -0
  173. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_lrzip.c +197 -0
  174. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_lz4.c +700 -0
  175. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_lzop.c +478 -0
  176. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_format_all.c → libarchive-3.6.2/libarchive/archive_write_add_filter_none.c} +11 -11
  177. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_program.c +391 -0
  178. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_uuencode.c +295 -0
  179. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_xz.c +545 -0
  180. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_zstd.c +418 -0
  181. data/ext/libarchive-3.6.2/libarchive/archive_write_disk_posix.c +4711 -0
  182. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_disk_private.h +9 -2
  183. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_disk_set_standard_lookup.c +30 -29
  184. data/ext/libarchive-3.6.2/libarchive/archive_write_disk_windows.c +2842 -0
  185. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_open_fd.c +15 -10
  186. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_open_file.c +15 -9
  187. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_open_filename.c +128 -20
  188. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_open_memory.c +7 -18
  189. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_private.h +72 -29
  190. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format.c +56 -3
  191. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_7zip.c +2322 -0
  192. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_ar.c +54 -34
  193. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_by_name.c +20 -2
  194. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_cpio.c +11 -0
  195. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_cpio_binary.c +610 -0
  196. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_cpio_newc.c +457 -0
  197. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_cpio_odc.c +500 -0
  198. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_filter_by_ext.c +142 -0
  199. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_gnutar.c +755 -0
  200. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_iso9660.c +8165 -0
  201. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_mtree.c +2217 -0
  202. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_pax.c +1049 -387
  203. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_private.h +42 -0
  204. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_raw.c +125 -0
  205. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_shar.c +62 -47
  206. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_ustar.c +279 -108
  207. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_v7tar.c +638 -0
  208. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_warc.c +453 -0
  209. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_xar.c +3259 -0
  210. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_zip.c +1704 -0
  211. data/ext/libarchive-3.6.2/libarchive/archive_write_set_options.c +130 -0
  212. data/ext/libarchive-3.6.2/libarchive/archive_write_set_passphrase.c +95 -0
  213. data/ext/libarchive-3.6.2/libarchive/archive_xxhash.h +48 -0
  214. data/ext/libarchive-3.6.2/libarchive/config_freebsd.h +271 -0
  215. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/filter_fork.h +10 -5
  216. data/ext/{libarchive-2.8.4/libarchive/filter_fork.c → libarchive-3.6.2/libarchive/filter_fork_posix.c} +98 -19
  217. data/ext/libarchive-3.6.2/libarchive/filter_fork_windows.c +236 -0
  218. data/ext/libarchive-3.6.2/libarchive/xxhash.c +525 -0
  219. data/ext/libarchive-static-makefile +144 -80
  220. data/ext/libarchive-static-wrapper-makefile +1 -1
  221. data/ext/zlib-1.2.13/Makefile.in +404 -0
  222. data/ext/{zlib-1.2.5 → zlib-1.2.13}/adler32.c +51 -34
  223. data/ext/{zlib-1.2.5 → zlib-1.2.13}/compress.c +27 -21
  224. data/ext/zlib-1.2.13/configure +922 -0
  225. data/ext/zlib-1.2.13/crc32.c +1125 -0
  226. data/ext/zlib-1.2.13/crc32.h +9446 -0
  227. data/ext/{zlib-1.2.5 → zlib-1.2.13}/deflate.c +842 -459
  228. data/ext/{zlib-1.2.5 → zlib-1.2.13}/deflate.h +37 -33
  229. data/ext/{zlib-1.2.5 → zlib-1.2.13}/gzclose.c +0 -0
  230. data/ext/{zlib-1.2.5 → zlib-1.2.13}/gzguts.h +103 -16
  231. data/ext/{zlib-1.2.5 → zlib-1.2.13}/gzlib.c +155 -53
  232. data/ext/zlib-1.2.13/gzread.c +650 -0
  233. data/ext/zlib-1.2.13/gzwrite.c +677 -0
  234. data/ext/{zlib-1.2.5 → zlib-1.2.13}/infback.c +24 -12
  235. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inffast.c +49 -66
  236. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inffast.h +0 -0
  237. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inffixed.h +3 -3
  238. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inflate.c +209 -94
  239. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inflate.h +9 -5
  240. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inftrees.c +24 -50
  241. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inftrees.h +1 -1
  242. data/ext/{zlib-1.2.5 → zlib-1.2.13}/trees.c +135 -198
  243. data/ext/{zlib-1.2.5 → zlib-1.2.13}/trees.h +0 -0
  244. data/ext/zlib-1.2.13/uncompr.c +93 -0
  245. data/ext/{zlib-1.2.5 → zlib-1.2.13}/zconf.h +182 -63
  246. data/ext/{zlib-1.2.5 → zlib-1.2.13}/zlib.h +617 -295
  247. data/ext/{zlib-1.2.5 → zlib-1.2.13}/zutil.c +50 -41
  248. data/ext/{zlib-1.2.5 → zlib-1.2.13}/zutil.h +83 -82
  249. metadata +241 -133
  250. data/ext/libarchive-0.1.1/libarchive.c +0 -1762
  251. data/ext/libarchive-2.8.4/Makefile.in +0 -7076
  252. data/ext/libarchive-2.8.4/build/autoconf/compile +0 -143
  253. data/ext/libarchive-2.8.4/build/autoconf/config.guess +0 -1502
  254. data/ext/libarchive-2.8.4/build/autoconf/config.sub +0 -1708
  255. data/ext/libarchive-2.8.4/build/autoconf/depcomp +0 -630
  256. data/ext/libarchive-2.8.4/build/autoconf/install-sh +0 -291
  257. data/ext/libarchive-2.8.4/build/autoconf/ltmain.sh +0 -8406
  258. data/ext/libarchive-2.8.4/build/autoconf/missing +0 -376
  259. data/ext/libarchive-2.8.4/config.h.in +0 -772
  260. data/ext/libarchive-2.8.4/configure +0 -17916
  261. data/ext/libarchive-2.8.4/libarchive/archive.h +0 -741
  262. data/ext/libarchive-2.8.4/libarchive/archive_entry.c +0 -2202
  263. data/ext/libarchive-2.8.4/libarchive/archive_hash.h +0 -281
  264. data/ext/libarchive-2.8.4/libarchive/archive_read.c +0 -1249
  265. data/ext/libarchive-2.8.4/libarchive/archive_read_disk.c +0 -198
  266. data/ext/libarchive-2.8.4/libarchive/archive_read_disk_entry_from_file.c +0 -570
  267. data/ext/libarchive-2.8.4/libarchive/archive_read_open_filename.c +0 -272
  268. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_cpio.c +0 -777
  269. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_mtree.c +0 -1304
  270. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_zip.c +0 -903
  271. data/ext/libarchive-2.8.4/libarchive/archive_string.c +0 -453
  272. data/ext/libarchive-2.8.4/libarchive/archive_string.h +0 -148
  273. data/ext/libarchive-2.8.4/libarchive/archive_util.c +0 -391
  274. data/ext/libarchive-2.8.4/libarchive/archive_write.c +0 -466
  275. data/ext/libarchive-2.8.4/libarchive/archive_write_disk.c +0 -2628
  276. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_bzip2.c +0 -408
  277. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_gzip.c +0 -477
  278. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_none.c +0 -257
  279. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_program.c +0 -347
  280. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_xz.c +0 -438
  281. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio.c +0 -344
  282. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio_newc.c +0 -295
  283. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_mtree.c +0 -1050
  284. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_zip.c +0 -667
  285. data/ext/libarchive-2.8.4/libarchive/config_freebsd.h +0 -154
  286. data/ext/libarchive-2.8.4/libarchive/filter_fork_windows.c +0 -113
  287. data/ext/zlib-1.2.5/Makefile.in +0 -257
  288. data/ext/zlib-1.2.5/configure +0 -596
  289. data/ext/zlib-1.2.5/crc32.c +0 -442
  290. data/ext/zlib-1.2.5/crc32.h +0 -441
  291. data/ext/zlib-1.2.5/example.c +0 -565
  292. data/ext/zlib-1.2.5/gzread.c +0 -653
  293. data/ext/zlib-1.2.5/gzwrite.c +0 -531
  294. data/ext/zlib-1.2.5/minigzip.c +0 -440
  295. data/ext/zlib-1.2.5/uncompr.c +0 -59
@@ -1,5 +1,5 @@
1
1
  /* deflate.c -- compress data using the deflation algorithm
2
- * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
2
+ * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -37,7 +37,7 @@
37
37
  * REFERENCES
38
38
  *
39
39
  * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
40
- * Available in http://www.ietf.org/rfc/rfc1951.txt
40
+ * Available in http://tools.ietf.org/html/rfc1951
41
41
  *
42
42
  * A description of the Rabin and Karp algorithm is given in the book
43
43
  * "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
@@ -52,7 +52,7 @@
52
52
  #include "deflate.h"
53
53
 
54
54
  const char deflate_copyright[] =
55
- " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
55
+ " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler ";
56
56
  /*
57
57
  If you use the zlib library in a product, an acknowledgment is welcome
58
58
  in the documentation of your product. If for some reason you cannot
@@ -73,6 +73,8 @@ typedef enum {
73
73
  typedef block_state (*compress_func) OF((deflate_state *s, int flush));
74
74
  /* Compression function. Returns the block state after the call. */
75
75
 
76
+ local int deflateStateCheck OF((z_streamp strm));
77
+ local void slide_hash OF((deflate_state *s));
76
78
  local void fill_window OF((deflate_state *s));
77
79
  local block_state deflate_stored OF((deflate_state *s, int flush));
78
80
  local block_state deflate_fast OF((deflate_state *s, int flush));
@@ -84,15 +86,10 @@ local block_state deflate_huff OF((deflate_state *s, int flush));
84
86
  local void lm_init OF((deflate_state *s));
85
87
  local void putShortMSB OF((deflate_state *s, uInt b));
86
88
  local void flush_pending OF((z_streamp strm));
87
- local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
88
- #ifdef ASMV
89
- void match_init OF((void)); /* asm code initialization */
90
- uInt longest_match OF((deflate_state *s, IPos cur_match));
91
- #else
89
+ local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
92
90
  local uInt longest_match OF((deflate_state *s, IPos cur_match));
93
- #endif
94
91
 
95
- #ifdef DEBUG
92
+ #ifdef ZLIB_DEBUG
96
93
  local void check_match OF((deflate_state *s, IPos start, IPos match,
97
94
  int length));
98
95
  #endif
@@ -148,20 +145,16 @@ local const config configuration_table[10] = {
148
145
  * meaning.
149
146
  */
150
147
 
151
- #define EQUAL 0
152
- /* result of memcmp for equal strings */
153
-
154
- #ifndef NO_DUMMY_DECL
155
- struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
156
- #endif
148
+ /* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
149
+ #define RANK(f) (((f) * 2) - ((f) > 4 ? 9 : 0))
157
150
 
158
151
  /* ===========================================================================
159
152
  * Update a hash value with the given input byte
160
- * IN assertion: all calls to to UPDATE_HASH are made with consecutive
161
- * input characters, so that a running hash key can be computed from the
162
- * previous key instead of complete recalculation each time.
153
+ * IN assertion: all calls to UPDATE_HASH are made with consecutive input
154
+ * characters, so that a running hash key can be computed from the previous
155
+ * key instead of complete recalculation each time.
163
156
  */
164
- #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
157
+ #define UPDATE_HASH(s,h,c) (h = (((h) << s->hash_shift) ^ (c)) & s->hash_mask)
165
158
 
166
159
 
167
160
  /* ===========================================================================
@@ -170,9 +163,9 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
170
163
  * the previous length of the hash chain.
171
164
  * If this file is compiled with -DFASTEST, the compression level is forced
172
165
  * to 1, and no hash chains are maintained.
173
- * IN assertion: all calls to to INSERT_STRING are made with consecutive
174
- * input characters and the first MIN_MATCH bytes of str are valid
175
- * (except for the last MIN_MATCH-1 bytes of the input file).
166
+ * IN assertion: all calls to INSERT_STRING are made with consecutive input
167
+ * characters and the first MIN_MATCH bytes of str are valid (except for
168
+ * the last MIN_MATCH-1 bytes of the input file).
176
169
  */
177
170
  #ifdef FASTEST
178
171
  #define INSERT_STRING(s, str, match_head) \
@@ -191,8 +184,42 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
191
184
  * prev[] will be initialized on the fly.
192
185
  */
193
186
  #define CLEAR_HASH(s) \
194
- s->head[s->hash_size-1] = NIL; \
195
- zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
187
+ do { \
188
+ s->head[s->hash_size - 1] = NIL; \
189
+ zmemzero((Bytef *)s->head, \
190
+ (unsigned)(s->hash_size - 1)*sizeof(*s->head)); \
191
+ } while (0)
192
+
193
+ /* ===========================================================================
194
+ * Slide the hash table when sliding the window down (could be avoided with 32
195
+ * bit values at the expense of memory usage). We slide even when level == 0 to
196
+ * keep the hash table consistent if we switch back to level > 0 later.
197
+ */
198
+ local void slide_hash(s)
199
+ deflate_state *s;
200
+ {
201
+ unsigned n, m;
202
+ Posf *p;
203
+ uInt wsize = s->w_size;
204
+
205
+ n = s->hash_size;
206
+ p = &s->head[n];
207
+ do {
208
+ m = *--p;
209
+ *p = (Pos)(m >= wsize ? m - wsize : NIL);
210
+ } while (--n);
211
+ n = wsize;
212
+ #ifndef FASTEST
213
+ p = &s->prev[n];
214
+ do {
215
+ m = *--p;
216
+ *p = (Pos)(m >= wsize ? m - wsize : NIL);
217
+ /* If n is not on any hash chain, prev[n] is garbage but
218
+ * its value will never be used.
219
+ */
220
+ } while (--n);
221
+ #endif
222
+ }
196
223
 
197
224
  /* ========================================================================= */
198
225
  int ZEXPORT deflateInit_(strm, level, version, stream_size)
@@ -222,11 +249,6 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
222
249
  int wrap = 1;
223
250
  static const char my_version[] = ZLIB_VERSION;
224
251
 
225
- ushf *overlay;
226
- /* We overlay pending_buf and d_buf+l_buf. This works since the average
227
- * output size for (length,distance) codes is <= 24 bits.
228
- */
229
-
230
252
  if (version == Z_NULL || version[0] != my_version[0] ||
231
253
  stream_size != sizeof(z_stream)) {
232
254
  return Z_VERSION_ERROR;
@@ -235,10 +257,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
235
257
 
236
258
  strm->msg = Z_NULL;
237
259
  if (strm->zalloc == (alloc_func)0) {
260
+ #ifdef Z_SOLO
261
+ return Z_STREAM_ERROR;
262
+ #else
238
263
  strm->zalloc = zcalloc;
239
264
  strm->opaque = (voidpf)0;
265
+ #endif
240
266
  }
241
- if (strm->zfree == (free_func)0) strm->zfree = zcfree;
267
+ if (strm->zfree == (free_func)0)
268
+ #ifdef Z_SOLO
269
+ return Z_STREAM_ERROR;
270
+ #else
271
+ strm->zfree = zcfree;
272
+ #endif
242
273
 
243
274
  #ifdef FASTEST
244
275
  if (level != 0) level = 1;
@@ -248,6 +279,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
248
279
 
249
280
  if (windowBits < 0) { /* suppress zlib wrapper */
250
281
  wrap = 0;
282
+ if (windowBits < -15)
283
+ return Z_STREAM_ERROR;
251
284
  windowBits = -windowBits;
252
285
  }
253
286
  #ifdef GZIP
@@ -258,7 +291,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
258
291
  #endif
259
292
  if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
260
293
  windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
261
- strategy < 0 || strategy > Z_FIXED) {
294
+ strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) {
262
295
  return Z_STREAM_ERROR;
263
296
  }
264
297
  if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
@@ -266,17 +299,18 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
266
299
  if (s == Z_NULL) return Z_MEM_ERROR;
267
300
  strm->state = (struct internal_state FAR *)s;
268
301
  s->strm = strm;
302
+ s->status = INIT_STATE; /* to pass state test in deflateReset() */
269
303
 
270
304
  s->wrap = wrap;
271
305
  s->gzhead = Z_NULL;
272
- s->w_bits = windowBits;
306
+ s->w_bits = (uInt)windowBits;
273
307
  s->w_size = 1 << s->w_bits;
274
308
  s->w_mask = s->w_size - 1;
275
309
 
276
- s->hash_bits = memLevel + 7;
310
+ s->hash_bits = (uInt)memLevel + 7;
277
311
  s->hash_size = 1 << s->hash_bits;
278
312
  s->hash_mask = s->hash_size - 1;
279
- s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
313
+ s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH);
280
314
 
281
315
  s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
282
316
  s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
@@ -286,19 +320,61 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
286
320
 
287
321
  s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
288
322
 
289
- overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
290
- s->pending_buf = (uchf *) overlay;
291
- s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
323
+ /* We overlay pending_buf and sym_buf. This works since the average size
324
+ * for length/distance pairs over any compressed block is assured to be 31
325
+ * bits or less.
326
+ *
327
+ * Analysis: The longest fixed codes are a length code of 8 bits plus 5
328
+ * extra bits, for lengths 131 to 257. The longest fixed distance codes are
329
+ * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
330
+ * possible fixed-codes length/distance pair is then 31 bits total.
331
+ *
332
+ * sym_buf starts one-fourth of the way into pending_buf. So there are
333
+ * three bytes in sym_buf for every four bytes in pending_buf. Each symbol
334
+ * in sym_buf is three bytes -- two for the distance and one for the
335
+ * literal/length. As each symbol is consumed, the pointer to the next
336
+ * sym_buf value to read moves forward three bytes. From that symbol, up to
337
+ * 31 bits are written to pending_buf. The closest the written pending_buf
338
+ * bits gets to the next sym_buf symbol to read is just before the last
339
+ * code is written. At that time, 31*(n - 2) bits have been written, just
340
+ * after 24*(n - 2) bits have been consumed from sym_buf. sym_buf starts at
341
+ * 8*n bits into pending_buf. (Note that the symbol buffer fills when n - 1
342
+ * symbols are written.) The closest the writing gets to what is unread is
343
+ * then n + 14 bits. Here n is lit_bufsize, which is 16384 by default, and
344
+ * can range from 128 to 32768.
345
+ *
346
+ * Therefore, at a minimum, there are 142 bits of space between what is
347
+ * written and what is read in the overlain buffers, so the symbols cannot
348
+ * be overwritten by the compressed data. That space is actually 139 bits,
349
+ * due to the three-bit fixed-code block header.
350
+ *
351
+ * That covers the case where either Z_FIXED is specified, forcing fixed
352
+ * codes, or when the use of fixed codes is chosen, because that choice
353
+ * results in a smaller compressed block than dynamic codes. That latter
354
+ * condition then assures that the above analysis also covers all dynamic
355
+ * blocks. A dynamic-code block will only be chosen to be emitted if it has
356
+ * fewer bits than a fixed-code block would for the same set of symbols.
357
+ * Therefore its average symbol length is assured to be less than 31. So
358
+ * the compressed data for a dynamic block also cannot overwrite the
359
+ * symbols from which it is being constructed.
360
+ */
361
+
362
+ s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4);
363
+ s->pending_buf_size = (ulg)s->lit_bufsize * 4;
292
364
 
293
365
  if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
294
366
  s->pending_buf == Z_NULL) {
295
367
  s->status = FINISH_STATE;
296
- strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
368
+ strm->msg = ERR_MSG(Z_MEM_ERROR);
297
369
  deflateEnd (strm);
298
370
  return Z_MEM_ERROR;
299
371
  }
300
- s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
301
- s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
372
+ s->sym_buf = s->pending_buf + s->lit_bufsize;
373
+ s->sym_end = (s->lit_bufsize - 1) * 3;
374
+ /* We avoid equality with lit_bufsize*3 because of wraparound at 64K
375
+ * on 16 bit machines and because stored blocks are restricted to
376
+ * 64K-1 bytes.
377
+ */
302
378
 
303
379
  s->level = level;
304
380
  s->strategy = strategy;
@@ -307,56 +383,129 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
307
383
  return deflateReset(strm);
308
384
  }
309
385
 
386
+ /* =========================================================================
387
+ * Check for a valid deflate stream state. Return 0 if ok, 1 if not.
388
+ */
389
+ local int deflateStateCheck(strm)
390
+ z_streamp strm;
391
+ {
392
+ deflate_state *s;
393
+ if (strm == Z_NULL ||
394
+ strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
395
+ return 1;
396
+ s = strm->state;
397
+ if (s == Z_NULL || s->strm != strm || (s->status != INIT_STATE &&
398
+ #ifdef GZIP
399
+ s->status != GZIP_STATE &&
400
+ #endif
401
+ s->status != EXTRA_STATE &&
402
+ s->status != NAME_STATE &&
403
+ s->status != COMMENT_STATE &&
404
+ s->status != HCRC_STATE &&
405
+ s->status != BUSY_STATE &&
406
+ s->status != FINISH_STATE))
407
+ return 1;
408
+ return 0;
409
+ }
410
+
310
411
  /* ========================================================================= */
311
- int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
412
+ int ZEXPORT deflateSetDictionary(strm, dictionary, dictLength)
312
413
  z_streamp strm;
313
414
  const Bytef *dictionary;
314
415
  uInt dictLength;
315
416
  {
316
417
  deflate_state *s;
317
- uInt length = dictLength;
318
- uInt n;
319
- IPos hash_head = 0;
418
+ uInt str, n;
419
+ int wrap;
420
+ unsigned avail;
421
+ z_const unsigned char *next;
320
422
 
321
- if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
322
- strm->state->wrap == 2 ||
323
- (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
423
+ if (deflateStateCheck(strm) || dictionary == Z_NULL)
324
424
  return Z_STREAM_ERROR;
325
-
326
425
  s = strm->state;
327
- if (s->wrap)
328
- strm->adler = adler32(strm->adler, dictionary, dictLength);
426
+ wrap = s->wrap;
427
+ if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
428
+ return Z_STREAM_ERROR;
329
429
 
330
- if (length < MIN_MATCH) return Z_OK;
331
- if (length > s->w_size) {
332
- length = s->w_size;
333
- dictionary += dictLength - length; /* use the tail of the dictionary */
430
+ /* when using zlib wrappers, compute Adler-32 for provided dictionary */
431
+ if (wrap == 1)
432
+ strm->adler = adler32(strm->adler, dictionary, dictLength);
433
+ s->wrap = 0; /* avoid computing Adler-32 in read_buf */
434
+
435
+ /* if dictionary would fill window, just replace the history */
436
+ if (dictLength >= s->w_size) {
437
+ if (wrap == 0) { /* already empty otherwise */
438
+ CLEAR_HASH(s);
439
+ s->strstart = 0;
440
+ s->block_start = 0L;
441
+ s->insert = 0;
442
+ }
443
+ dictionary += dictLength - s->w_size; /* use the tail */
444
+ dictLength = s->w_size;
334
445
  }
335
- zmemcpy(s->window, dictionary, length);
336
- s->strstart = length;
337
- s->block_start = (long)length;
338
446
 
339
- /* Insert all strings in the hash table (except for the last two bytes).
340
- * s->lookahead stays null, so s->ins_h will be recomputed at the next
341
- * call of fill_window.
342
- */
343
- s->ins_h = s->window[0];
344
- UPDATE_HASH(s, s->ins_h, s->window[1]);
345
- for (n = 0; n <= length - MIN_MATCH; n++) {
346
- INSERT_STRING(s, n, hash_head);
447
+ /* insert dictionary into window and hash */
448
+ avail = strm->avail_in;
449
+ next = strm->next_in;
450
+ strm->avail_in = dictLength;
451
+ strm->next_in = (z_const Bytef *)dictionary;
452
+ fill_window(s);
453
+ while (s->lookahead >= MIN_MATCH) {
454
+ str = s->strstart;
455
+ n = s->lookahead - (MIN_MATCH-1);
456
+ do {
457
+ UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
458
+ #ifndef FASTEST
459
+ s->prev[str & s->w_mask] = s->head[s->ins_h];
460
+ #endif
461
+ s->head[s->ins_h] = (Pos)str;
462
+ str++;
463
+ } while (--n);
464
+ s->strstart = str;
465
+ s->lookahead = MIN_MATCH-1;
466
+ fill_window(s);
347
467
  }
348
- if (hash_head) hash_head = 0; /* to make compiler happy */
468
+ s->strstart += s->lookahead;
469
+ s->block_start = (long)s->strstart;
470
+ s->insert = s->lookahead;
471
+ s->lookahead = 0;
472
+ s->match_length = s->prev_length = MIN_MATCH-1;
473
+ s->match_available = 0;
474
+ strm->next_in = next;
475
+ strm->avail_in = avail;
476
+ s->wrap = wrap;
477
+ return Z_OK;
478
+ }
479
+
480
+ /* ========================================================================= */
481
+ int ZEXPORT deflateGetDictionary(strm, dictionary, dictLength)
482
+ z_streamp strm;
483
+ Bytef *dictionary;
484
+ uInt *dictLength;
485
+ {
486
+ deflate_state *s;
487
+ uInt len;
488
+
489
+ if (deflateStateCheck(strm))
490
+ return Z_STREAM_ERROR;
491
+ s = strm->state;
492
+ len = s->strstart + s->lookahead;
493
+ if (len > s->w_size)
494
+ len = s->w_size;
495
+ if (dictionary != Z_NULL && len)
496
+ zmemcpy(dictionary, s->window + s->strstart + s->lookahead - len, len);
497
+ if (dictLength != Z_NULL)
498
+ *dictLength = len;
349
499
  return Z_OK;
350
500
  }
351
501
 
352
502
  /* ========================================================================= */
353
- int ZEXPORT deflateReset (strm)
503
+ int ZEXPORT deflateResetKeep(strm)
354
504
  z_streamp strm;
355
505
  {
356
506
  deflate_state *s;
357
507
 
358
- if (strm == Z_NULL || strm->state == Z_NULL ||
359
- strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
508
+ if (deflateStateCheck(strm)) {
360
509
  return Z_STREAM_ERROR;
361
510
  }
362
511
 
@@ -371,40 +520,84 @@ int ZEXPORT deflateReset (strm)
371
520
  if (s->wrap < 0) {
372
521
  s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
373
522
  }
374
- s->status = s->wrap ? INIT_STATE : BUSY_STATE;
523
+ s->status =
524
+ #ifdef GZIP
525
+ s->wrap == 2 ? GZIP_STATE :
526
+ #endif
527
+ INIT_STATE;
375
528
  strm->adler =
376
529
  #ifdef GZIP
377
530
  s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
378
531
  #endif
379
532
  adler32(0L, Z_NULL, 0);
380
- s->last_flush = Z_NO_FLUSH;
533
+ s->last_flush = -2;
381
534
 
382
535
  _tr_init(s);
383
- lm_init(s);
384
536
 
385
537
  return Z_OK;
386
538
  }
387
539
 
388
540
  /* ========================================================================= */
389
- int ZEXPORT deflateSetHeader (strm, head)
541
+ int ZEXPORT deflateReset(strm)
542
+ z_streamp strm;
543
+ {
544
+ int ret;
545
+
546
+ ret = deflateResetKeep(strm);
547
+ if (ret == Z_OK)
548
+ lm_init(strm->state);
549
+ return ret;
550
+ }
551
+
552
+ /* ========================================================================= */
553
+ int ZEXPORT deflateSetHeader(strm, head)
390
554
  z_streamp strm;
391
555
  gz_headerp head;
392
556
  {
393
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
394
- if (strm->state->wrap != 2) return Z_STREAM_ERROR;
557
+ if (deflateStateCheck(strm) || strm->state->wrap != 2)
558
+ return Z_STREAM_ERROR;
395
559
  strm->state->gzhead = head;
396
560
  return Z_OK;
397
561
  }
398
562
 
399
563
  /* ========================================================================= */
400
- int ZEXPORT deflatePrime (strm, bits, value)
564
+ int ZEXPORT deflatePending(strm, pending, bits)
565
+ unsigned *pending;
566
+ int *bits;
567
+ z_streamp strm;
568
+ {
569
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
570
+ if (pending != Z_NULL)
571
+ *pending = strm->state->pending;
572
+ if (bits != Z_NULL)
573
+ *bits = strm->state->bi_valid;
574
+ return Z_OK;
575
+ }
576
+
577
+ /* ========================================================================= */
578
+ int ZEXPORT deflatePrime(strm, bits, value)
401
579
  z_streamp strm;
402
580
  int bits;
403
581
  int value;
404
582
  {
405
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
406
- strm->state->bi_valid = bits;
407
- strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
583
+ deflate_state *s;
584
+ int put;
585
+
586
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
587
+ s = strm->state;
588
+ if (bits < 0 || bits > 16 ||
589
+ s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))
590
+ return Z_BUF_ERROR;
591
+ do {
592
+ put = Buf_size - s->bi_valid;
593
+ if (put > bits)
594
+ put = bits;
595
+ s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
596
+ s->bi_valid += put;
597
+ _tr_flush_bits(s);
598
+ value >>= put;
599
+ bits -= put;
600
+ } while (bits);
408
601
  return Z_OK;
409
602
  }
410
603
 
@@ -416,9 +609,8 @@ int ZEXPORT deflateParams(strm, level, strategy)
416
609
  {
417
610
  deflate_state *s;
418
611
  compress_func func;
419
- int err = Z_OK;
420
612
 
421
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
613
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
422
614
  s = strm->state;
423
615
 
424
616
  #ifdef FASTEST
@@ -432,11 +624,22 @@ int ZEXPORT deflateParams(strm, level, strategy)
432
624
  func = configuration_table[s->level].func;
433
625
 
434
626
  if ((strategy != s->strategy || func != configuration_table[level].func) &&
435
- strm->total_in != 0) {
627
+ s->last_flush != -2) {
436
628
  /* Flush the last buffer: */
437
- err = deflate(strm, Z_BLOCK);
629
+ int err = deflate(strm, Z_BLOCK);
630
+ if (err == Z_STREAM_ERROR)
631
+ return err;
632
+ if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
633
+ return Z_BUF_ERROR;
438
634
  }
439
635
  if (s->level != level) {
636
+ if (s->level == 0 && s->matches != 0) {
637
+ if (s->matches == 1)
638
+ slide_hash(s);
639
+ else
640
+ CLEAR_HASH(s);
641
+ s->matches = 0;
642
+ }
440
643
  s->level = level;
441
644
  s->max_lazy_match = configuration_table[level].max_lazy;
442
645
  s->good_match = configuration_table[level].good_length;
@@ -444,7 +647,7 @@ int ZEXPORT deflateParams(strm, level, strategy)
444
647
  s->max_chain_length = configuration_table[level].max_chain;
445
648
  }
446
649
  s->strategy = strategy;
447
- return err;
650
+ return Z_OK;
448
651
  }
449
652
 
450
653
  /* ========================================================================= */
@@ -457,47 +660,60 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
457
660
  {
458
661
  deflate_state *s;
459
662
 
460
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
663
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
461
664
  s = strm->state;
462
- s->good_match = good_length;
463
- s->max_lazy_match = max_lazy;
665
+ s->good_match = (uInt)good_length;
666
+ s->max_lazy_match = (uInt)max_lazy;
464
667
  s->nice_match = nice_length;
465
- s->max_chain_length = max_chain;
668
+ s->max_chain_length = (uInt)max_chain;
466
669
  return Z_OK;
467
670
  }
468
671
 
469
672
  /* =========================================================================
470
- * For the default windowBits of 15 and memLevel of 8, this function returns
471
- * a close to exact, as well as small, upper bound on the compressed size.
472
- * They are coded as constants here for a reason--if the #define's are
473
- * changed, then this function needs to be changed as well. The return
474
- * value for 15 and 8 only works for those exact settings.
673
+ * For the default windowBits of 15 and memLevel of 8, this function returns a
674
+ * close to exact, as well as small, upper bound on the compressed size. This
675
+ * is an expansion of ~0.03%, plus a small constant.
676
+ *
677
+ * For any setting other than those defaults for windowBits and memLevel, one
678
+ * of two worst case bounds is returned. This is at most an expansion of ~4% or
679
+ * ~13%, plus a small constant.
680
+ *
681
+ * Both the 0.03% and 4% derive from the overhead of stored blocks. The first
682
+ * one is for stored blocks of 16383 bytes (memLevel == 8), whereas the second
683
+ * is for stored blocks of 127 bytes (the worst case memLevel == 1). The
684
+ * expansion results from five bytes of header for each stored block.
475
685
  *
476
- * For any setting other than those defaults for windowBits and memLevel,
477
- * the value returned is a conservative worst case for the maximum expansion
478
- * resulting from using fixed blocks instead of stored blocks, which deflate
479
- * can emit on compressed data for some combinations of the parameters.
686
+ * The larger expansion of 13% results from a window size less than or equal to
687
+ * the symbols buffer size (windowBits <= memLevel + 7). In that case some of
688
+ * the data being compressed may have slid out of the sliding window, impeding
689
+ * a stored block from being emitted. Then the only choice is a fixed or
690
+ * dynamic block, where a fixed block limits the maximum expansion to 9 bits
691
+ * per 8-bit byte, plus 10 bits for every block. The smallest block size for
692
+ * which this can occur is 255 (memLevel == 2).
480
693
  *
481
- * This function could be more sophisticated to provide closer upper bounds for
482
- * every combination of windowBits and memLevel. But even the conservative
483
- * upper bound of about 14% expansion does not seem onerous for output buffer
484
- * allocation.
694
+ * Shifts are used to approximate divisions, for speed.
485
695
  */
486
696
  uLong ZEXPORT deflateBound(strm, sourceLen)
487
697
  z_streamp strm;
488
698
  uLong sourceLen;
489
699
  {
490
700
  deflate_state *s;
491
- uLong complen, wraplen;
492
- Bytef *str;
701
+ uLong fixedlen, storelen, wraplen;
493
702
 
494
- /* conservative upper bound for compressed data */
495
- complen = sourceLen +
496
- ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
703
+ /* upper bound for fixed blocks with 9-bit literals and length 255
704
+ (memLevel == 2, which is the lowest that may not use stored blocks) --
705
+ ~13% overhead plus a small constant */
706
+ fixedlen = sourceLen + (sourceLen >> 3) + (sourceLen >> 8) +
707
+ (sourceLen >> 9) + 4;
497
708
 
498
- /* if can't get parameters, return conservative bound plus zlib wrapper */
499
- if (strm == Z_NULL || strm->state == Z_NULL)
500
- return complen + 6;
709
+ /* upper bound for stored blocks with length 127 (memLevel == 1) --
710
+ ~4% overhead plus a small constant */
711
+ storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) +
712
+ (sourceLen >> 11) + 7;
713
+
714
+ /* if can't get parameters, return larger bound plus a zlib wrapper */
715
+ if (deflateStateCheck(strm))
716
+ return (fixedlen > storelen ? fixedlen : storelen) + 6;
501
717
 
502
718
  /* compute wrapper length */
503
719
  s = strm->state;
@@ -508,9 +724,11 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
508
724
  case 1: /* zlib wrapper */
509
725
  wraplen = 6 + (s->strstart ? 4 : 0);
510
726
  break;
727
+ #ifdef GZIP
511
728
  case 2: /* gzip wrapper */
512
729
  wraplen = 18;
513
730
  if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
731
+ Bytef *str;
514
732
  if (s->gzhead->extra != Z_NULL)
515
733
  wraplen += 2 + s->gzhead->extra_len;
516
734
  str = s->gzhead->name;
@@ -527,15 +745,17 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
527
745
  wraplen += 2;
528
746
  }
529
747
  break;
748
+ #endif
530
749
  default: /* for compiler happiness */
531
750
  wraplen = 6;
532
751
  }
533
752
 
534
- /* if not default parameters, return conservative bound */
753
+ /* if not default parameters, return one of the conservative bounds */
535
754
  if (s->w_bits != 15 || s->hash_bits != 8 + 7)
536
- return complen + wraplen;
755
+ return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen;
537
756
 
538
- /* default settings: return tight bound for that case */
757
+ /* default settings: return tight bound for that case -- ~0.03% overhead
758
+ plus a small constant */
539
759
  return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
540
760
  (sourceLen >> 25) + 13 - 6 + wraplen;
541
761
  }
@@ -545,7 +765,7 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
545
765
  * IN assertion: the stream state is correct and there is enough room in
546
766
  * pending_buf.
547
767
  */
548
- local void putShortMSB (s, b)
768
+ local void putShortMSB(s, b)
549
769
  deflate_state *s;
550
770
  uInt b;
551
771
  {
@@ -554,262 +774,276 @@ local void putShortMSB (s, b)
554
774
  }
555
775
 
556
776
  /* =========================================================================
557
- * Flush as much pending output as possible. All deflate() output goes
558
- * through this function so some applications may wish to modify it
559
- * to avoid allocating a large strm->next_out buffer and copying into it.
560
- * (See also read_buf()).
777
+ * Flush as much pending output as possible. All deflate() output, except for
778
+ * some deflate_stored() output, goes through this function so some
779
+ * applications may wish to modify it to avoid allocating a large
780
+ * strm->next_out buffer and copying into it. (See also read_buf()).
561
781
  */
562
782
  local void flush_pending(strm)
563
783
  z_streamp strm;
564
784
  {
565
- unsigned len = strm->state->pending;
785
+ unsigned len;
786
+ deflate_state *s = strm->state;
566
787
 
788
+ _tr_flush_bits(s);
789
+ len = s->pending;
567
790
  if (len > strm->avail_out) len = strm->avail_out;
568
791
  if (len == 0) return;
569
792
 
570
- zmemcpy(strm->next_out, strm->state->pending_out, len);
793
+ zmemcpy(strm->next_out, s->pending_out, len);
571
794
  strm->next_out += len;
572
- strm->state->pending_out += len;
795
+ s->pending_out += len;
573
796
  strm->total_out += len;
574
- strm->avail_out -= len;
575
- strm->state->pending -= len;
576
- if (strm->state->pending == 0) {
577
- strm->state->pending_out = strm->state->pending_buf;
797
+ strm->avail_out -= len;
798
+ s->pending -= len;
799
+ if (s->pending == 0) {
800
+ s->pending_out = s->pending_buf;
578
801
  }
579
802
  }
580
803
 
804
+ /* ===========================================================================
805
+ * Update the header CRC with the bytes s->pending_buf[beg..s->pending - 1].
806
+ */
807
+ #define HCRC_UPDATE(beg) \
808
+ do { \
809
+ if (s->gzhead->hcrc && s->pending > (beg)) \
810
+ strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
811
+ s->pending - (beg)); \
812
+ } while (0)
813
+
581
814
  /* ========================================================================= */
582
- int ZEXPORT deflate (strm, flush)
815
+ int ZEXPORT deflate(strm, flush)
583
816
  z_streamp strm;
584
817
  int flush;
585
818
  {
586
819
  int old_flush; /* value of flush param for previous deflate call */
587
820
  deflate_state *s;
588
821
 
589
- if (strm == Z_NULL || strm->state == Z_NULL ||
590
- flush > Z_BLOCK || flush < 0) {
822
+ if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
591
823
  return Z_STREAM_ERROR;
592
824
  }
593
825
  s = strm->state;
594
826
 
595
827
  if (strm->next_out == Z_NULL ||
596
- (strm->next_in == Z_NULL && strm->avail_in != 0) ||
828
+ (strm->avail_in != 0 && strm->next_in == Z_NULL) ||
597
829
  (s->status == FINISH_STATE && flush != Z_FINISH)) {
598
830
  ERR_RETURN(strm, Z_STREAM_ERROR);
599
831
  }
600
832
  if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
601
833
 
602
- s->strm = strm; /* just in case */
603
834
  old_flush = s->last_flush;
604
835
  s->last_flush = flush;
605
836
 
837
+ /* Flush as much pending output as possible */
838
+ if (s->pending != 0) {
839
+ flush_pending(strm);
840
+ if (strm->avail_out == 0) {
841
+ /* Since avail_out is 0, deflate will be called again with
842
+ * more output space, but possibly with both pending and
843
+ * avail_in equal to zero. There won't be anything to do,
844
+ * but this is not an error situation so make sure we
845
+ * return OK instead of BUF_ERROR at next call of deflate:
846
+ */
847
+ s->last_flush = -1;
848
+ return Z_OK;
849
+ }
850
+
851
+ /* Make sure there is something to do and avoid duplicate consecutive
852
+ * flushes. For repeated and useless calls with Z_FINISH, we keep
853
+ * returning Z_STREAM_END instead of Z_BUF_ERROR.
854
+ */
855
+ } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
856
+ flush != Z_FINISH) {
857
+ ERR_RETURN(strm, Z_BUF_ERROR);
858
+ }
859
+
860
+ /* User must not provide more input after the first FINISH: */
861
+ if (s->status == FINISH_STATE && strm->avail_in != 0) {
862
+ ERR_RETURN(strm, Z_BUF_ERROR);
863
+ }
864
+
606
865
  /* Write the header */
866
+ if (s->status == INIT_STATE && s->wrap == 0)
867
+ s->status = BUSY_STATE;
607
868
  if (s->status == INIT_STATE) {
608
- #ifdef GZIP
609
- if (s->wrap == 2) {
610
- strm->adler = crc32(0L, Z_NULL, 0);
611
- put_byte(s, 31);
612
- put_byte(s, 139);
613
- put_byte(s, 8);
614
- if (s->gzhead == Z_NULL) {
615
- put_byte(s, 0);
616
- put_byte(s, 0);
617
- put_byte(s, 0);
618
- put_byte(s, 0);
619
- put_byte(s, 0);
620
- put_byte(s, s->level == 9 ? 2 :
621
- (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
622
- 4 : 0));
623
- put_byte(s, OS_CODE);
624
- s->status = BUSY_STATE;
625
- }
626
- else {
627
- put_byte(s, (s->gzhead->text ? 1 : 0) +
628
- (s->gzhead->hcrc ? 2 : 0) +
629
- (s->gzhead->extra == Z_NULL ? 0 : 4) +
630
- (s->gzhead->name == Z_NULL ? 0 : 8) +
631
- (s->gzhead->comment == Z_NULL ? 0 : 16)
632
- );
633
- put_byte(s, (Byte)(s->gzhead->time & 0xff));
634
- put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
635
- put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
636
- put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
637
- put_byte(s, s->level == 9 ? 2 :
638
- (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
639
- 4 : 0));
640
- put_byte(s, s->gzhead->os & 0xff);
641
- if (s->gzhead->extra != Z_NULL) {
642
- put_byte(s, s->gzhead->extra_len & 0xff);
643
- put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
644
- }
645
- if (s->gzhead->hcrc)
646
- strm->adler = crc32(strm->adler, s->pending_buf,
647
- s->pending);
648
- s->gzindex = 0;
649
- s->status = EXTRA_STATE;
650
- }
651
- }
869
+ /* zlib header */
870
+ uInt header = (Z_DEFLATED + ((s->w_bits - 8) << 4)) << 8;
871
+ uInt level_flags;
872
+
873
+ if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
874
+ level_flags = 0;
875
+ else if (s->level < 6)
876
+ level_flags = 1;
877
+ else if (s->level == 6)
878
+ level_flags = 2;
652
879
  else
653
- #endif
654
- {
655
- uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
656
- uInt level_flags;
657
-
658
- if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
659
- level_flags = 0;
660
- else if (s->level < 6)
661
- level_flags = 1;
662
- else if (s->level == 6)
663
- level_flags = 2;
664
- else
665
- level_flags = 3;
666
- header |= (level_flags << 6);
667
- if (s->strstart != 0) header |= PRESET_DICT;
668
- header += 31 - (header % 31);
880
+ level_flags = 3;
881
+ header |= (level_flags << 6);
882
+ if (s->strstart != 0) header |= PRESET_DICT;
883
+ header += 31 - (header % 31);
669
884
 
885
+ putShortMSB(s, header);
886
+
887
+ /* Save the adler32 of the preset dictionary: */
888
+ if (s->strstart != 0) {
889
+ putShortMSB(s, (uInt)(strm->adler >> 16));
890
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
891
+ }
892
+ strm->adler = adler32(0L, Z_NULL, 0);
893
+ s->status = BUSY_STATE;
894
+
895
+ /* Compression must start with an empty pending buffer */
896
+ flush_pending(strm);
897
+ if (s->pending != 0) {
898
+ s->last_flush = -1;
899
+ return Z_OK;
900
+ }
901
+ }
902
+ #ifdef GZIP
903
+ if (s->status == GZIP_STATE) {
904
+ /* gzip header */
905
+ strm->adler = crc32(0L, Z_NULL, 0);
906
+ put_byte(s, 31);
907
+ put_byte(s, 139);
908
+ put_byte(s, 8);
909
+ if (s->gzhead == Z_NULL) {
910
+ put_byte(s, 0);
911
+ put_byte(s, 0);
912
+ put_byte(s, 0);
913
+ put_byte(s, 0);
914
+ put_byte(s, 0);
915
+ put_byte(s, s->level == 9 ? 2 :
916
+ (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
917
+ 4 : 0));
918
+ put_byte(s, OS_CODE);
670
919
  s->status = BUSY_STATE;
671
- putShortMSB(s, header);
672
920
 
673
- /* Save the adler32 of the preset dictionary: */
674
- if (s->strstart != 0) {
675
- putShortMSB(s, (uInt)(strm->adler >> 16));
676
- putShortMSB(s, (uInt)(strm->adler & 0xffff));
921
+ /* Compression must start with an empty pending buffer */
922
+ flush_pending(strm);
923
+ if (s->pending != 0) {
924
+ s->last_flush = -1;
925
+ return Z_OK;
926
+ }
927
+ }
928
+ else {
929
+ put_byte(s, (s->gzhead->text ? 1 : 0) +
930
+ (s->gzhead->hcrc ? 2 : 0) +
931
+ (s->gzhead->extra == Z_NULL ? 0 : 4) +
932
+ (s->gzhead->name == Z_NULL ? 0 : 8) +
933
+ (s->gzhead->comment == Z_NULL ? 0 : 16)
934
+ );
935
+ put_byte(s, (Byte)(s->gzhead->time & 0xff));
936
+ put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
937
+ put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
938
+ put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
939
+ put_byte(s, s->level == 9 ? 2 :
940
+ (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
941
+ 4 : 0));
942
+ put_byte(s, s->gzhead->os & 0xff);
943
+ if (s->gzhead->extra != Z_NULL) {
944
+ put_byte(s, s->gzhead->extra_len & 0xff);
945
+ put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
677
946
  }
678
- strm->adler = adler32(0L, Z_NULL, 0);
947
+ if (s->gzhead->hcrc)
948
+ strm->adler = crc32(strm->adler, s->pending_buf,
949
+ s->pending);
950
+ s->gzindex = 0;
951
+ s->status = EXTRA_STATE;
679
952
  }
680
953
  }
681
- #ifdef GZIP
682
954
  if (s->status == EXTRA_STATE) {
683
955
  if (s->gzhead->extra != Z_NULL) {
684
- uInt beg = s->pending; /* start of bytes to update crc */
685
-
686
- while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
687
- if (s->pending == s->pending_buf_size) {
688
- if (s->gzhead->hcrc && s->pending > beg)
689
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
690
- s->pending - beg);
691
- flush_pending(strm);
692
- beg = s->pending;
693
- if (s->pending == s->pending_buf_size)
694
- break;
956
+ ulg beg = s->pending; /* start of bytes to update crc */
957
+ uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex;
958
+ while (s->pending + left > s->pending_buf_size) {
959
+ uInt copy = s->pending_buf_size - s->pending;
960
+ zmemcpy(s->pending_buf + s->pending,
961
+ s->gzhead->extra + s->gzindex, copy);
962
+ s->pending = s->pending_buf_size;
963
+ HCRC_UPDATE(beg);
964
+ s->gzindex += copy;
965
+ flush_pending(strm);
966
+ if (s->pending != 0) {
967
+ s->last_flush = -1;
968
+ return Z_OK;
695
969
  }
696
- put_byte(s, s->gzhead->extra[s->gzindex]);
697
- s->gzindex++;
698
- }
699
- if (s->gzhead->hcrc && s->pending > beg)
700
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
701
- s->pending - beg);
702
- if (s->gzindex == s->gzhead->extra_len) {
703
- s->gzindex = 0;
704
- s->status = NAME_STATE;
970
+ beg = 0;
971
+ left -= copy;
705
972
  }
973
+ zmemcpy(s->pending_buf + s->pending,
974
+ s->gzhead->extra + s->gzindex, left);
975
+ s->pending += left;
976
+ HCRC_UPDATE(beg);
977
+ s->gzindex = 0;
706
978
  }
707
- else
708
- s->status = NAME_STATE;
979
+ s->status = NAME_STATE;
709
980
  }
710
981
  if (s->status == NAME_STATE) {
711
982
  if (s->gzhead->name != Z_NULL) {
712
- uInt beg = s->pending; /* start of bytes to update crc */
983
+ ulg beg = s->pending; /* start of bytes to update crc */
713
984
  int val;
714
-
715
985
  do {
716
986
  if (s->pending == s->pending_buf_size) {
717
- if (s->gzhead->hcrc && s->pending > beg)
718
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
719
- s->pending - beg);
987
+ HCRC_UPDATE(beg);
720
988
  flush_pending(strm);
721
- beg = s->pending;
722
- if (s->pending == s->pending_buf_size) {
723
- val = 1;
724
- break;
989
+ if (s->pending != 0) {
990
+ s->last_flush = -1;
991
+ return Z_OK;
725
992
  }
993
+ beg = 0;
726
994
  }
727
995
  val = s->gzhead->name[s->gzindex++];
728
996
  put_byte(s, val);
729
997
  } while (val != 0);
730
- if (s->gzhead->hcrc && s->pending > beg)
731
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
732
- s->pending - beg);
733
- if (val == 0) {
734
- s->gzindex = 0;
735
- s->status = COMMENT_STATE;
736
- }
998
+ HCRC_UPDATE(beg);
999
+ s->gzindex = 0;
737
1000
  }
738
- else
739
- s->status = COMMENT_STATE;
1001
+ s->status = COMMENT_STATE;
740
1002
  }
741
1003
  if (s->status == COMMENT_STATE) {
742
1004
  if (s->gzhead->comment != Z_NULL) {
743
- uInt beg = s->pending; /* start of bytes to update crc */
1005
+ ulg beg = s->pending; /* start of bytes to update crc */
744
1006
  int val;
745
-
746
1007
  do {
747
1008
  if (s->pending == s->pending_buf_size) {
748
- if (s->gzhead->hcrc && s->pending > beg)
749
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
750
- s->pending - beg);
1009
+ HCRC_UPDATE(beg);
751
1010
  flush_pending(strm);
752
- beg = s->pending;
753
- if (s->pending == s->pending_buf_size) {
754
- val = 1;
755
- break;
1011
+ if (s->pending != 0) {
1012
+ s->last_flush = -1;
1013
+ return Z_OK;
756
1014
  }
1015
+ beg = 0;
757
1016
  }
758
1017
  val = s->gzhead->comment[s->gzindex++];
759
1018
  put_byte(s, val);
760
1019
  } while (val != 0);
761
- if (s->gzhead->hcrc && s->pending > beg)
762
- strm->adler = crc32(strm->adler, s->pending_buf + beg,
763
- s->pending - beg);
764
- if (val == 0)
765
- s->status = HCRC_STATE;
1020
+ HCRC_UPDATE(beg);
766
1021
  }
767
- else
768
- s->status = HCRC_STATE;
1022
+ s->status = HCRC_STATE;
769
1023
  }
770
1024
  if (s->status == HCRC_STATE) {
771
1025
  if (s->gzhead->hcrc) {
772
- if (s->pending + 2 > s->pending_buf_size)
1026
+ if (s->pending + 2 > s->pending_buf_size) {
773
1027
  flush_pending(strm);
774
- if (s->pending + 2 <= s->pending_buf_size) {
775
- put_byte(s, (Byte)(strm->adler & 0xff));
776
- put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
777
- strm->adler = crc32(0L, Z_NULL, 0);
778
- s->status = BUSY_STATE;
1028
+ if (s->pending != 0) {
1029
+ s->last_flush = -1;
1030
+ return Z_OK;
1031
+ }
779
1032
  }
1033
+ put_byte(s, (Byte)(strm->adler & 0xff));
1034
+ put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
1035
+ strm->adler = crc32(0L, Z_NULL, 0);
780
1036
  }
781
- else
782
- s->status = BUSY_STATE;
783
- }
784
- #endif
1037
+ s->status = BUSY_STATE;
785
1038
 
786
- /* Flush as much pending output as possible */
787
- if (s->pending != 0) {
1039
+ /* Compression must start with an empty pending buffer */
788
1040
  flush_pending(strm);
789
- if (strm->avail_out == 0) {
790
- /* Since avail_out is 0, deflate will be called again with
791
- * more output space, but possibly with both pending and
792
- * avail_in equal to zero. There won't be anything to do,
793
- * but this is not an error situation so make sure we
794
- * return OK instead of BUF_ERROR at next call of deflate:
795
- */
1041
+ if (s->pending != 0) {
796
1042
  s->last_flush = -1;
797
1043
  return Z_OK;
798
1044
  }
799
-
800
- /* Make sure there is something to do and avoid duplicate consecutive
801
- * flushes. For repeated and useless calls with Z_FINISH, we keep
802
- * returning Z_STREAM_END instead of Z_BUF_ERROR.
803
- */
804
- } else if (strm->avail_in == 0 && flush <= old_flush &&
805
- flush != Z_FINISH) {
806
- ERR_RETURN(strm, Z_BUF_ERROR);
807
- }
808
-
809
- /* User must not provide more input after the first FINISH: */
810
- if (s->status == FINISH_STATE && strm->avail_in != 0) {
811
- ERR_RETURN(strm, Z_BUF_ERROR);
812
1045
  }
1046
+ #endif
813
1047
 
814
1048
  /* Start a new block or continue the current one.
815
1049
  */
@@ -817,9 +1051,10 @@ int ZEXPORT deflate (strm, flush)
817
1051
  (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
818
1052
  block_state bstate;
819
1053
 
820
- bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
821
- (s->strategy == Z_RLE ? deflate_rle(s, flush) :
822
- (*(configuration_table[s->level].func))(s, flush));
1054
+ bstate = s->level == 0 ? deflate_stored(s, flush) :
1055
+ s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
1056
+ s->strategy == Z_RLE ? deflate_rle(s, flush) :
1057
+ (*(configuration_table[s->level].func))(s, flush);
823
1058
 
824
1059
  if (bstate == finish_started || bstate == finish_done) {
825
1060
  s->status = FINISH_STATE;
@@ -850,6 +1085,7 @@ int ZEXPORT deflate (strm, flush)
850
1085
  if (s->lookahead == 0) {
851
1086
  s->strstart = 0;
852
1087
  s->block_start = 0L;
1088
+ s->insert = 0;
853
1089
  }
854
1090
  }
855
1091
  }
@@ -860,7 +1096,6 @@ int ZEXPORT deflate (strm, flush)
860
1096
  }
861
1097
  }
862
1098
  }
863
- Assert(strm->avail_out > 0, "bug2");
864
1099
 
865
1100
  if (flush != Z_FINISH) return Z_OK;
866
1101
  if (s->wrap <= 0) return Z_STREAM_END;
@@ -892,23 +1127,14 @@ int ZEXPORT deflate (strm, flush)
892
1127
  }
893
1128
 
894
1129
  /* ========================================================================= */
895
- int ZEXPORT deflateEnd (strm)
1130
+ int ZEXPORT deflateEnd(strm)
896
1131
  z_streamp strm;
897
1132
  {
898
1133
  int status;
899
1134
 
900
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1135
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
901
1136
 
902
1137
  status = strm->state->status;
903
- if (status != INIT_STATE &&
904
- status != EXTRA_STATE &&
905
- status != NAME_STATE &&
906
- status != COMMENT_STATE &&
907
- status != HCRC_STATE &&
908
- status != BUSY_STATE &&
909
- status != FINISH_STATE) {
910
- return Z_STREAM_ERROR;
911
- }
912
1138
 
913
1139
  /* Deallocate in reverse order of allocations: */
914
1140
  TRY_FREE(strm, strm->state->pending_buf);
@@ -927,7 +1153,7 @@ int ZEXPORT deflateEnd (strm)
927
1153
  * To simplify the source, this is not supported for 16-bit MSDOS (which
928
1154
  * doesn't have enough memory anyway to duplicate compression states).
929
1155
  */
930
- int ZEXPORT deflateCopy (dest, source)
1156
+ int ZEXPORT deflateCopy(dest, source)
931
1157
  z_streamp dest;
932
1158
  z_streamp source;
933
1159
  {
@@ -936,28 +1162,26 @@ int ZEXPORT deflateCopy (dest, source)
936
1162
  #else
937
1163
  deflate_state *ds;
938
1164
  deflate_state *ss;
939
- ushf *overlay;
940
1165
 
941
1166
 
942
- if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
1167
+ if (deflateStateCheck(source) || dest == Z_NULL) {
943
1168
  return Z_STREAM_ERROR;
944
1169
  }
945
1170
 
946
1171
  ss = source->state;
947
1172
 
948
- zmemcpy(dest, source, sizeof(z_stream));
1173
+ zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
949
1174
 
950
1175
  ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
951
1176
  if (ds == Z_NULL) return Z_MEM_ERROR;
952
1177
  dest->state = (struct internal_state FAR *) ds;
953
- zmemcpy(ds, ss, sizeof(deflate_state));
1178
+ zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
954
1179
  ds->strm = dest;
955
1180
 
956
1181
  ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
957
1182
  ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
958
1183
  ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
959
- overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
960
- ds->pending_buf = (uchf *) overlay;
1184
+ ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
961
1185
 
962
1186
  if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
963
1187
  ds->pending_buf == Z_NULL) {
@@ -966,13 +1190,12 @@ int ZEXPORT deflateCopy (dest, source)
966
1190
  }
967
1191
  /* following zmemcpy do not work for 16-bit MSDOS */
968
1192
  zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
969
- zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
970
- zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
1193
+ zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
1194
+ zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
971
1195
  zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
972
1196
 
973
1197
  ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
974
- ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
975
- ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
1198
+ ds->sym_buf = ds->pending_buf + ds->lit_bufsize;
976
1199
 
977
1200
  ds->l_desc.dyn_tree = ds->dyn_ltree;
978
1201
  ds->d_desc.dyn_tree = ds->dyn_dtree;
@@ -989,7 +1212,7 @@ int ZEXPORT deflateCopy (dest, source)
989
1212
  * allocating a large strm->next_in buffer and copying from it.
990
1213
  * (See also flush_pending()).
991
1214
  */
992
- local int read_buf(strm, buf, size)
1215
+ local unsigned read_buf(strm, buf, size)
993
1216
  z_streamp strm;
994
1217
  Bytef *buf;
995
1218
  unsigned size;
@@ -1001,25 +1224,25 @@ local int read_buf(strm, buf, size)
1001
1224
 
1002
1225
  strm->avail_in -= len;
1003
1226
 
1227
+ zmemcpy(buf, strm->next_in, len);
1004
1228
  if (strm->state->wrap == 1) {
1005
- strm->adler = adler32(strm->adler, strm->next_in, len);
1229
+ strm->adler = adler32(strm->adler, buf, len);
1006
1230
  }
1007
1231
  #ifdef GZIP
1008
1232
  else if (strm->state->wrap == 2) {
1009
- strm->adler = crc32(strm->adler, strm->next_in, len);
1233
+ strm->adler = crc32(strm->adler, buf, len);
1010
1234
  }
1011
1235
  #endif
1012
- zmemcpy(buf, strm->next_in, len);
1013
1236
  strm->next_in += len;
1014
1237
  strm->total_in += len;
1015
1238
 
1016
- return (int)len;
1239
+ return len;
1017
1240
  }
1018
1241
 
1019
1242
  /* ===========================================================================
1020
1243
  * Initialize the "longest match" routines for a new zlib stream
1021
1244
  */
1022
- local void lm_init (s)
1245
+ local void lm_init(s)
1023
1246
  deflate_state *s;
1024
1247
  {
1025
1248
  s->window_size = (ulg)2L*s->w_size;
@@ -1036,14 +1259,10 @@ local void lm_init (s)
1036
1259
  s->strstart = 0;
1037
1260
  s->block_start = 0L;
1038
1261
  s->lookahead = 0;
1262
+ s->insert = 0;
1039
1263
  s->match_length = s->prev_length = MIN_MATCH-1;
1040
1264
  s->match_available = 0;
1041
1265
  s->ins_h = 0;
1042
- #ifndef FASTEST
1043
- #ifdef ASMV
1044
- match_init(); /* initialize the asm code */
1045
- #endif
1046
- #endif
1047
1266
  }
1048
1267
 
1049
1268
  #ifndef FASTEST
@@ -1056,19 +1275,15 @@ local void lm_init (s)
1056
1275
  * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
1057
1276
  * OUT assertion: the match length is not greater than s->lookahead.
1058
1277
  */
1059
- #ifndef ASMV
1060
- /* For 80x86 and 680x0, an optimized version will be provided in match.asm or
1061
- * match.S. The code will be functionally equivalent.
1062
- */
1063
1278
  local uInt longest_match(s, cur_match)
1064
1279
  deflate_state *s;
1065
1280
  IPos cur_match; /* current match */
1066
1281
  {
1067
1282
  unsigned chain_length = s->max_chain_length;/* max hash chain length */
1068
1283
  register Bytef *scan = s->window + s->strstart; /* current string */
1069
- register Bytef *match; /* matched string */
1284
+ register Bytef *match; /* matched string */
1070
1285
  register int len; /* length of current match */
1071
- int best_len = s->prev_length; /* best match length so far */
1286
+ int best_len = (int)s->prev_length; /* best match length so far */
1072
1287
  int nice_match = s->nice_match; /* stop if match long enough */
1073
1288
  IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
1074
1289
  s->strstart - (IPos)MAX_DIST(s) : NIL;
@@ -1084,10 +1299,10 @@ local uInt longest_match(s, cur_match)
1084
1299
  */
1085
1300
  register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
1086
1301
  register ush scan_start = *(ushf*)scan;
1087
- register ush scan_end = *(ushf*)(scan+best_len-1);
1302
+ register ush scan_end = *(ushf*)(scan + best_len - 1);
1088
1303
  #else
1089
1304
  register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1090
- register Byte scan_end1 = scan[best_len-1];
1305
+ register Byte scan_end1 = scan[best_len - 1];
1091
1306
  register Byte scan_end = scan[best_len];
1092
1307
  #endif
1093
1308
 
@@ -1103,9 +1318,10 @@ local uInt longest_match(s, cur_match)
1103
1318
  /* Do not look for matches beyond the end of the input. This is necessary
1104
1319
  * to make deflate deterministic.
1105
1320
  */
1106
- if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
1321
+ if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead;
1107
1322
 
1108
- Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1323
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1324
+ "need lookahead");
1109
1325
 
1110
1326
  do {
1111
1327
  Assert(cur_match < s->strstart, "no future");
@@ -1123,43 +1339,44 @@ local uInt longest_match(s, cur_match)
1123
1339
  /* This code assumes sizeof(unsigned short) == 2. Do not use
1124
1340
  * UNALIGNED_OK if your compiler uses a different size.
1125
1341
  */
1126
- if (*(ushf*)(match+best_len-1) != scan_end ||
1342
+ if (*(ushf*)(match + best_len - 1) != scan_end ||
1127
1343
  *(ushf*)match != scan_start) continue;
1128
1344
 
1129
1345
  /* It is not necessary to compare scan[2] and match[2] since they are
1130
1346
  * always equal when the other bytes match, given that the hash keys
1131
1347
  * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
1132
- * strstart+3, +5, ... up to strstart+257. We check for insufficient
1348
+ * strstart + 3, + 5, up to strstart + 257. We check for insufficient
1133
1349
  * lookahead only every 4th comparison; the 128th check will be made
1134
- * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
1350
+ * at strstart + 257. If MAX_MATCH-2 is not a multiple of 8, it is
1135
1351
  * necessary to put more guard bytes at the end of the window, or
1136
1352
  * to check more often for insufficient lookahead.
1137
1353
  */
1138
1354
  Assert(scan[2] == match[2], "scan[2]?");
1139
1355
  scan++, match++;
1140
1356
  do {
1141
- } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1142
- *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1143
- *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1144
- *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1357
+ } while (*(ushf*)(scan += 2) == *(ushf*)(match += 2) &&
1358
+ *(ushf*)(scan += 2) == *(ushf*)(match += 2) &&
1359
+ *(ushf*)(scan += 2) == *(ushf*)(match += 2) &&
1360
+ *(ushf*)(scan += 2) == *(ushf*)(match += 2) &&
1145
1361
  scan < strend);
1146
1362
  /* The funny "do {}" generates better code on most compilers */
1147
1363
 
1148
- /* Here, scan <= window+strstart+257 */
1149
- Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1364
+ /* Here, scan <= window + strstart + 257 */
1365
+ Assert(scan <= s->window + (unsigned)(s->window_size - 1),
1366
+ "wild scan");
1150
1367
  if (*scan == *match) scan++;
1151
1368
 
1152
- len = (MAX_MATCH - 1) - (int)(strend-scan);
1369
+ len = (MAX_MATCH - 1) - (int)(strend - scan);
1153
1370
  scan = strend - (MAX_MATCH-1);
1154
1371
 
1155
1372
  #else /* UNALIGNED_OK */
1156
1373
 
1157
- if (match[best_len] != scan_end ||
1158
- match[best_len-1] != scan_end1 ||
1159
- *match != *scan ||
1160
- *++match != scan[1]) continue;
1374
+ if (match[best_len] != scan_end ||
1375
+ match[best_len - 1] != scan_end1 ||
1376
+ *match != *scan ||
1377
+ *++match != scan[1]) continue;
1161
1378
 
1162
- /* The check at best_len-1 can be removed because it will be made
1379
+ /* The check at best_len - 1 can be removed because it will be made
1163
1380
  * again later. (This heuristic is not always a win.)
1164
1381
  * It is not necessary to compare scan[2] and match[2] since they
1165
1382
  * are always equal when the other bytes match, given that
@@ -1169,7 +1386,7 @@ local uInt longest_match(s, cur_match)
1169
1386
  Assert(*scan == *match, "match[2]?");
1170
1387
 
1171
1388
  /* We check for insufficient lookahead only every 8th comparison;
1172
- * the 256th check will be made at strstart+258.
1389
+ * the 256th check will be made at strstart + 258.
1173
1390
  */
1174
1391
  do {
1175
1392
  } while (*++scan == *++match && *++scan == *++match &&
@@ -1178,7 +1395,8 @@ local uInt longest_match(s, cur_match)
1178
1395
  *++scan == *++match && *++scan == *++match &&
1179
1396
  scan < strend);
1180
1397
 
1181
- Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1398
+ Assert(scan <= s->window + (unsigned)(s->window_size - 1),
1399
+ "wild scan");
1182
1400
 
1183
1401
  len = MAX_MATCH - (int)(strend - scan);
1184
1402
  scan = strend - MAX_MATCH;
@@ -1190,9 +1408,9 @@ local uInt longest_match(s, cur_match)
1190
1408
  best_len = len;
1191
1409
  if (len >= nice_match) break;
1192
1410
  #ifdef UNALIGNED_OK
1193
- scan_end = *(ushf*)(scan+best_len-1);
1411
+ scan_end = *(ushf*)(scan + best_len - 1);
1194
1412
  #else
1195
- scan_end1 = scan[best_len-1];
1413
+ scan_end1 = scan[best_len - 1];
1196
1414
  scan_end = scan[best_len];
1197
1415
  #endif
1198
1416
  }
@@ -1202,7 +1420,6 @@ local uInt longest_match(s, cur_match)
1202
1420
  if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
1203
1421
  return s->lookahead;
1204
1422
  }
1205
- #endif /* ASMV */
1206
1423
 
1207
1424
  #else /* FASTEST */
1208
1425
 
@@ -1223,7 +1440,8 @@ local uInt longest_match(s, cur_match)
1223
1440
  */
1224
1441
  Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1225
1442
 
1226
- Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1443
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1444
+ "need lookahead");
1227
1445
 
1228
1446
  Assert(cur_match < s->strstart, "no future");
1229
1447
 
@@ -1233,7 +1451,7 @@ local uInt longest_match(s, cur_match)
1233
1451
  */
1234
1452
  if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
1235
1453
 
1236
- /* The check at best_len-1 can be removed because it will be made
1454
+ /* The check at best_len - 1 can be removed because it will be made
1237
1455
  * again later. (This heuristic is not always a win.)
1238
1456
  * It is not necessary to compare scan[2] and match[2] since they
1239
1457
  * are always equal when the other bytes match, given that
@@ -1243,7 +1461,7 @@ local uInt longest_match(s, cur_match)
1243
1461
  Assert(*scan == *match, "match[2]?");
1244
1462
 
1245
1463
  /* We check for insufficient lookahead only every 8th comparison;
1246
- * the 256th check will be made at strstart+258.
1464
+ * the 256th check will be made at strstart + 258.
1247
1465
  */
1248
1466
  do {
1249
1467
  } while (*++scan == *++match && *++scan == *++match &&
@@ -1252,7 +1470,7 @@ local uInt longest_match(s, cur_match)
1252
1470
  *++scan == *++match && *++scan == *++match &&
1253
1471
  scan < strend);
1254
1472
 
1255
- Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1473
+ Assert(scan <= s->window + (unsigned)(s->window_size - 1), "wild scan");
1256
1474
 
1257
1475
  len = MAX_MATCH - (int)(strend - scan);
1258
1476
 
@@ -1264,7 +1482,11 @@ local uInt longest_match(s, cur_match)
1264
1482
 
1265
1483
  #endif /* FASTEST */
1266
1484
 
1267
- #ifdef DEBUG
1485
+ #ifdef ZLIB_DEBUG
1486
+
1487
+ #define EQUAL 0
1488
+ /* result of memcmp for equal strings */
1489
+
1268
1490
  /* ===========================================================================
1269
1491
  * Check that the match at match_start is indeed a match.
1270
1492
  */
@@ -1284,13 +1506,13 @@ local void check_match(s, start, match, length)
1284
1506
  z_error("invalid match");
1285
1507
  }
1286
1508
  if (z_verbose > 1) {
1287
- fprintf(stderr,"\\[%d,%d]", start-match, length);
1509
+ fprintf(stderr,"\\[%d,%d]", start - match, length);
1288
1510
  do { putc(s->window[start++], stderr); } while (--length != 0);
1289
1511
  }
1290
1512
  }
1291
1513
  #else
1292
1514
  # define check_match(s, start, match, length)
1293
- #endif /* DEBUG */
1515
+ #endif /* ZLIB_DEBUG */
1294
1516
 
1295
1517
  /* ===========================================================================
1296
1518
  * Fill the window when the lookahead becomes insufficient.
@@ -1305,11 +1527,12 @@ local void check_match(s, start, match, length)
1305
1527
  local void fill_window(s)
1306
1528
  deflate_state *s;
1307
1529
  {
1308
- register unsigned n, m;
1309
- register Posf *p;
1530
+ unsigned n;
1310
1531
  unsigned more; /* Amount of free space at the end of the window. */
1311
1532
  uInt wsize = s->w_size;
1312
1533
 
1534
+ Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
1535
+
1313
1536
  do {
1314
1537
  more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1315
1538
 
@@ -1329,40 +1552,18 @@ local void fill_window(s)
1329
1552
  /* If the window is almost full and there is insufficient lookahead,
1330
1553
  * move the upper half to the lower one to make room in the upper half.
1331
1554
  */
1332
- if (s->strstart >= wsize+MAX_DIST(s)) {
1555
+ if (s->strstart >= wsize + MAX_DIST(s)) {
1333
1556
 
1334
- zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
1557
+ zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
1335
1558
  s->match_start -= wsize;
1336
1559
  s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1337
1560
  s->block_start -= (long) wsize;
1338
-
1339
- /* Slide the hash table (could be avoided with 32 bit values
1340
- at the expense of memory usage). We slide even when level == 0
1341
- to keep the hash table consistent if we switch back to level > 0
1342
- later. (Using level 0 permanently is not an optimal usage of
1343
- zlib, so we don't care about this pathological case.)
1344
- */
1345
- n = s->hash_size;
1346
- p = &s->head[n];
1347
- do {
1348
- m = *--p;
1349
- *p = (Pos)(m >= wsize ? m-wsize : NIL);
1350
- } while (--n);
1351
-
1352
- n = wsize;
1353
- #ifndef FASTEST
1354
- p = &s->prev[n];
1355
- do {
1356
- m = *--p;
1357
- *p = (Pos)(m >= wsize ? m-wsize : NIL);
1358
- /* If n is not on any hash chain, prev[n] is garbage but
1359
- * its value will never be used.
1360
- */
1361
- } while (--n);
1362
- #endif
1561
+ if (s->insert > s->strstart)
1562
+ s->insert = s->strstart;
1563
+ slide_hash(s);
1363
1564
  more += wsize;
1364
1565
  }
1365
- if (s->strm->avail_in == 0) return;
1566
+ if (s->strm->avail_in == 0) break;
1366
1567
 
1367
1568
  /* If there was no sliding:
1368
1569
  * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
@@ -1381,12 +1582,24 @@ local void fill_window(s)
1381
1582
  s->lookahead += n;
1382
1583
 
1383
1584
  /* Initialize the hash value now that we have some input: */
1384
- if (s->lookahead >= MIN_MATCH) {
1385
- s->ins_h = s->window[s->strstart];
1386
- UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
1585
+ if (s->lookahead + s->insert >= MIN_MATCH) {
1586
+ uInt str = s->strstart - s->insert;
1587
+ s->ins_h = s->window[str];
1588
+ UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
1387
1589
  #if MIN_MATCH != 3
1388
1590
  Call UPDATE_HASH() MIN_MATCH-3 more times
1389
1591
  #endif
1592
+ while (s->insert) {
1593
+ UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
1594
+ #ifndef FASTEST
1595
+ s->prev[str & s->w_mask] = s->head[s->ins_h];
1596
+ #endif
1597
+ s->head[s->ins_h] = (Pos)str;
1598
+ str++;
1599
+ s->insert--;
1600
+ if (s->lookahead + s->insert < MIN_MATCH)
1601
+ break;
1602
+ }
1390
1603
  }
1391
1604
  /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
1392
1605
  * but this is not important since only literal bytes will be emitted.
@@ -1427,6 +1640,9 @@ local void fill_window(s)
1427
1640
  s->high_water += init;
1428
1641
  }
1429
1642
  }
1643
+
1644
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1645
+ "not enough room for search");
1430
1646
  }
1431
1647
 
1432
1648
  /* ===========================================================================
@@ -1450,64 +1666,205 @@ local void fill_window(s)
1450
1666
  if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
1451
1667
  }
1452
1668
 
1669
+ /* Maximum stored block length in deflate format (not including header). */
1670
+ #define MAX_STORED 65535
1671
+
1672
+ /* Minimum of a and b. */
1673
+ #define MIN(a, b) ((a) > (b) ? (b) : (a))
1674
+
1453
1675
  /* ===========================================================================
1454
1676
  * Copy without compression as much as possible from the input stream, return
1455
1677
  * the current block state.
1456
- * This function does not insert new strings in the dictionary since
1457
- * uncompressible data is probably not useful. This function is used
1458
- * only for the level=0 compression option.
1459
- * NOTE: this function should be optimized to avoid extra copying from
1460
- * window to pending_buf.
1678
+ *
1679
+ * In case deflateParams() is used to later switch to a non-zero compression
1680
+ * level, s->matches (otherwise unused when storing) keeps track of the number
1681
+ * of hash table slides to perform. If s->matches is 1, then one hash table
1682
+ * slide will be done when switching. If s->matches is 2, the maximum value
1683
+ * allowed here, then the hash table will be cleared, since two or more slides
1684
+ * is the same as a clear.
1685
+ *
1686
+ * deflate_stored() is written to minimize the number of times an input byte is
1687
+ * copied. It is most efficient with large input and output buffers, which
1688
+ * maximizes the opportunities to have a single copy from next_in to next_out.
1461
1689
  */
1462
1690
  local block_state deflate_stored(s, flush)
1463
1691
  deflate_state *s;
1464
1692
  int flush;
1465
1693
  {
1466
- /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
1467
- * to pending_buf_size, and each stored block has a 5 byte header:
1694
+ /* Smallest worthy block size when not flushing or finishing. By default
1695
+ * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
1696
+ * large input and output buffers, the stored block size will be larger.
1468
1697
  */
1469
- ulg max_block_size = 0xffff;
1470
- ulg max_start;
1471
-
1472
- if (max_block_size > s->pending_buf_size - 5) {
1473
- max_block_size = s->pending_buf_size - 5;
1474
- }
1475
-
1476
- /* Copy as much as possible from input to output: */
1477
- for (;;) {
1478
- /* Fill the window as much as possible: */
1479
- if (s->lookahead <= 1) {
1698
+ unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
1480
1699
 
1481
- Assert(s->strstart < s->w_size+MAX_DIST(s) ||
1482
- s->block_start >= (long)s->w_size, "slide too late");
1700
+ /* Copy as many min_block or larger stored blocks directly to next_out as
1701
+ * possible. If flushing, copy the remaining available input to next_out as
1702
+ * stored blocks, if there is enough space.
1703
+ */
1704
+ unsigned len, left, have, last = 0;
1705
+ unsigned used = s->strm->avail_in;
1706
+ do {
1707
+ /* Set len to the maximum size block that we can copy directly with the
1708
+ * available input data and output space. Set left to how much of that
1709
+ * would be copied from what's left in the window.
1710
+ */
1711
+ len = MAX_STORED; /* maximum deflate stored block length */
1712
+ have = (s->bi_valid + 42) >> 3; /* number of header bytes */
1713
+ if (s->strm->avail_out < have) /* need room for header */
1714
+ break;
1715
+ /* maximum stored block length that will fit in avail_out: */
1716
+ have = s->strm->avail_out - have;
1717
+ left = s->strstart - s->block_start; /* bytes left in window */
1718
+ if (len > (ulg)left + s->strm->avail_in)
1719
+ len = left + s->strm->avail_in; /* limit len to the input */
1720
+ if (len > have)
1721
+ len = have; /* limit len to the output */
1722
+
1723
+ /* If the stored block would be less than min_block in length, or if
1724
+ * unable to copy all of the available input when flushing, then try
1725
+ * copying to the window and the pending buffer instead. Also don't
1726
+ * write an empty block when flushing -- deflate() does that.
1727
+ */
1728
+ if (len < min_block && ((len == 0 && flush != Z_FINISH) ||
1729
+ flush == Z_NO_FLUSH ||
1730
+ len != left + s->strm->avail_in))
1731
+ break;
1483
1732
 
1484
- fill_window(s);
1485
- if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
1733
+ /* Make a dummy stored block in pending to get the header bytes,
1734
+ * including any pending bits. This also updates the debugging counts.
1735
+ */
1736
+ last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
1737
+ _tr_stored_block(s, (char *)0, 0L, last);
1738
+
1739
+ /* Replace the lengths in the dummy stored block with len. */
1740
+ s->pending_buf[s->pending - 4] = len;
1741
+ s->pending_buf[s->pending - 3] = len >> 8;
1742
+ s->pending_buf[s->pending - 2] = ~len;
1743
+ s->pending_buf[s->pending - 1] = ~len >> 8;
1744
+
1745
+ /* Write the stored block header bytes. */
1746
+ flush_pending(s->strm);
1747
+
1748
+ #ifdef ZLIB_DEBUG
1749
+ /* Update debugging counts for the data about to be copied. */
1750
+ s->compressed_len += len << 3;
1751
+ s->bits_sent += len << 3;
1752
+ #endif
1486
1753
 
1487
- if (s->lookahead == 0) break; /* flush the current block */
1754
+ /* Copy uncompressed bytes from the window to next_out. */
1755
+ if (left) {
1756
+ if (left > len)
1757
+ left = len;
1758
+ zmemcpy(s->strm->next_out, s->window + s->block_start, left);
1759
+ s->strm->next_out += left;
1760
+ s->strm->avail_out -= left;
1761
+ s->strm->total_out += left;
1762
+ s->block_start += left;
1763
+ len -= left;
1488
1764
  }
1489
- Assert(s->block_start >= 0L, "block gone");
1490
-
1491
- s->strstart += s->lookahead;
1492
- s->lookahead = 0;
1493
-
1494
- /* Emit a stored block if pending_buf will be full: */
1495
- max_start = s->block_start + max_block_size;
1496
- if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
1497
- /* strstart == 0 is possible when wraparound on 16-bit machine */
1498
- s->lookahead = (uInt)(s->strstart - max_start);
1499
- s->strstart = (uInt)max_start;
1500
- FLUSH_BLOCK(s, 0);
1765
+
1766
+ /* Copy uncompressed bytes directly from next_in to next_out, updating
1767
+ * the check value.
1768
+ */
1769
+ if (len) {
1770
+ read_buf(s->strm, s->strm->next_out, len);
1771
+ s->strm->next_out += len;
1772
+ s->strm->avail_out -= len;
1773
+ s->strm->total_out += len;
1501
1774
  }
1502
- /* Flush if we may have to slide, otherwise block_start may become
1503
- * negative and the data will be gone:
1775
+ } while (last == 0);
1776
+
1777
+ /* Update the sliding window with the last s->w_size bytes of the copied
1778
+ * data, or append all of the copied data to the existing window if less
1779
+ * than s->w_size bytes were copied. Also update the number of bytes to
1780
+ * insert in the hash tables, in the event that deflateParams() switches to
1781
+ * a non-zero compression level.
1782
+ */
1783
+ used -= s->strm->avail_in; /* number of input bytes directly copied */
1784
+ if (used) {
1785
+ /* If any input was used, then no unused input remains in the window,
1786
+ * therefore s->block_start == s->strstart.
1504
1787
  */
1505
- if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
1506
- FLUSH_BLOCK(s, 0);
1788
+ if (used >= s->w_size) { /* supplant the previous history */
1789
+ s->matches = 2; /* clear hash */
1790
+ zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
1791
+ s->strstart = s->w_size;
1792
+ s->insert = s->strstart;
1793
+ }
1794
+ else {
1795
+ if (s->window_size - s->strstart <= used) {
1796
+ /* Slide the window down. */
1797
+ s->strstart -= s->w_size;
1798
+ zmemcpy(s->window, s->window + s->w_size, s->strstart);
1799
+ if (s->matches < 2)
1800
+ s->matches++; /* add a pending slide_hash() */
1801
+ if (s->insert > s->strstart)
1802
+ s->insert = s->strstart;
1803
+ }
1804
+ zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
1805
+ s->strstart += used;
1806
+ s->insert += MIN(used, s->w_size - s->insert);
1507
1807
  }
1808
+ s->block_start = s->strstart;
1809
+ }
1810
+ if (s->high_water < s->strstart)
1811
+ s->high_water = s->strstart;
1812
+
1813
+ /* If the last block was written to next_out, then done. */
1814
+ if (last)
1815
+ return finish_done;
1816
+
1817
+ /* If flushing and all input has been consumed, then done. */
1818
+ if (flush != Z_NO_FLUSH && flush != Z_FINISH &&
1819
+ s->strm->avail_in == 0 && (long)s->strstart == s->block_start)
1820
+ return block_done;
1821
+
1822
+ /* Fill the window with any remaining input. */
1823
+ have = s->window_size - s->strstart;
1824
+ if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) {
1825
+ /* Slide the window down. */
1826
+ s->block_start -= s->w_size;
1827
+ s->strstart -= s->w_size;
1828
+ zmemcpy(s->window, s->window + s->w_size, s->strstart);
1829
+ if (s->matches < 2)
1830
+ s->matches++; /* add a pending slide_hash() */
1831
+ have += s->w_size; /* more space now */
1832
+ if (s->insert > s->strstart)
1833
+ s->insert = s->strstart;
1834
+ }
1835
+ if (have > s->strm->avail_in)
1836
+ have = s->strm->avail_in;
1837
+ if (have) {
1838
+ read_buf(s->strm, s->window + s->strstart, have);
1839
+ s->strstart += have;
1840
+ s->insert += MIN(have, s->w_size - s->insert);
1841
+ }
1842
+ if (s->high_water < s->strstart)
1843
+ s->high_water = s->strstart;
1844
+
1845
+ /* There was not enough avail_out to write a complete worthy or flushed
1846
+ * stored block to next_out. Write a stored block to pending instead, if we
1847
+ * have enough input for a worthy block, or if flushing and there is enough
1848
+ * room for the remaining input as a stored block in the pending buffer.
1849
+ */
1850
+ have = (s->bi_valid + 42) >> 3; /* number of header bytes */
1851
+ /* maximum stored block length that will fit in pending: */
1852
+ have = MIN(s->pending_buf_size - have, MAX_STORED);
1853
+ min_block = MIN(have, s->w_size);
1854
+ left = s->strstart - s->block_start;
1855
+ if (left >= min_block ||
1856
+ ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH &&
1857
+ s->strm->avail_in == 0 && left <= have)) {
1858
+ len = MIN(left, have);
1859
+ last = flush == Z_FINISH && s->strm->avail_in == 0 &&
1860
+ len == left ? 1 : 0;
1861
+ _tr_stored_block(s, (charf *)s->window + s->block_start, len, last);
1862
+ s->block_start += len;
1863
+ flush_pending(s->strm);
1508
1864
  }
1509
- FLUSH_BLOCK(s, flush == Z_FINISH);
1510
- return flush == Z_FINISH ? finish_done : block_done;
1865
+
1866
+ /* We've done all we can with the available input and output. */
1867
+ return last ? finish_started : need_more;
1511
1868
  }
1512
1869
 
1513
1870
  /* ===========================================================================
@@ -1538,7 +1895,7 @@ local block_state deflate_fast(s, flush)
1538
1895
  if (s->lookahead == 0) break; /* flush the current block */
1539
1896
  }
1540
1897
 
1541
- /* Insert the string window[strstart .. strstart+2] in the
1898
+ /* Insert the string window[strstart .. strstart + 2] in the
1542
1899
  * dictionary, and set hash_head to the head of the hash chain:
1543
1900
  */
1544
1901
  hash_head = NIL;
@@ -1586,7 +1943,7 @@ local block_state deflate_fast(s, flush)
1586
1943
  s->strstart += s->match_length;
1587
1944
  s->match_length = 0;
1588
1945
  s->ins_h = s->window[s->strstart];
1589
- UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
1946
+ UPDATE_HASH(s, s->ins_h, s->window[s->strstart + 1]);
1590
1947
  #if MIN_MATCH != 3
1591
1948
  Call UPDATE_HASH() MIN_MATCH-3 more times
1592
1949
  #endif
@@ -1597,14 +1954,20 @@ local block_state deflate_fast(s, flush)
1597
1954
  } else {
1598
1955
  /* No match, output a literal byte */
1599
1956
  Tracevv((stderr,"%c", s->window[s->strstart]));
1600
- _tr_tally_lit (s, s->window[s->strstart], bflush);
1957
+ _tr_tally_lit(s, s->window[s->strstart], bflush);
1601
1958
  s->lookahead--;
1602
1959
  s->strstart++;
1603
1960
  }
1604
1961
  if (bflush) FLUSH_BLOCK(s, 0);
1605
1962
  }
1606
- FLUSH_BLOCK(s, flush == Z_FINISH);
1607
- return flush == Z_FINISH ? finish_done : block_done;
1963
+ s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
1964
+ if (flush == Z_FINISH) {
1965
+ FLUSH_BLOCK(s, 1);
1966
+ return finish_done;
1967
+ }
1968
+ if (s->sym_next)
1969
+ FLUSH_BLOCK(s, 0);
1970
+ return block_done;
1608
1971
  }
1609
1972
 
1610
1973
  #ifndef FASTEST
@@ -1635,7 +1998,7 @@ local block_state deflate_slow(s, flush)
1635
1998
  if (s->lookahead == 0) break; /* flush the current block */
1636
1999
  }
1637
2000
 
1638
- /* Insert the string window[strstart .. strstart+2] in the
2001
+ /* Insert the string window[strstart .. strstart + 2] in the
1639
2002
  * dictionary, and set hash_head to the head of the hash chain:
1640
2003
  */
1641
2004
  hash_head = NIL;
@@ -1677,17 +2040,17 @@ local block_state deflate_slow(s, flush)
1677
2040
  uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
1678
2041
  /* Do not insert strings in hash table beyond this. */
1679
2042
 
1680
- check_match(s, s->strstart-1, s->prev_match, s->prev_length);
2043
+ check_match(s, s->strstart - 1, s->prev_match, s->prev_length);
1681
2044
 
1682
- _tr_tally_dist(s, s->strstart -1 - s->prev_match,
2045
+ _tr_tally_dist(s, s->strstart - 1 - s->prev_match,
1683
2046
  s->prev_length - MIN_MATCH, bflush);
1684
2047
 
1685
2048
  /* Insert in hash table all strings up to the end of the match.
1686
- * strstart-1 and strstart are already inserted. If there is not
2049
+ * strstart - 1 and strstart are already inserted. If there is not
1687
2050
  * enough lookahead, the last two strings are not inserted in
1688
2051
  * the hash table.
1689
2052
  */
1690
- s->lookahead -= s->prev_length-1;
2053
+ s->lookahead -= s->prev_length - 1;
1691
2054
  s->prev_length -= 2;
1692
2055
  do {
1693
2056
  if (++s->strstart <= max_insert) {
@@ -1705,8 +2068,8 @@ local block_state deflate_slow(s, flush)
1705
2068
  * single literal. If there was a match but the current match
1706
2069
  * is longer, truncate the previous match to a single literal.
1707
2070
  */
1708
- Tracevv((stderr,"%c", s->window[s->strstart-1]));
1709
- _tr_tally_lit(s, s->window[s->strstart-1], bflush);
2071
+ Tracevv((stderr,"%c", s->window[s->strstart - 1]));
2072
+ _tr_tally_lit(s, s->window[s->strstart - 1], bflush);
1710
2073
  if (bflush) {
1711
2074
  FLUSH_BLOCK_ONLY(s, 0);
1712
2075
  }
@@ -1724,12 +2087,18 @@ local block_state deflate_slow(s, flush)
1724
2087
  }
1725
2088
  Assert (flush != Z_NO_FLUSH, "no flush?");
1726
2089
  if (s->match_available) {
1727
- Tracevv((stderr,"%c", s->window[s->strstart-1]));
1728
- _tr_tally_lit(s, s->window[s->strstart-1], bflush);
2090
+ Tracevv((stderr,"%c", s->window[s->strstart - 1]));
2091
+ _tr_tally_lit(s, s->window[s->strstart - 1], bflush);
1729
2092
  s->match_available = 0;
1730
2093
  }
1731
- FLUSH_BLOCK(s, flush == Z_FINISH);
1732
- return flush == Z_FINISH ? finish_done : block_done;
2094
+ s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
2095
+ if (flush == Z_FINISH) {
2096
+ FLUSH_BLOCK(s, 1);
2097
+ return finish_done;
2098
+ }
2099
+ if (s->sym_next)
2100
+ FLUSH_BLOCK(s, 0);
2101
+ return block_done;
1733
2102
  }
1734
2103
  #endif /* FASTEST */
1735
2104
 
@@ -1749,11 +2118,11 @@ local block_state deflate_rle(s, flush)
1749
2118
  for (;;) {
1750
2119
  /* Make sure that we always have enough lookahead, except
1751
2120
  * at the end of the input file. We need MAX_MATCH bytes
1752
- * for the longest encodable run.
2121
+ * for the longest run, plus one for the unrolled loop.
1753
2122
  */
1754
- if (s->lookahead < MAX_MATCH) {
2123
+ if (s->lookahead <= MAX_MATCH) {
1755
2124
  fill_window(s);
1756
- if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
2125
+ if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
1757
2126
  return need_more;
1758
2127
  }
1759
2128
  if (s->lookahead == 0) break; /* flush the current block */
@@ -1772,10 +2141,12 @@ local block_state deflate_rle(s, flush)
1772
2141
  prev == *++scan && prev == *++scan &&
1773
2142
  prev == *++scan && prev == *++scan &&
1774
2143
  scan < strend);
1775
- s->match_length = MAX_MATCH - (int)(strend - scan);
2144
+ s->match_length = MAX_MATCH - (uInt)(strend - scan);
1776
2145
  if (s->match_length > s->lookahead)
1777
2146
  s->match_length = s->lookahead;
1778
2147
  }
2148
+ Assert(scan <= s->window + (uInt)(s->window_size - 1),
2149
+ "wild scan");
1779
2150
  }
1780
2151
 
1781
2152
  /* Emit match if have run of MIN_MATCH or longer, else emit literal */
@@ -1790,14 +2161,20 @@ local block_state deflate_rle(s, flush)
1790
2161
  } else {
1791
2162
  /* No match, output a literal byte */
1792
2163
  Tracevv((stderr,"%c", s->window[s->strstart]));
1793
- _tr_tally_lit (s, s->window[s->strstart], bflush);
2164
+ _tr_tally_lit(s, s->window[s->strstart], bflush);
1794
2165
  s->lookahead--;
1795
2166
  s->strstart++;
1796
2167
  }
1797
2168
  if (bflush) FLUSH_BLOCK(s, 0);
1798
2169
  }
1799
- FLUSH_BLOCK(s, flush == Z_FINISH);
1800
- return flush == Z_FINISH ? finish_done : block_done;
2170
+ s->insert = 0;
2171
+ if (flush == Z_FINISH) {
2172
+ FLUSH_BLOCK(s, 1);
2173
+ return finish_done;
2174
+ }
2175
+ if (s->sym_next)
2176
+ FLUSH_BLOCK(s, 0);
2177
+ return block_done;
1801
2178
  }
1802
2179
 
1803
2180
  /* ===========================================================================
@@ -1824,11 +2201,17 @@ local block_state deflate_huff(s, flush)
1824
2201
  /* Output a literal byte */
1825
2202
  s->match_length = 0;
1826
2203
  Tracevv((stderr,"%c", s->window[s->strstart]));
1827
- _tr_tally_lit (s, s->window[s->strstart], bflush);
2204
+ _tr_tally_lit(s, s->window[s->strstart], bflush);
1828
2205
  s->lookahead--;
1829
2206
  s->strstart++;
1830
2207
  if (bflush) FLUSH_BLOCK(s, 0);
1831
2208
  }
1832
- FLUSH_BLOCK(s, flush == Z_FINISH);
1833
- return flush == Z_FINISH ? finish_done : block_done;
2209
+ s->insert = 0;
2210
+ if (flush == Z_FINISH) {
2211
+ FLUSH_BLOCK(s, 1);
2212
+ return finish_done;
2213
+ }
2214
+ if (s->sym_next)
2215
+ FLUSH_BLOCK(s, 0);
2216
+ return block_done;
1834
2217
  }