brotli 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +6 -3
  3. data/.github/workflows/publish.yml +7 -17
  4. data/.gitmodules +1 -1
  5. data/README.md +2 -2
  6. data/ext/brotli/brotli.c +1 -0
  7. data/ext/brotli/extconf.rb +6 -0
  8. data/lib/brotli/version.rb +1 -1
  9. data/test/brotli_test.rb +4 -1
  10. data/vendor/brotli/c/common/constants.c +1 -1
  11. data/vendor/brotli/c/common/constants.h +2 -1
  12. data/vendor/brotli/c/common/context.c +1 -1
  13. data/vendor/brotli/c/common/dictionary.c +5 -3
  14. data/vendor/brotli/c/common/platform.c +2 -1
  15. data/vendor/brotli/c/common/platform.h +60 -113
  16. data/vendor/brotli/c/common/shared_dictionary.c +521 -0
  17. data/vendor/brotli/c/common/shared_dictionary_internal.h +75 -0
  18. data/vendor/brotli/c/common/transform.c +1 -1
  19. data/vendor/brotli/c/common/version.h +31 -6
  20. data/vendor/brotli/c/dec/bit_reader.c +10 -8
  21. data/vendor/brotli/c/dec/bit_reader.h +172 -100
  22. data/vendor/brotli/c/dec/decode.c +467 -200
  23. data/vendor/brotli/c/dec/huffman.c +7 -4
  24. data/vendor/brotli/c/dec/huffman.h +2 -1
  25. data/vendor/brotli/c/dec/prefix.h +2 -1
  26. data/vendor/brotli/c/dec/state.c +33 -9
  27. data/vendor/brotli/c/dec/state.h +70 -35
  28. data/vendor/brotli/c/enc/backward_references.c +81 -19
  29. data/vendor/brotli/c/enc/backward_references.h +5 -4
  30. data/vendor/brotli/c/enc/backward_references_hq.c +148 -52
  31. data/vendor/brotli/c/enc/backward_references_hq.h +6 -5
  32. data/vendor/brotli/c/enc/backward_references_inc.h +31 -5
  33. data/vendor/brotli/c/enc/bit_cost.c +8 -7
  34. data/vendor/brotli/c/enc/bit_cost.h +5 -4
  35. data/vendor/brotli/c/enc/block_splitter.c +37 -14
  36. data/vendor/brotli/c/enc/block_splitter.h +5 -4
  37. data/vendor/brotli/c/enc/block_splitter_inc.h +86 -45
  38. data/vendor/brotli/c/enc/brotli_bit_stream.c +132 -110
  39. data/vendor/brotli/c/enc/brotli_bit_stream.h +11 -6
  40. data/vendor/brotli/c/enc/cluster.c +10 -9
  41. data/vendor/brotli/c/enc/cluster.h +7 -6
  42. data/vendor/brotli/c/enc/cluster_inc.h +25 -20
  43. data/vendor/brotli/c/enc/command.c +1 -1
  44. data/vendor/brotli/c/enc/command.h +5 -4
  45. data/vendor/brotli/c/enc/compound_dictionary.c +207 -0
  46. data/vendor/brotli/c/enc/compound_dictionary.h +74 -0
  47. data/vendor/brotli/c/enc/compress_fragment.c +93 -83
  48. data/vendor/brotli/c/enc/compress_fragment.h +32 -7
  49. data/vendor/brotli/c/enc/compress_fragment_two_pass.c +99 -87
  50. data/vendor/brotli/c/enc/compress_fragment_two_pass.h +21 -3
  51. data/vendor/brotli/c/enc/dictionary_hash.c +3 -1
  52. data/vendor/brotli/c/enc/encode.c +473 -404
  53. data/vendor/brotli/c/enc/encoder_dict.c +611 -4
  54. data/vendor/brotli/c/enc/encoder_dict.h +117 -3
  55. data/vendor/brotli/c/enc/entropy_encode.c +3 -2
  56. data/vendor/brotli/c/enc/entropy_encode.h +2 -1
  57. data/vendor/brotli/c/enc/entropy_encode_static.h +5 -2
  58. data/vendor/brotli/c/enc/fast_log.c +1 -1
  59. data/vendor/brotli/c/enc/fast_log.h +2 -1
  60. data/vendor/brotli/c/enc/find_match_length.h +15 -22
  61. data/vendor/brotli/c/enc/hash.h +285 -45
  62. data/vendor/brotli/c/enc/hash_composite_inc.h +26 -11
  63. data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +20 -18
  64. data/vendor/brotli/c/enc/hash_longest_match64_inc.h +34 -39
  65. data/vendor/brotli/c/enc/hash_longest_match_inc.h +6 -10
  66. data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -4
  67. data/vendor/brotli/c/enc/hash_rolling_inc.h +4 -4
  68. data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +6 -5
  69. data/vendor/brotli/c/enc/histogram.c +4 -4
  70. data/vendor/brotli/c/enc/histogram.h +7 -6
  71. data/vendor/brotli/c/enc/literal_cost.c +20 -15
  72. data/vendor/brotli/c/enc/literal_cost.h +4 -2
  73. data/vendor/brotli/c/enc/memory.c +29 -5
  74. data/vendor/brotli/c/enc/memory.h +19 -2
  75. data/vendor/brotli/c/enc/metablock.c +72 -58
  76. data/vendor/brotli/c/enc/metablock.h +9 -8
  77. data/vendor/brotli/c/enc/metablock_inc.h +8 -6
  78. data/vendor/brotli/c/enc/params.h +4 -3
  79. data/vendor/brotli/c/enc/prefix.h +3 -2
  80. data/vendor/brotli/c/enc/quality.h +40 -3
  81. data/vendor/brotli/c/enc/ringbuffer.h +4 -3
  82. data/vendor/brotli/c/enc/state.h +104 -0
  83. data/vendor/brotli/c/enc/static_dict.c +60 -4
  84. data/vendor/brotli/c/enc/static_dict.h +3 -2
  85. data/vendor/brotli/c/enc/static_dict_lut.h +2 -0
  86. data/vendor/brotli/c/enc/utf8_util.c +1 -1
  87. data/vendor/brotli/c/enc/utf8_util.h +2 -1
  88. data/vendor/brotli/c/enc/write_bits.h +2 -1
  89. data/vendor/brotli/c/include/brotli/decode.h +67 -2
  90. data/vendor/brotli/c/include/brotli/encode.h +55 -2
  91. data/vendor/brotli/c/include/brotli/port.h +28 -11
  92. data/vendor/brotli/c/include/brotli/shared_dictionary.h +100 -0
  93. metadata +9 -3
@@ -4,13 +4,13 @@
4
4
  See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
5
  */
6
6
 
7
- #include "./static_dict.h"
7
+ #include "static_dict.h"
8
8
 
9
9
  #include "../common/dictionary.h"
10
10
  #include "../common/platform.h"
11
11
  #include "../common/transform.h"
12
- #include "./encoder_dict.h"
13
- #include "./find_match_length.h"
12
+ #include "encoder_dict.h"
13
+ #include "find_match_length.h"
14
14
 
15
15
  #if defined(__cplusplus) || defined(c_plusplus)
16
16
  extern "C" {
@@ -74,10 +74,27 @@ static BROTLI_INLINE BROTLI_BOOL IsMatch(const BrotliDictionary* dictionary,
74
74
  }
75
75
  }
76
76
 
77
- BROTLI_BOOL BrotliFindAllStaticDictionaryMatches(
77
+ /* Finds matches for a single static dictionary */
78
+ static BROTLI_BOOL BrotliFindAllStaticDictionaryMatchesFor(
78
79
  const BrotliEncoderDictionary* dictionary, const uint8_t* data,
79
80
  size_t min_length, size_t max_length, uint32_t* matches) {
80
81
  BROTLI_BOOL has_found_match = BROTLI_FALSE;
82
+ #if defined(BROTLI_EXPERIMENTAL)
83
+ if (dictionary->has_words_heavy) {
84
+ const BrotliTrieNode* node = &dictionary->trie.root;
85
+ size_t l = 0;
86
+ while (node && l < max_length) {
87
+ uint8_t c;
88
+ if (l >= min_length && node->len_) {
89
+ AddMatch(node->idx_, l, node->len_, matches);
90
+ has_found_match = BROTLI_TRUE;
91
+ }
92
+ c = data[l++];
93
+ node = BrotliTrieSub(&dictionary->trie, node, c);
94
+ }
95
+ return has_found_match;
96
+ }
97
+ #endif /* BROTLI_EXPERIMENTAL */
81
98
  {
82
99
  size_t offset = dictionary->buckets[Hash(data)];
83
100
  BROTLI_BOOL end = !offset;
@@ -481,6 +498,45 @@ BROTLI_BOOL BrotliFindAllStaticDictionaryMatches(
481
498
  return has_found_match;
482
499
  }
483
500
 
501
+ /* Finds matches for one or more dictionaries, if multiple are present
502
+ in the contextual dictionary */
503
+ BROTLI_BOOL BrotliFindAllStaticDictionaryMatches(
504
+ const BrotliEncoderDictionary* dictionary, const uint8_t* data,
505
+ size_t min_length, size_t max_length, uint32_t* matches) {
506
+ BROTLI_BOOL has_found_match =
507
+ BrotliFindAllStaticDictionaryMatchesFor(
508
+ dictionary, data, min_length, max_length, matches);
509
+
510
+ if (!!dictionary->parent && dictionary->parent->num_dictionaries > 1) {
511
+ uint32_t matches2[BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN + 1];
512
+ int l;
513
+ const BrotliEncoderDictionary* dictionary2 = dictionary->parent->dict[0];
514
+ if (dictionary2 == dictionary) {
515
+ dictionary2 = dictionary->parent->dict[1];
516
+ }
517
+
518
+ for (l = 0; l < BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN + 1; l++) {
519
+ matches2[l] = kInvalidMatch;
520
+ }
521
+
522
+ has_found_match |= BrotliFindAllStaticDictionaryMatchesFor(
523
+ dictionary2, data, min_length, max_length, matches2);
524
+
525
+ for (l = 0; l < BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN + 1; l++) {
526
+ if (matches2[l] != kInvalidMatch) {
527
+ uint32_t dist = (uint32_t)(matches2[l] >> 5);
528
+ uint32_t len_code = matches2[l] & 31;
529
+ uint32_t skipdist = (uint32_t)((uint32_t)(1 << dictionary->words->
530
+ size_bits_by_length[len_code]) & ~1u) *
531
+ (uint32_t)dictionary->num_transforms;
532
+ /* TODO(lode): check for dist overflow */
533
+ dist += skipdist;
534
+ AddMatch(dist, (size_t)l, len_code, matches);
535
+ }
536
+ }
537
+ }
538
+ return has_found_match;
539
+ }
484
540
  #if defined(__cplusplus) || defined(c_plusplus)
485
541
  } /* extern "C" */
486
542
  #endif
@@ -9,10 +9,11 @@
9
9
  #ifndef BROTLI_ENC_STATIC_DICT_H_
10
10
  #define BROTLI_ENC_STATIC_DICT_H_
11
11
 
12
+ #include <brotli/types.h>
13
+
12
14
  #include "../common/dictionary.h"
13
15
  #include "../common/platform.h"
14
- #include <brotli/types.h>
15
- #include "./encoder_dict.h"
16
+ #include "encoder_dict.h"
16
17
 
17
18
  #if defined(__cplusplus) || defined(c_plusplus)
18
19
  extern "C" {
@@ -22,6 +22,7 @@ typedef struct DictWord {
22
22
  uint16_t idx;
23
23
  } DictWord;
24
24
 
25
+ /* GENERATED CODE START */
25
26
  static const int kDictNumBits = 15;
26
27
  static const uint32_t kDictHashMul32 = 0x1E35A7BD;
27
28
 
@@ -5856,6 +5857,7 @@ static const DictWord kStaticDictionaryWords[31705] = {
5856
5857
  ,0,1735},{5,0,598},{7,0,791},{8,0,108},{9,0,123},{7,10,1570},{140,10,542},{142,
5857
5858
  11,410},{9,11,660},{138,11,347}
5858
5859
  };
5860
+ /* GENERATED CODE END */
5859
5861
 
5860
5862
  #if defined(__cplusplus) || defined(c_plusplus)
5861
5863
  } /* extern "C" */
@@ -6,7 +6,7 @@
6
6
 
7
7
  /* Heuristics for deciding about the UTF8-ness of strings. */
8
8
 
9
- #include "./utf8_util.h"
9
+ #include "utf8_util.h"
10
10
 
11
11
  #include <brotli/types.h>
12
12
 
@@ -9,9 +9,10 @@
9
9
  #ifndef BROTLI_ENC_UTF8_UTIL_H_
10
10
  #define BROTLI_ENC_UTF8_UTIL_H_
11
11
 
12
- #include "../common/platform.h"
13
12
  #include <brotli/types.h>
14
13
 
14
+ #include "../common/platform.h"
15
+
15
16
  #if defined(__cplusplus) || defined(c_plusplus)
16
17
  extern "C" {
17
18
  #endif
@@ -9,9 +9,10 @@
9
9
  #ifndef BROTLI_ENC_WRITE_BITS_H_
10
10
  #define BROTLI_ENC_WRITE_BITS_H_
11
11
 
12
- #include "../common/platform.h"
13
12
  #include <brotli/types.h>
14
13
 
14
+ #include "../common/platform.h"
15
+
15
16
  #if defined(__cplusplus) || defined(c_plusplus)
16
17
  extern "C" {
17
18
  #endif
@@ -13,6 +13,7 @@
13
13
  #define BROTLI_DEC_DECODE_H_
14
14
 
15
15
  #include <brotli/port.h>
16
+ #include <brotli/shared_dictionary.h>
16
17
  #include <brotli/types.h>
17
18
 
18
19
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -85,8 +86,9 @@ typedef enum {
85
86
  BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_2, -15) SEPARATOR \
86
87
  BROTLI_ERROR_CODE(_ERROR_FORMAT_, DISTANCE, -16) SEPARATOR \
87
88
  \
88
- /* -17..-18 codes are reserved */ \
89
+ /* -17 code is reserved */ \
89
90
  \
91
+ BROTLI_ERROR_CODE(_ERROR_, COMPOUND_DICTIONARY, -18) SEPARATOR \
90
92
  BROTLI_ERROR_CODE(_ERROR_, DICTIONARY_NOT_SET, -19) SEPARATOR \
91
93
  BROTLI_ERROR_CODE(_ERROR_, INVALID_ARGUMENTS, -20) SEPARATOR \
92
94
  \
@@ -154,6 +156,28 @@ typedef enum BrotliDecoderParameter {
154
156
  BROTLI_DEC_API BROTLI_BOOL BrotliDecoderSetParameter(
155
157
  BrotliDecoderState* state, BrotliDecoderParameter param, uint32_t value);
156
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
+
157
181
  /**
158
182
  * Creates an instance of ::BrotliDecoderState and initializes it.
159
183
  *
@@ -333,10 +357,51 @@ BROTLI_DEC_API const char* BrotliDecoderErrorString(BrotliDecoderErrorCode c);
333
357
  /**
334
358
  * Gets a decoder library version.
335
359
  *
336
- * Look at BROTLI_VERSION for more information.
360
+ * Look at BROTLI_MAKE_HEX_VERSION for more information.
337
361
  */
338
362
  BROTLI_DEC_API uint32_t BrotliDecoderVersion(void);
339
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
+
340
405
  #if defined(__cplusplus) || defined(c_plusplus)
341
406
  } /* extern "C" */
342
407
  #endif
@@ -13,6 +13,7 @@
13
13
  #define BROTLI_ENC_ENCODE_H_
14
14
 
15
15
  #include <brotli/port.h>
16
+ #include <brotli/shared_dictionary.h>
16
17
  #include <brotli/types.h>
17
18
 
18
19
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -269,6 +270,51 @@ BROTLI_ENC_API BrotliEncoderState* BrotliEncoderCreateInstance(
269
270
  */
270
271
  BROTLI_ENC_API void BrotliEncoderDestroyInstance(BrotliEncoderState* state);
271
272
 
273
+ /* Opaque type for pointer to different possible internal structures containing
274
+ dictionary prepared for the encoder */
275
+ typedef struct BrotliEncoderPreparedDictionaryStruct
276
+ BrotliEncoderPreparedDictionary;
277
+
278
+ /**
279
+ * Prepares a shared dictionary from the given file format for the encoder.
280
+ *
281
+ * @p alloc_func and @p free_func @b MUST be both zero or both non-zero. In the
282
+ * case they are both zero, default memory allocators are used. @p opaque is
283
+ * passed to @p alloc_func and @p free_func when they are called. @p free_func
284
+ * has to return without doing anything when asked to free a NULL pointer.
285
+ *
286
+ * @param type type of dictionary stored in data
287
+ * @param data_size size of @p data buffer
288
+ * @param data pointer to the dictionary data
289
+ * @param quality the maximum Brotli quality to prepare the dictionary for,
290
+ * use BROTLI_MAX_QUALITY by default
291
+ * @param alloc_func custom memory allocation function
292
+ * @param free_func custom memory free function
293
+ * @param opaque custom memory manager handle
294
+ */
295
+ BROTLI_ENC_API BrotliEncoderPreparedDictionary*
296
+ BrotliEncoderPrepareDictionary(BrotliSharedDictionaryType type,
297
+ size_t data_size, const uint8_t data[BROTLI_ARRAY_PARAM(data_size)],
298
+ int quality,
299
+ brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
300
+
301
+ BROTLI_ENC_API void BrotliEncoderDestroyPreparedDictionary(
302
+ BrotliEncoderPreparedDictionary* dictionary);
303
+
304
+ /**
305
+ * Attaches a prepared dictionary of any type to the encoder. Can be used
306
+ * multiple times to attach multiple dictionaries. The dictionary type was
307
+ * determined by BrotliEncoderPrepareDictionary. Multiple raw prefix
308
+ * dictionaries and/or max 1 serialized dictionary with custom words can be
309
+ * attached.
310
+ *
311
+ * @returns ::BROTLI_FALSE in case of error
312
+ * @returns ::BROTLI_TRUE otherwise
313
+ */
314
+ BROTLI_ENC_API BROTLI_BOOL BrotliEncoderAttachPreparedDictionary(
315
+ BrotliEncoderState* state,
316
+ const BrotliEncoderPreparedDictionary* dictionary);
317
+
272
318
  /**
273
319
  * Calculates the output size bound for the given @p input_size.
274
320
  *
@@ -407,7 +453,7 @@ BROTLI_ENC_API BROTLI_BOOL BrotliEncoderHasMoreOutput(
407
453
  *
408
454
  * This method is used to make language bindings easier and more efficient:
409
455
  * -# push data to ::BrotliEncoderCompressStream,
410
- * until ::BrotliEncoderHasMoreOutput returns BROTL_TRUE
456
+ * until ::BrotliEncoderHasMoreOutput returns BROTLI_TRUE
411
457
  * -# use ::BrotliEncoderTakeOutput to peek bytes and copy to language-specific
412
458
  * entity
413
459
  *
@@ -433,11 +479,18 @@ BROTLI_ENC_API BROTLI_BOOL BrotliEncoderHasMoreOutput(
433
479
  BROTLI_ENC_API const uint8_t* BrotliEncoderTakeOutput(
434
480
  BrotliEncoderState* state, size_t* size);
435
481
 
482
+ /* Returns the estimated peak memory usage (in bytes) of the BrotliCompress()
483
+ function, not counting the memory needed for the input and output. */
484
+ BROTLI_ENC_EXTRA_API size_t BrotliEncoderEstimatePeakMemoryUsage(
485
+ int quality, int lgwin, size_t input_size);
486
+ /* Returns 0 if dictionary is not valid; otherwise returns allocation size. */
487
+ BROTLI_ENC_EXTRA_API size_t BrotliEncoderGetPreparedDictionarySize(
488
+ const BrotliEncoderPreparedDictionary* dictionary);
436
489
 
437
490
  /**
438
491
  * Gets an encoder library version.
439
492
  *
440
- * Look at BROTLI_VERSION for more information.
493
+ * Look at BROTLI_MAKE_HEX_VERSION for more information.
441
494
  */
442
495
  BROTLI_ENC_API uint32_t BrotliEncoderVersion(void);
443
496
 
@@ -224,14 +224,6 @@
224
224
  #define BROTLI_HAS_FEATURE(feature) (0)
225
225
  #endif
226
226
 
227
- #if defined(ADDRESS_SANITIZER) || BROTLI_HAS_FEATURE(address_sanitizer) || \
228
- defined(THREAD_SANITIZER) || BROTLI_HAS_FEATURE(thread_sanitizer) || \
229
- defined(MEMORY_SANITIZER) || BROTLI_HAS_FEATURE(memory_sanitizer)
230
- #define BROTLI_SANITIZED 1
231
- #else
232
- #define BROTLI_SANITIZED 0
233
- #endif
234
-
235
227
  #if defined(_WIN32) || defined(__CYGWIN__)
236
228
  #define BROTLI_PUBLIC
237
229
  #elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \
@@ -247,9 +239,28 @@
247
239
  #define BROTLI_PUBLIC
248
240
  #endif
249
241
 
250
- #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
251
- !defined(__STDC_NO_VLA__) && !defined(__cplusplus) && \
252
- !defined(__PGI) && !defined(__PGIC__) && !defined(__TINYC__)
242
+ /* BROTLI_INTERNAL could be defined to override visibility, e.g. for tests. */
243
+ #if !defined(BROTLI_INTERNAL)
244
+ #if defined(_WIN32) || defined(__CYGWIN__)
245
+ #define BROTLI_INTERNAL
246
+ #elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \
247
+ BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
248
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
249
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
250
+ BROTLI_IBM_VERSION_CHECK(13, 1, 0) || \
251
+ BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
252
+ (BROTLI_TI_VERSION_CHECK(7, 3, 0) && \
253
+ defined(__TI_GNU_ATTRIBUTE_SUPPORT__) && defined(__TI_EABI__))
254
+ #define BROTLI_INTERNAL __attribute__ ((visibility ("hidden")))
255
+ #else
256
+ #define BROTLI_INTERNAL
257
+ #endif
258
+ #endif
259
+
260
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
261
+ !defined(__STDC_NO_VLA__) && !defined(__cplusplus) && \
262
+ !defined(__PGI) && !defined(__PGIC__) && !defined(__TINYC__) && \
263
+ !defined(__clang__)
253
264
  #define BROTLI_ARRAY_PARAM(name) (name)
254
265
  #else
255
266
  #define BROTLI_ARRAY_PARAM(name)
@@ -285,4 +296,10 @@
285
296
  #define BROTLI_ENC_API
286
297
  #endif
287
298
 
299
+ #if defined(BROTLI_BUILD_ENC_EXTRA_API)
300
+ #define BROTLI_ENC_EXTRA_API BROTLI_ENC_API
301
+ #else
302
+ #define BROTLI_ENC_EXTRA_API BROTLI_INTERNAL
303
+ #endif
304
+
288
305
  #endif /* BROTLI_COMMON_PORT_H_ */
@@ -0,0 +1,100 @@
1
+ /* Copyright 2017 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
+ /* (Opaque) Shared Dictionary definition and utilities. */
8
+
9
+ #ifndef BROTLI_COMMON_SHARED_DICTIONARY_H_
10
+ #define BROTLI_COMMON_SHARED_DICTIONARY_H_
11
+
12
+ #include <brotli/port.h>
13
+ #include <brotli/types.h>
14
+
15
+ #if defined(__cplusplus) || defined(c_plusplus)
16
+ extern "C" {
17
+ #endif
18
+
19
+ #define SHARED_BROTLI_MIN_DICTIONARY_WORD_LENGTH 4
20
+ #define SHARED_BROTLI_MAX_DICTIONARY_WORD_LENGTH 31
21
+ #define SHARED_BROTLI_NUM_DICTIONARY_CONTEXTS 64
22
+ #define SHARED_BROTLI_MAX_COMPOUND_DICTS 15
23
+
24
+ /**
25
+ * Opaque structure that holds shared dictionary data.
26
+ *
27
+ * Allocated and initialized with ::BrotliSharedDictionaryCreateInstance.
28
+ * Cleaned up and deallocated with ::BrotliSharedDictionaryDestroyInstance.
29
+ */
30
+ typedef struct BrotliSharedDictionaryStruct BrotliSharedDictionary;
31
+
32
+ /**
33
+ * Input data type for ::BrotliSharedDictionaryAttach.
34
+ */
35
+ typedef enum BrotliSharedDictionaryType {
36
+ /** Raw LZ77 prefix dictionary. */
37
+ BROTLI_SHARED_DICTIONARY_RAW = 0,
38
+ /** Serialized shared dictionary.
39
+ *
40
+ * DO NOT USE: methods accepting this value will fail.
41
+ */
42
+ BROTLI_SHARED_DICTIONARY_SERIALIZED = 1
43
+ } BrotliSharedDictionaryType;
44
+
45
+ /**
46
+ * Creates an instance of ::BrotliSharedDictionary.
47
+ *
48
+ * Fresh instance has default word dictionary and transforms
49
+ * and no LZ77 prefix dictionary.
50
+ *
51
+ * @p alloc_func and @p free_func @b MUST be both zero or both non-zero. In the
52
+ * case they are both zero, default memory allocators are used. @p opaque is
53
+ * passed to @p alloc_func and @p free_func when they are called. @p free_func
54
+ * has to return without doing anything when asked to free a NULL pointer.
55
+ *
56
+ * @param alloc_func custom memory allocation function
57
+ * @param free_func custom memory free function
58
+ * @param opaque custom memory manager handle
59
+ * @returns @c 0 if instance can not be allocated or initialized
60
+ * @returns pointer to initialized ::BrotliSharedDictionary otherwise
61
+ */
62
+ BROTLI_COMMON_API BrotliSharedDictionary* BrotliSharedDictionaryCreateInstance(
63
+ brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
64
+
65
+ /**
66
+ * Deinitializes and frees ::BrotliSharedDictionary instance.
67
+ *
68
+ * @param dict shared dictionary instance to be cleaned up and deallocated
69
+ */
70
+ BROTLI_COMMON_API void BrotliSharedDictionaryDestroyInstance(
71
+ BrotliSharedDictionary* dict);
72
+
73
+ /**
74
+ * Attaches dictionary to a given instance of ::BrotliSharedDictionary.
75
+ *
76
+ * Dictionary to be attached is represented in a serialized format as a region
77
+ * of memory.
78
+ *
79
+ * Provided data it partially referenced by a resulting (compound) dictionary,
80
+ * and should be kept untouched, while at least one compound dictionary uses it.
81
+ * This way memory overhead is kept minimal by the cost of additional resource
82
+ * management.
83
+ *
84
+ * @param dict dictionary to extend
85
+ * @param type type of dictionary to attach
86
+ * @param data_size size of @p data
87
+ * @param data serialized dictionary of type @p type, with at least @p data_size
88
+ * addressable bytes
89
+ * @returns ::BROTLI_TRUE if provided dictionary is successfully attached
90
+ * @returns ::BROTLI_FALSE otherwise
91
+ */
92
+ BROTLI_COMMON_API BROTLI_BOOL BrotliSharedDictionaryAttach(
93
+ BrotliSharedDictionary* dict, BrotliSharedDictionaryType type,
94
+ size_t data_size, const uint8_t data[BROTLI_ARRAY_PARAM(data_size)]);
95
+
96
+ #if defined(__cplusplus) || defined(c_plusplus)
97
+ } /* extern "C" */
98
+ #endif
99
+
100
+ #endif /* BROTLI_COMMON_SHARED_DICTIONARY_H_ */
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brotli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - miyucy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-27 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Brotli compressor/decompressor
14
14
  email:
@@ -53,6 +53,8 @@ files:
53
53
  - vendor/brotli/c/common/dictionary.h
54
54
  - vendor/brotli/c/common/platform.c
55
55
  - vendor/brotli/c/common/platform.h
56
+ - vendor/brotli/c/common/shared_dictionary.c
57
+ - vendor/brotli/c/common/shared_dictionary_internal.h
56
58
  - vendor/brotli/c/common/transform.c
57
59
  - vendor/brotli/c/common/transform.h
58
60
  - vendor/brotli/c/common/version.h
@@ -83,6 +85,8 @@ files:
83
85
  - vendor/brotli/c/enc/cluster_inc.h
84
86
  - vendor/brotli/c/enc/command.c
85
87
  - vendor/brotli/c/enc/command.h
88
+ - vendor/brotli/c/enc/compound_dictionary.c
89
+ - vendor/brotli/c/enc/compound_dictionary.h
86
90
  - vendor/brotli/c/enc/compress_fragment.c
87
91
  - vendor/brotli/c/enc/compress_fragment.h
88
92
  - vendor/brotli/c/enc/compress_fragment_two_pass.c
@@ -120,6 +124,7 @@ files:
120
124
  - vendor/brotli/c/enc/prefix.h
121
125
  - vendor/brotli/c/enc/quality.h
122
126
  - vendor/brotli/c/enc/ringbuffer.h
127
+ - vendor/brotli/c/enc/state.h
123
128
  - vendor/brotli/c/enc/static_dict.c
124
129
  - vendor/brotli/c/enc/static_dict.h
125
130
  - vendor/brotli/c/enc/static_dict_lut.h
@@ -129,6 +134,7 @@ files:
129
134
  - vendor/brotli/c/include/brotli/decode.h
130
135
  - vendor/brotli/c/include/brotli/encode.h
131
136
  - vendor/brotli/c/include/brotli/port.h
137
+ - vendor/brotli/c/include/brotli/shared_dictionary.h
132
138
  - vendor/brotli/c/include/brotli/types.h
133
139
  homepage: https://github.com/miyucy/brotli
134
140
  licenses:
@@ -149,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
155
  - !ruby/object:Gem::Version
150
156
  version: '0'
151
157
  requirements: []
152
- rubygems_version: 3.1.4
158
+ rubygems_version: 3.5.3
153
159
  signing_key:
154
160
  specification_version: 4
155
161
  summary: Brotli compressor/decompressor