multi_compress 0.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 (219) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +13 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +116 -0
  5. data/ext/multi_compress/extconf.rb +171 -0
  6. data/ext/multi_compress/multi_compress.c +1534 -0
  7. data/ext/multi_compress/vendor/brotli/c/common/constants.c +15 -0
  8. data/ext/multi_compress/vendor/brotli/c/common/constants.h +201 -0
  9. data/ext/multi_compress/vendor/brotli/c/common/context.c +156 -0
  10. data/ext/multi_compress/vendor/brotli/c/common/context.h +113 -0
  11. data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +5916 -0
  12. data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +64 -0
  13. data/ext/multi_compress/vendor/brotli/c/common/platform.c +23 -0
  14. data/ext/multi_compress/vendor/brotli/c/common/platform.h +541 -0
  15. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +521 -0
  16. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +75 -0
  17. data/ext/multi_compress/vendor/brotli/c/common/transform.c +291 -0
  18. data/ext/multi_compress/vendor/brotli/c/common/transform.h +85 -0
  19. data/ext/multi_compress/vendor/brotli/c/common/version.h +51 -0
  20. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +78 -0
  21. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +423 -0
  22. data/ext/multi_compress/vendor/brotli/c/dec/decode.c +2875 -0
  23. data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +342 -0
  24. data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +122 -0
  25. data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +733 -0
  26. data/ext/multi_compress/vendor/brotli/c/dec/state.c +183 -0
  27. data/ext/multi_compress/vendor/brotli/c/dec/state.h +400 -0
  28. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +207 -0
  29. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +40 -0
  30. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +939 -0
  31. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +96 -0
  32. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_inc.h +189 -0
  33. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +36 -0
  34. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +64 -0
  35. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +127 -0
  36. data/ext/multi_compress/vendor/brotli/c/enc/block_encoder_inc.h +34 -0
  37. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +217 -0
  38. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +52 -0
  39. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +481 -0
  40. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +1336 -0
  41. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +89 -0
  42. data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +57 -0
  43. data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +49 -0
  44. data/ext/multi_compress/vendor/brotli/c/enc/cluster_inc.h +325 -0
  45. data/ext/multi_compress/vendor/brotli/c/enc/command.c +28 -0
  46. data/ext/multi_compress/vendor/brotli/c/enc/command.h +191 -0
  47. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +207 -0
  48. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +74 -0
  49. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +800 -0
  50. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +86 -0
  51. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +657 -0
  52. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +72 -0
  53. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +1848 -0
  54. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +25 -0
  55. data/ext/multi_compress/vendor/brotli/c/enc/encode.c +1996 -0
  56. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +640 -0
  57. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +157 -0
  58. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +504 -0
  59. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +123 -0
  60. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +542 -0
  61. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +105 -0
  62. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +67 -0
  63. data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +72 -0
  64. data/ext/multi_compress/vendor/brotli/c/enc/hash.h +728 -0
  65. data/ext/multi_compress/vendor/brotli/c/enc/hash_composite_inc.h +140 -0
  66. data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +295 -0
  67. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +262 -0
  68. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +258 -0
  69. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +266 -0
  70. data/ext/multi_compress/vendor/brotli/c/enc/hash_rolling_inc.h +212 -0
  71. data/ext/multi_compress/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +330 -0
  72. data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +100 -0
  73. data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +64 -0
  74. data/ext/multi_compress/vendor/brotli/c/enc/histogram_inc.h +51 -0
  75. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +180 -0
  76. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +32 -0
  77. data/ext/multi_compress/vendor/brotli/c/enc/memory.c +194 -0
  78. data/ext/multi_compress/vendor/brotli/c/enc/memory.h +131 -0
  79. data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +677 -0
  80. data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +106 -0
  81. data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +185 -0
  82. data/ext/multi_compress/vendor/brotli/c/enc/params.h +47 -0
  83. data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +54 -0
  84. data/ext/multi_compress/vendor/brotli/c/enc/quality.h +202 -0
  85. data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +168 -0
  86. data/ext/multi_compress/vendor/brotli/c/enc/state.h +104 -0
  87. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +542 -0
  88. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +41 -0
  89. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +5866 -0
  90. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +85 -0
  91. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +33 -0
  92. data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +88 -0
  93. data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +409 -0
  94. data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +501 -0
  95. data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +305 -0
  96. data/ext/multi_compress/vendor/brotli/c/include/brotli/shared_dictionary.h +100 -0
  97. data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +83 -0
  98. data/ext/multi_compress/vendor/lz4/lib/LICENSE +24 -0
  99. data/ext/multi_compress/vendor/lz4/lib/Makefile +244 -0
  100. data/ext/multi_compress/vendor/lz4/lib/README.md +193 -0
  101. data/ext/multi_compress/vendor/lz4/lib/dll/example/Makefile +63 -0
  102. data/ext/multi_compress/vendor/lz4/lib/dll/example/README.md +69 -0
  103. data/ext/multi_compress/vendor/lz4/lib/dll/example/fullbench-dll.sln +25 -0
  104. data/ext/multi_compress/vendor/lz4/lib/dll/example/fullbench-dll.vcxproj +182 -0
  105. data/ext/multi_compress/vendor/lz4/lib/liblz4-dll.rc.in +35 -0
  106. data/ext/multi_compress/vendor/lz4/lib/liblz4.pc.in +14 -0
  107. data/ext/multi_compress/vendor/lz4/lib/lz4.c +2829 -0
  108. data/ext/multi_compress/vendor/lz4/lib/lz4.h +884 -0
  109. data/ext/multi_compress/vendor/lz4/lib/lz4file.c +341 -0
  110. data/ext/multi_compress/vendor/lz4/lib/lz4file.h +93 -0
  111. data/ext/multi_compress/vendor/lz4/lib/lz4frame.c +2136 -0
  112. data/ext/multi_compress/vendor/lz4/lib/lz4frame.h +751 -0
  113. data/ext/multi_compress/vendor/lz4/lib/lz4frame_static.h +47 -0
  114. data/ext/multi_compress/vendor/lz4/lib/lz4hc.c +2192 -0
  115. data/ext/multi_compress/vendor/lz4/lib/lz4hc.h +414 -0
  116. data/ext/multi_compress/vendor/lz4/lib/xxhash.c +1030 -0
  117. data/ext/multi_compress/vendor/lz4/lib/xxhash.h +328 -0
  118. data/ext/multi_compress/vendor/zstd/lib/BUCK +232 -0
  119. data/ext/multi_compress/vendor/zstd/lib/Makefile +369 -0
  120. data/ext/multi_compress/vendor/zstd/lib/README.md +237 -0
  121. data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
  122. data/ext/multi_compress/vendor/zstd/lib/common/bits.h +200 -0
  123. data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +457 -0
  124. data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +450 -0
  125. data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +249 -0
  126. data/ext/multi_compress/vendor/zstd/lib/common/debug.c +30 -0
  127. data/ext/multi_compress/vendor/zstd/lib/common/debug.h +116 -0
  128. data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +340 -0
  129. data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +63 -0
  130. data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +168 -0
  131. data/ext/multi_compress/vendor/zstd/lib/common/fse.h +640 -0
  132. data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +313 -0
  133. data/ext/multi_compress/vendor/zstd/lib/common/huf.h +286 -0
  134. data/ext/multi_compress/vendor/zstd/lib/common/mem.h +426 -0
  135. data/ext/multi_compress/vendor/zstd/lib/common/pool.c +371 -0
  136. data/ext/multi_compress/vendor/zstd/lib/common/pool.h +90 -0
  137. data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +158 -0
  138. data/ext/multi_compress/vendor/zstd/lib/common/threading.c +182 -0
  139. data/ext/multi_compress/vendor/zstd/lib/common/threading.h +150 -0
  140. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +18 -0
  141. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +7020 -0
  142. data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +48 -0
  143. data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +111 -0
  144. data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +392 -0
  145. data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +163 -0
  146. data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +134 -0
  147. data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +625 -0
  148. data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +181 -0
  149. data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +75 -0
  150. data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +1464 -0
  151. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +7153 -0
  152. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +1534 -0
  153. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +235 -0
  154. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +39 -0
  155. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +442 -0
  156. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  157. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +688 -0
  158. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  159. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +748 -0
  160. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +770 -0
  161. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +50 -0
  162. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +968 -0
  163. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +38 -0
  164. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +2199 -0
  165. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +202 -0
  166. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +730 -0
  167. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +117 -0
  168. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
  169. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +1576 -0
  170. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +80 -0
  171. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +1882 -0
  172. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +113 -0
  173. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +1944 -0
  174. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +595 -0
  175. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +244 -0
  176. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +44 -0
  177. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +2407 -0
  178. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +2215 -0
  179. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +73 -0
  180. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +240 -0
  181. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +214 -0
  182. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +26 -0
  183. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +167 -0
  184. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +77 -0
  185. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +1261 -0
  186. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +152 -0
  187. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.c +1913 -0
  188. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +67 -0
  189. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +766 -0
  190. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +1133 -0
  191. data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +48 -0
  192. data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +63 -0
  193. data/ext/multi_compress/vendor/zstd/lib/dll/example/build_package.bat +20 -0
  194. data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.sln +25 -0
  195. data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj +181 -0
  196. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +452 -0
  197. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +2127 -0
  198. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +94 -0
  199. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +3465 -0
  200. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +93 -0
  201. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +3105 -0
  202. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +93 -0
  203. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +3598 -0
  204. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +142 -0
  205. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +4005 -0
  206. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +162 -0
  207. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +4106 -0
  208. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +172 -0
  209. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +4490 -0
  210. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +187 -0
  211. data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +237 -0
  212. data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +16 -0
  213. data/ext/multi_compress/vendor/zstd/lib/module.modulemap +35 -0
  214. data/ext/multi_compress/vendor/zstd/lib/zdict.h +474 -0
  215. data/ext/multi_compress/vendor/zstd/lib/zstd.h +3089 -0
  216. data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +114 -0
  217. data/lib/multi_compress/version.rb +5 -0
  218. data/lib/multi_compress.rb +329 -0
  219. metadata +322 -0
@@ -0,0 +1,85 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Heuristics for deciding about the UTF8-ness of strings. */
8
+
9
+ #include "utf8_util.h"
10
+
11
+ #include <brotli/types.h>
12
+
13
+ #if defined(__cplusplus) || defined(c_plusplus)
14
+ extern "C" {
15
+ #endif
16
+
17
+ static size_t BrotliParseAsUTF8(
18
+ int* symbol, const uint8_t* input, size_t size) {
19
+ /* ASCII */
20
+ if ((input[0] & 0x80) == 0) {
21
+ *symbol = input[0];
22
+ if (*symbol > 0) {
23
+ return 1;
24
+ }
25
+ }
26
+ /* 2-byte UTF8 */
27
+ if (size > 1u &&
28
+ (input[0] & 0xE0) == 0xC0 &&
29
+ (input[1] & 0xC0) == 0x80) {
30
+ *symbol = (((input[0] & 0x1F) << 6) |
31
+ (input[1] & 0x3F));
32
+ if (*symbol > 0x7F) {
33
+ return 2;
34
+ }
35
+ }
36
+ /* 3-byte UFT8 */
37
+ if (size > 2u &&
38
+ (input[0] & 0xF0) == 0xE0 &&
39
+ (input[1] & 0xC0) == 0x80 &&
40
+ (input[2] & 0xC0) == 0x80) {
41
+ *symbol = (((input[0] & 0x0F) << 12) |
42
+ ((input[1] & 0x3F) << 6) |
43
+ (input[2] & 0x3F));
44
+ if (*symbol > 0x7FF) {
45
+ return 3;
46
+ }
47
+ }
48
+ /* 4-byte UFT8 */
49
+ if (size > 3u &&
50
+ (input[0] & 0xF8) == 0xF0 &&
51
+ (input[1] & 0xC0) == 0x80 &&
52
+ (input[2] & 0xC0) == 0x80 &&
53
+ (input[3] & 0xC0) == 0x80) {
54
+ *symbol = (((input[0] & 0x07) << 18) |
55
+ ((input[1] & 0x3F) << 12) |
56
+ ((input[2] & 0x3F) << 6) |
57
+ (input[3] & 0x3F));
58
+ if (*symbol > 0xFFFF && *symbol <= 0x10FFFF) {
59
+ return 4;
60
+ }
61
+ }
62
+ /* Not UTF8, emit a special symbol above the UTF8-code space */
63
+ *symbol = 0x110000 | input[0];
64
+ return 1;
65
+ }
66
+
67
+ /* Returns 1 if at least min_fraction of the data is UTF8-encoded.*/
68
+ BROTLI_BOOL BrotliIsMostlyUTF8(
69
+ const uint8_t* data, const size_t pos, const size_t mask,
70
+ const size_t length, const double min_fraction) {
71
+ size_t size_utf8 = 0;
72
+ size_t i = 0;
73
+ while (i < length) {
74
+ int symbol;
75
+ size_t bytes_read =
76
+ BrotliParseAsUTF8(&symbol, &data[(pos + i) & mask], length - i);
77
+ i += bytes_read;
78
+ if (symbol < 0x110000) size_utf8 += bytes_read;
79
+ }
80
+ return TO_BROTLI_BOOL((double)size_utf8 > min_fraction * (double)length);
81
+ }
82
+
83
+ #if defined(__cplusplus) || defined(c_plusplus)
84
+ } /* extern "C" */
85
+ #endif
@@ -0,0 +1,33 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Heuristics for deciding about the UTF8-ness of strings. */
8
+
9
+ #ifndef BROTLI_ENC_UTF8_UTIL_H_
10
+ #define BROTLI_ENC_UTF8_UTIL_H_
11
+
12
+ #include <brotli/types.h>
13
+
14
+ #include "../common/platform.h"
15
+
16
+ #if defined(__cplusplus) || defined(c_plusplus)
17
+ extern "C" {
18
+ #endif
19
+
20
+ static const double kMinUTF8Ratio = 0.75;
21
+
22
+ /* Returns 1 if at least min_fraction of the bytes between pos and
23
+ pos + length in the (data, mask) ring-buffer is UTF8-encoded, otherwise
24
+ returns 0. */
25
+ BROTLI_INTERNAL BROTLI_BOOL BrotliIsMostlyUTF8(
26
+ const uint8_t* data, const size_t pos, const size_t mask,
27
+ const size_t length, const double min_fraction);
28
+
29
+ #if defined(__cplusplus) || defined(c_plusplus)
30
+ } /* extern "C" */
31
+ #endif
32
+
33
+ #endif /* BROTLI_ENC_UTF8_UTIL_H_ */
@@ -0,0 +1,88 @@
1
+ /* Copyright 2010 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Write bits into a byte array. */
8
+
9
+ #ifndef BROTLI_ENC_WRITE_BITS_H_
10
+ #define BROTLI_ENC_WRITE_BITS_H_
11
+
12
+ #include <brotli/types.h>
13
+
14
+ #include "../common/platform.h"
15
+
16
+ #if defined(__cplusplus) || defined(c_plusplus)
17
+ extern "C" {
18
+ #endif
19
+
20
+ /* This function writes bits into bytes in increasing addresses, and within
21
+ a byte least-significant-bit first.
22
+
23
+ The function can write up to 56 bits in one go with WriteBits
24
+ Example: let's assume that 3 bits (Rs below) have been written already:
25
+
26
+ BYTE-0 BYTE+1 BYTE+2
27
+
28
+ 0000 0RRR 0000 0000 0000 0000
29
+
30
+ Now, we could write 5 or less bits in MSB by just shifting by 3
31
+ and OR'ing to BYTE-0.
32
+
33
+ For n bits, we take the last 5 bits, OR that with high bits in BYTE-0,
34
+ and locate the rest in BYTE+1, BYTE+2, etc. */
35
+ static BROTLI_INLINE void BrotliWriteBits(size_t n_bits,
36
+ uint64_t bits,
37
+ size_t* BROTLI_RESTRICT pos,
38
+ uint8_t* BROTLI_RESTRICT array) {
39
+ BROTLI_LOG(("WriteBits %2d 0x%08x%08x %10d\n", (int)n_bits,
40
+ (uint32_t)(bits >> 32), (uint32_t)(bits & 0xFFFFFFFF),
41
+ (int)*pos));
42
+ BROTLI_DCHECK((bits >> n_bits) == 0);
43
+ BROTLI_DCHECK(n_bits <= 56);
44
+ #if defined(BROTLI_LITTLE_ENDIAN)
45
+ /* This branch of the code can write up to 56 bits at a time,
46
+ 7 bits are lost by being perhaps already in *p and at least
47
+ 1 bit is needed to initialize the bit-stream ahead (i.e. if 7
48
+ bits are in *p and we write 57 bits, then the next write will
49
+ access a byte that was never initialized). */
50
+ {
51
+ uint8_t* p = &array[*pos >> 3];
52
+ uint64_t v = (uint64_t)(*p); /* Zero-extend 8 to 64 bits. */
53
+ v |= bits << (*pos & 7);
54
+ BROTLI_UNALIGNED_STORE64LE(p, v); /* Set some bits. */
55
+ *pos += n_bits;
56
+ }
57
+ #else
58
+ /* implicit & 0xFF is assumed for uint8_t arithmetics */
59
+ {
60
+ uint8_t* array_pos = &array[*pos >> 3];
61
+ const size_t bits_reserved_in_first_byte = (*pos & 7);
62
+ size_t bits_left_to_write;
63
+ bits <<= bits_reserved_in_first_byte;
64
+ *array_pos++ |= (uint8_t)bits;
65
+ for (bits_left_to_write = n_bits + bits_reserved_in_first_byte;
66
+ bits_left_to_write >= 9;
67
+ bits_left_to_write -= 8) {
68
+ bits >>= 8;
69
+ *array_pos++ = (uint8_t)bits;
70
+ }
71
+ *array_pos = 0;
72
+ *pos += n_bits;
73
+ }
74
+ #endif
75
+ }
76
+
77
+ static BROTLI_INLINE void BrotliWriteBitsPrepareStorage(
78
+ size_t pos, uint8_t* array) {
79
+ BROTLI_LOG(("WriteBitsPrepareStorage %10d\n", (int)pos));
80
+ BROTLI_DCHECK((pos & 7) == 0);
81
+ array[pos >> 3] = 0;
82
+ }
83
+
84
+ #if defined(__cplusplus) || defined(c_plusplus)
85
+ } /* extern "C" */
86
+ #endif
87
+
88
+ #endif /* BROTLI_ENC_WRITE_BITS_H_ */
@@ -0,0 +1,409 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /**
8
+ * @file
9
+ * API for Brotli decompression.
10
+ */
11
+
12
+ #ifndef BROTLI_DEC_DECODE_H_
13
+ #define BROTLI_DEC_DECODE_H_
14
+
15
+ #include <brotli/port.h>
16
+ #include <brotli/shared_dictionary.h>
17
+ #include <brotli/types.h>
18
+
19
+ #if defined(__cplusplus) || defined(c_plusplus)
20
+ extern "C" {
21
+ #endif
22
+
23
+ /**
24
+ * Opaque structure that holds decoder state.
25
+ *
26
+ * Allocated and initialized with ::BrotliDecoderCreateInstance.
27
+ * Cleaned up and deallocated with ::BrotliDecoderDestroyInstance.
28
+ */
29
+ typedef struct BrotliDecoderStateStruct BrotliDecoderState;
30
+
31
+ /**
32
+ * Result type for ::BrotliDecoderDecompress and
33
+ * ::BrotliDecoderDecompressStream functions.
34
+ */
35
+ typedef enum {
36
+ /** Decoding error, e.g. corrupted input or memory allocation problem. */
37
+ BROTLI_DECODER_RESULT_ERROR = 0,
38
+ /** Decoding successfully completed. */
39
+ BROTLI_DECODER_RESULT_SUCCESS = 1,
40
+ /** Partially done; should be called again with more input. */
41
+ BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT = 2,
42
+ /** Partially done; should be called again with more output. */
43
+ BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT = 3
44
+ } BrotliDecoderResult;
45
+
46
+ /**
47
+ * Template that evaluates items of ::BrotliDecoderErrorCode.
48
+ *
49
+ * Example: @code {.cpp}
50
+ * // Log Brotli error code.
51
+ * switch (brotliDecoderErrorCode) {
52
+ * #define CASE_(PREFIX, NAME, CODE) \
53
+ * case BROTLI_DECODER ## PREFIX ## NAME: \
54
+ * LOG(INFO) << "error code:" << #NAME; \
55
+ * break;
56
+ * #define NEWLINE_
57
+ * BROTLI_DECODER_ERROR_CODES_LIST(CASE_, NEWLINE_)
58
+ * #undef CASE_
59
+ * #undef NEWLINE_
60
+ * default: LOG(FATAL) << "unknown brotli error code";
61
+ * }
62
+ * @endcode
63
+ */
64
+ #define BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE, SEPARATOR) \
65
+ BROTLI_ERROR_CODE(_, NO_ERROR, 0) SEPARATOR \
66
+ /* Same as BrotliDecoderResult values */ \
67
+ BROTLI_ERROR_CODE(_, SUCCESS, 1) SEPARATOR \
68
+ BROTLI_ERROR_CODE(_, NEEDS_MORE_INPUT, 2) SEPARATOR \
69
+ BROTLI_ERROR_CODE(_, NEEDS_MORE_OUTPUT, 3) SEPARATOR \
70
+ \
71
+ /* Errors caused by invalid input */ \
72
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_NIBBLE, -1) SEPARATOR \
73
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, RESERVED, -2) SEPARATOR \
74
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_META_NIBBLE, -3) SEPARATOR \
75
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_ALPHABET, -4) SEPARATOR \
76
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_SAME, -5) SEPARATOR \
77
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, CL_SPACE, -6) SEPARATOR \
78
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, HUFFMAN_SPACE, -7) SEPARATOR \
79
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, CONTEXT_MAP_REPEAT, -8) SEPARATOR \
80
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_1, -9) SEPARATOR \
81
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_2, -10) SEPARATOR \
82
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, TRANSFORM, -11) SEPARATOR \
83
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, DICTIONARY, -12) SEPARATOR \
84
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, WINDOW_BITS, -13) SEPARATOR \
85
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_1, -14) SEPARATOR \
86
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_2, -15) SEPARATOR \
87
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, DISTANCE, -16) SEPARATOR \
88
+ \
89
+ /* -17 code is reserved */ \
90
+ \
91
+ BROTLI_ERROR_CODE(_ERROR_, COMPOUND_DICTIONARY, -18) SEPARATOR \
92
+ BROTLI_ERROR_CODE(_ERROR_, DICTIONARY_NOT_SET, -19) SEPARATOR \
93
+ BROTLI_ERROR_CODE(_ERROR_, INVALID_ARGUMENTS, -20) SEPARATOR \
94
+ \
95
+ /* Memory allocation problems */ \
96
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MODES, -21) SEPARATOR \
97
+ /* Literal, insert and distance trees together */ \
98
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, TREE_GROUPS, -22) SEPARATOR \
99
+ /* -23..-24 codes are reserved for distinct tree groups */ \
100
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MAP, -25) SEPARATOR \
101
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_1, -26) SEPARATOR \
102
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_2, -27) SEPARATOR \
103
+ /* -28..-29 codes are reserved for dynamic ring-buffer allocation */ \
104
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, BLOCK_TYPE_TREES, -30) SEPARATOR \
105
+ \
106
+ /* "Impossible" states */ \
107
+ BROTLI_ERROR_CODE(_ERROR_, UNREACHABLE, -31)
108
+
109
+ /**
110
+ * Error code for detailed logging / production debugging.
111
+ *
112
+ * See ::BrotliDecoderGetErrorCode and ::BROTLI_LAST_ERROR_CODE.
113
+ */
114
+ typedef enum {
115
+ #define BROTLI_COMMA_ ,
116
+ #define BROTLI_ERROR_CODE_ENUM_ITEM_(PREFIX, NAME, CODE) \
117
+ BROTLI_DECODER ## PREFIX ## NAME = CODE
118
+ BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE_ENUM_ITEM_, BROTLI_COMMA_)
119
+ } BrotliDecoderErrorCode;
120
+ #undef BROTLI_ERROR_CODE_ENUM_ITEM_
121
+ #undef BROTLI_COMMA_
122
+
123
+ /**
124
+ * The value of the last error code, negative integer.
125
+ *
126
+ * All other error code values are in the range from ::BROTLI_LAST_ERROR_CODE
127
+ * to @c -1. There are also 4 other possible non-error codes @c 0 .. @c 3 in
128
+ * ::BrotliDecoderErrorCode enumeration.
129
+ */
130
+ #define BROTLI_LAST_ERROR_CODE BROTLI_DECODER_ERROR_UNREACHABLE
131
+
132
+ /** Options to be used with ::BrotliDecoderSetParameter. */
133
+ typedef enum BrotliDecoderParameter {
134
+ /**
135
+ * Disable "canny" ring buffer allocation strategy.
136
+ *
137
+ * Ring buffer is allocated according to window size, despite the real size of
138
+ * the content.
139
+ */
140
+ BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION = 0,
141
+ /**
142
+ * Flag that determines if "Large Window Brotli" is used.
143
+ */
144
+ BROTLI_DECODER_PARAM_LARGE_WINDOW = 1
145
+ } BrotliDecoderParameter;
146
+
147
+ /**
148
+ * Sets the specified parameter to the given decoder instance.
149
+ *
150
+ * @param state decoder instance
151
+ * @param param parameter to set
152
+ * @param value new parameter value
153
+ * @returns ::BROTLI_FALSE if parameter is unrecognized, or value is invalid
154
+ * @returns ::BROTLI_TRUE if value is accepted
155
+ */
156
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderSetParameter(
157
+ BrotliDecoderState* state, BrotliDecoderParameter param, uint32_t value);
158
+
159
+ /**
160
+ * Adds LZ77 prefix dictionary, adds or replaces built-in static dictionary and
161
+ * transforms.
162
+ *
163
+ * Attached dictionary ownership is not transferred.
164
+ * Data provided to this method should be kept accessible until
165
+ * decoding is finished and decoder instance is destroyed.
166
+ *
167
+ * @note Dictionaries can NOT be attached after actual decoding is started.
168
+ *
169
+ * @param state decoder instance
170
+ * @param type dictionary data format
171
+ * @param data_size length of memory region pointed by @p data
172
+ * @param data dictionary data in format corresponding to @p type
173
+ * @returns ::BROTLI_FALSE if dictionary is corrupted,
174
+ * or dictionary count limit is reached
175
+ * @returns ::BROTLI_TRUE if dictionary is accepted / attached
176
+ */
177
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderAttachDictionary(
178
+ BrotliDecoderState* state, BrotliSharedDictionaryType type,
179
+ size_t data_size, const uint8_t data[BROTLI_ARRAY_PARAM(data_size)]);
180
+
181
+ /**
182
+ * Creates an instance of ::BrotliDecoderState and initializes it.
183
+ *
184
+ * The instance can be used once for decoding and should then be destroyed with
185
+ * ::BrotliDecoderDestroyInstance, it cannot be reused for a new decoding
186
+ * session.
187
+ *
188
+ * @p alloc_func and @p free_func @b MUST be both zero or both non-zero. In the
189
+ * case they are both zero, default memory allocators are used. @p opaque is
190
+ * passed to @p alloc_func and @p free_func when they are called. @p free_func
191
+ * has to return without doing anything when asked to free a NULL pointer.
192
+ *
193
+ * @param alloc_func custom memory allocation function
194
+ * @param free_func custom memory free function
195
+ * @param opaque custom memory manager handle
196
+ * @returns @c 0 if instance can not be allocated or initialized
197
+ * @returns pointer to initialized ::BrotliDecoderState otherwise
198
+ */
199
+ BROTLI_DEC_API BrotliDecoderState* BrotliDecoderCreateInstance(
200
+ brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
201
+
202
+ /**
203
+ * Deinitializes and frees ::BrotliDecoderState instance.
204
+ *
205
+ * @param state decoder instance to be cleaned up and deallocated
206
+ */
207
+ BROTLI_DEC_API void BrotliDecoderDestroyInstance(BrotliDecoderState* state);
208
+
209
+ /**
210
+ * Performs one-shot memory-to-memory decompression.
211
+ *
212
+ * Decompresses the data in @p encoded_buffer into @p decoded_buffer, and sets
213
+ * @p *decoded_size to the decompressed length.
214
+ *
215
+ * @param encoded_size size of @p encoded_buffer
216
+ * @param encoded_buffer compressed data buffer with at least @p encoded_size
217
+ * addressable bytes
218
+ * @param[in, out] decoded_size @b in: size of @p decoded_buffer; \n
219
+ * @b out: length of decompressed data written to
220
+ * @p decoded_buffer
221
+ * @param decoded_buffer decompressed data destination buffer
222
+ * @returns ::BROTLI_DECODER_RESULT_ERROR if input is corrupted, memory
223
+ * allocation failed, or @p decoded_buffer is not large enough;
224
+ * @returns ::BROTLI_DECODER_RESULT_SUCCESS otherwise
225
+ */
226
+ BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompress(
227
+ size_t encoded_size,
228
+ const uint8_t encoded_buffer[BROTLI_ARRAY_PARAM(encoded_size)],
229
+ size_t* decoded_size,
230
+ uint8_t decoded_buffer[BROTLI_ARRAY_PARAM(*decoded_size)]);
231
+
232
+ /**
233
+ * Decompresses the input stream to the output stream.
234
+ *
235
+ * The values @p *available_in and @p *available_out must specify the number of
236
+ * bytes addressable at @p *next_in and @p *next_out respectively.
237
+ * When @p *available_out is @c 0, @p next_out is allowed to be @c NULL.
238
+ *
239
+ * After each call, @p *available_in will be decremented by the amount of input
240
+ * bytes consumed, and the @p *next_in pointer will be incremented by that
241
+ * amount. Similarly, @p *available_out will be decremented by the amount of
242
+ * output bytes written, and the @p *next_out pointer will be incremented by
243
+ * that amount.
244
+ *
245
+ * @p total_out, if it is not a null-pointer, will be set to the number
246
+ * of bytes decompressed since the last @p state initialization.
247
+ *
248
+ * @note Input is never overconsumed, so @p next_in and @p available_in could be
249
+ * passed to the next consumer after decoding is complete.
250
+ *
251
+ * @param state decoder instance
252
+ * @param[in, out] available_in @b in: amount of available input; \n
253
+ * @b out: amount of unused input
254
+ * @param[in, out] next_in pointer to the next compressed byte
255
+ * @param[in, out] available_out @b in: length of output buffer; \n
256
+ * @b out: remaining size of output buffer
257
+ * @param[in, out] next_out output buffer cursor;
258
+ * can be @c NULL if @p available_out is @c 0
259
+ * @param[out] total_out number of bytes decompressed so far; can be @c NULL
260
+ * @returns ::BROTLI_DECODER_RESULT_ERROR if input is corrupted, memory
261
+ * allocation failed, arguments were invalid, etc.;
262
+ * use ::BrotliDecoderGetErrorCode to get detailed error code
263
+ * @returns ::BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT decoding is blocked until
264
+ * more input data is provided
265
+ * @returns ::BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT decoding is blocked until
266
+ * more output space is provided
267
+ * @returns ::BROTLI_DECODER_RESULT_SUCCESS decoding is finished, no more
268
+ * input might be consumed and no more output will be produced
269
+ */
270
+ BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompressStream(
271
+ BrotliDecoderState* state, size_t* available_in, const uint8_t** next_in,
272
+ size_t* available_out, uint8_t** next_out, size_t* total_out);
273
+
274
+ /**
275
+ * Checks if decoder has more output.
276
+ *
277
+ * @param state decoder instance
278
+ * @returns ::BROTLI_TRUE, if decoder has some unconsumed output
279
+ * @returns ::BROTLI_FALSE otherwise
280
+ */
281
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderHasMoreOutput(
282
+ const BrotliDecoderState* state);
283
+
284
+ /**
285
+ * Acquires pointer to internal output buffer.
286
+ *
287
+ * This method is used to make language bindings easier and more efficient:
288
+ * -# push data to ::BrotliDecoderDecompressStream,
289
+ * until ::BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT is reported
290
+ * -# use ::BrotliDecoderTakeOutput to peek bytes and copy to language-specific
291
+ * entity
292
+ *
293
+ * Also this could be useful if there is an output stream that is able to
294
+ * consume all the provided data (e.g. when data is saved to file system).
295
+ *
296
+ * @attention After every call to ::BrotliDecoderTakeOutput @p *size bytes of
297
+ * output are considered consumed for all consecutive calls to the
298
+ * instance methods; returned pointer becomes invalidated as well.
299
+ *
300
+ * @note Decoder output is not guaranteed to be contiguous. This means that
301
+ * after the size-unrestricted call to ::BrotliDecoderTakeOutput,
302
+ * immediate next call to ::BrotliDecoderTakeOutput may return more data.
303
+ *
304
+ * @param state decoder instance
305
+ * @param[in, out] size @b in: number of bytes caller is ready to take, @c 0 if
306
+ * any amount could be handled; \n
307
+ * @b out: amount of data pointed by returned pointer and
308
+ * considered consumed; \n
309
+ * out value is never greater than in value, unless it is @c 0
310
+ * @returns pointer to output data
311
+ */
312
+ BROTLI_DEC_API const uint8_t* BrotliDecoderTakeOutput(
313
+ BrotliDecoderState* state, size_t* size);
314
+
315
+ /**
316
+ * Checks if instance has already consumed input.
317
+ *
318
+ * Instance that returns ::BROTLI_FALSE is considered "fresh" and could be
319
+ * reused.
320
+ *
321
+ * @param state decoder instance
322
+ * @returns ::BROTLI_TRUE if decoder has already used some input bytes
323
+ * @returns ::BROTLI_FALSE otherwise
324
+ */
325
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsUsed(const BrotliDecoderState* state);
326
+
327
+ /**
328
+ * Checks if decoder instance reached the final state.
329
+ *
330
+ * @param state decoder instance
331
+ * @returns ::BROTLI_TRUE if decoder is in a state where it reached the end of
332
+ * the input and produced all of the output
333
+ * @returns ::BROTLI_FALSE otherwise
334
+ */
335
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsFinished(
336
+ const BrotliDecoderState* state);
337
+
338
+ /**
339
+ * Acquires a detailed error code.
340
+ *
341
+ * Should be used only after ::BrotliDecoderDecompressStream returns
342
+ * ::BROTLI_DECODER_RESULT_ERROR.
343
+ *
344
+ * See also ::BrotliDecoderErrorString
345
+ *
346
+ * @param state decoder instance
347
+ * @returns last saved error code
348
+ */
349
+ BROTLI_DEC_API BrotliDecoderErrorCode BrotliDecoderGetErrorCode(
350
+ const BrotliDecoderState* state);
351
+
352
+ /**
353
+ * Converts error code to a c-string.
354
+ */
355
+ BROTLI_DEC_API const char* BrotliDecoderErrorString(BrotliDecoderErrorCode c);
356
+
357
+ /**
358
+ * Gets a decoder library version.
359
+ *
360
+ * Look at BROTLI_MAKE_HEX_VERSION for more information.
361
+ */
362
+ BROTLI_DEC_API uint32_t BrotliDecoderVersion(void);
363
+
364
+ /**
365
+ * Callback to fire on metadata block start.
366
+ *
367
+ * After this callback is fired, if @p size is not @c 0, it is followed by
368
+ * ::brotli_decoder_metadata_chunk_func as more metadata block contents become
369
+ * accessible.
370
+ *
371
+ * @param opaque callback handle
372
+ * @param size size of metadata block
373
+ */
374
+ typedef void (*brotli_decoder_metadata_start_func)(void* opaque, size_t size);
375
+
376
+ /**
377
+ * Callback to fire on metadata block chunk becomes available.
378
+ *
379
+ * This function can be invoked multiple times per metadata block; block should
380
+ * be considered finished when sum of @p size matches the announced metadata
381
+ * block size. Chunks contents pointed by @p data are transient and shouln not
382
+ * be accessed after leaving the callback.
383
+ *
384
+ * @param opaque callback handle
385
+ * @param data pointer to metadata contents
386
+ * @param size size of metadata block chunk, at least @c 1
387
+ */
388
+ typedef void (*brotli_decoder_metadata_chunk_func)(void* opaque,
389
+ const uint8_t* data,
390
+ size_t size);
391
+
392
+ /**
393
+ * Sets callback for receiving metadata blocks.
394
+ *
395
+ * @param state decoder instance
396
+ * @param start_func callback on metadata block start
397
+ * @param chunk_func callback on metadata block chunk
398
+ * @param opaque callback handle
399
+ */
400
+ BROTLI_DEC_API void BrotliDecoderSetMetadataCallbacks(
401
+ BrotliDecoderState* state,
402
+ brotli_decoder_metadata_start_func start_func,
403
+ brotli_decoder_metadata_chunk_func chunk_func, void* opaque);
404
+
405
+ #if defined(__cplusplus) || defined(c_plusplus)
406
+ } /* extern "C" */
407
+ #endif
408
+
409
+ #endif /* BROTLI_DEC_DECODE_H_ */