brotli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +4 -0
  7. data/README.md +36 -0
  8. data/Rakefile +13 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/brotli.gemspec +28 -0
  12. data/ext/brotli/brotli.cc +67 -0
  13. data/ext/brotli/brotli.h +9 -0
  14. data/ext/brotli/extconf.rb +34 -0
  15. data/lib/brotli.rb +2 -0
  16. data/lib/brotli/version.rb +3 -0
  17. data/vendor/brotli/LICENSE +202 -0
  18. data/vendor/brotli/dec/Makefile +12 -0
  19. data/vendor/brotli/dec/bit_reader.c +55 -0
  20. data/vendor/brotli/dec/bit_reader.h +256 -0
  21. data/vendor/brotli/dec/context.h +260 -0
  22. data/vendor/brotli/dec/decode.c +1573 -0
  23. data/vendor/brotli/dec/decode.h +160 -0
  24. data/vendor/brotli/dec/dictionary.h +9494 -0
  25. data/vendor/brotli/dec/huffman.c +325 -0
  26. data/vendor/brotli/dec/huffman.h +77 -0
  27. data/vendor/brotli/dec/port.h +148 -0
  28. data/vendor/brotli/dec/prefix.h +756 -0
  29. data/vendor/brotli/dec/state.c +149 -0
  30. data/vendor/brotli/dec/state.h +185 -0
  31. data/vendor/brotli/dec/streams.c +99 -0
  32. data/vendor/brotli/dec/streams.h +100 -0
  33. data/vendor/brotli/dec/transform.h +315 -0
  34. data/vendor/brotli/dec/types.h +36 -0
  35. data/vendor/brotli/enc/Makefile +11 -0
  36. data/vendor/brotli/enc/backward_references.cc +769 -0
  37. data/vendor/brotli/enc/backward_references.h +50 -0
  38. data/vendor/brotli/enc/bit_cost.h +147 -0
  39. data/vendor/brotli/enc/block_splitter.cc +418 -0
  40. data/vendor/brotli/enc/block_splitter.h +78 -0
  41. data/vendor/brotli/enc/brotli_bit_stream.cc +884 -0
  42. data/vendor/brotli/enc/brotli_bit_stream.h +149 -0
  43. data/vendor/brotli/enc/cluster.h +290 -0
  44. data/vendor/brotli/enc/command.h +140 -0
  45. data/vendor/brotli/enc/context.h +185 -0
  46. data/vendor/brotli/enc/dictionary.h +9485 -0
  47. data/vendor/brotli/enc/dictionary_hash.h +4125 -0
  48. data/vendor/brotli/enc/encode.cc +715 -0
  49. data/vendor/brotli/enc/encode.h +196 -0
  50. data/vendor/brotli/enc/encode_parallel.cc +354 -0
  51. data/vendor/brotli/enc/encode_parallel.h +37 -0
  52. data/vendor/brotli/enc/entropy_encode.cc +492 -0
  53. data/vendor/brotli/enc/entropy_encode.h +88 -0
  54. data/vendor/brotli/enc/fast_log.h +179 -0
  55. data/vendor/brotli/enc/find_match_length.h +87 -0
  56. data/vendor/brotli/enc/hash.h +686 -0
  57. data/vendor/brotli/enc/histogram.cc +76 -0
  58. data/vendor/brotli/enc/histogram.h +100 -0
  59. data/vendor/brotli/enc/literal_cost.cc +172 -0
  60. data/vendor/brotli/enc/literal_cost.h +38 -0
  61. data/vendor/brotli/enc/metablock.cc +544 -0
  62. data/vendor/brotli/enc/metablock.h +88 -0
  63. data/vendor/brotli/enc/port.h +151 -0
  64. data/vendor/brotli/enc/prefix.h +85 -0
  65. data/vendor/brotli/enc/ringbuffer.h +108 -0
  66. data/vendor/brotli/enc/static_dict.cc +441 -0
  67. data/vendor/brotli/enc/static_dict.h +40 -0
  68. data/vendor/brotli/enc/static_dict_lut.h +12063 -0
  69. data/vendor/brotli/enc/streams.cc +127 -0
  70. data/vendor/brotli/enc/streams.h +129 -0
  71. data/vendor/brotli/enc/transform.h +250 -0
  72. data/vendor/brotli/enc/write_bits.h +91 -0
  73. metadata +171 -0
@@ -0,0 +1,149 @@
1
+ /* Copyright 2015 Google Inc. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ */
15
+
16
+ #include "./huffman.h"
17
+ #include "./state.h"
18
+
19
+ #include <stdlib.h>
20
+ #include <string.h>
21
+
22
+ #if defined(__cplusplus) || defined(c_plusplus)
23
+ extern "C" {
24
+ #endif
25
+
26
+ void BrotliStateInit(BrotliState* s) {
27
+ s->state = BROTLI_STATE_UNINITED;
28
+ s->sub0_state = BROTLI_STATE_SUB0_NONE;
29
+ s->sub1_state = BROTLI_STATE_SUB1_NONE;
30
+
31
+ s->block_type_trees = NULL;
32
+ s->block_len_trees = NULL;
33
+ s->ringbuffer = NULL;
34
+
35
+ s->context_map = NULL;
36
+ s->context_modes = NULL;
37
+ s->dist_context_map = NULL;
38
+ s->context_map_slice = NULL;
39
+ s->dist_context_map_slice = NULL;
40
+
41
+ s->literal_hgroup.codes = NULL;
42
+ s->literal_hgroup.htrees = NULL;
43
+ s->insert_copy_hgroup.codes = NULL;
44
+ s->insert_copy_hgroup.htrees = NULL;
45
+ s->distance_hgroup.codes = NULL;
46
+ s->distance_hgroup.htrees = NULL;
47
+
48
+ s->custom_dict = NULL;
49
+ s->custom_dict_size = 0;
50
+
51
+ s->input_end = 0;
52
+ s->window_bits = 0;
53
+ s->max_distance = 0;
54
+ s->dist_rb[0] = 16;
55
+ s->dist_rb[1] = 15;
56
+ s->dist_rb[2] = 11;
57
+ s->dist_rb[3] = 4;
58
+ s->dist_rb_idx = 0;
59
+ s->block_type_trees = NULL;
60
+ s->block_len_trees = NULL;
61
+
62
+ /* Make small negative indexes addressable. */
63
+ s->symbol_lists = &s->symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1];
64
+
65
+ s->mtf_upper_bound = 255;
66
+ }
67
+
68
+ void BrotliStateMetablockBegin(BrotliState* s) {
69
+ s->meta_block_remaining_len = 0;
70
+ s->block_length[0] = 1 << 28;
71
+ s->block_length[1] = 1 << 28;
72
+ s->block_length[2] = 1 << 28;
73
+ s->num_block_types[0] = 1;
74
+ s->num_block_types[1] = 1;
75
+ s->num_block_types[2] = 1;
76
+ s->block_type_rb[0] = 1;
77
+ s->block_type_rb[1] = 0;
78
+ s->block_type_rb[2] = 1;
79
+ s->block_type_rb[3] = 0;
80
+ s->block_type_rb[4] = 1;
81
+ s->block_type_rb[5] = 0;
82
+ s->context_map = NULL;
83
+ s->context_modes = NULL;
84
+ s->dist_context_map = NULL;
85
+ s->context_map_slice = NULL;
86
+ s->literal_htree_index = 0;
87
+ s->literal_htree = NULL;
88
+ s->dist_context_map_slice = NULL;
89
+ s->dist_htree_index = 0;
90
+ s->context_lookup1 = NULL;
91
+ s->context_lookup2 = NULL;
92
+ s->literal_hgroup.codes = NULL;
93
+ s->literal_hgroup.htrees = NULL;
94
+ s->insert_copy_hgroup.codes = NULL;
95
+ s->insert_copy_hgroup.htrees = NULL;
96
+ s->distance_hgroup.codes = NULL;
97
+ s->distance_hgroup.htrees = NULL;
98
+ }
99
+
100
+ void BrotliStateCleanupAfterMetablock(BrotliState* s) {
101
+ if (s->context_modes != 0) {
102
+ free(s->context_modes);
103
+ s->context_modes = NULL;
104
+ }
105
+ if (s->context_map != 0) {
106
+ free(s->context_map);
107
+ s->context_map = NULL;
108
+ }
109
+ if (s->dist_context_map != 0) {
110
+ free(s->dist_context_map);
111
+ s->dist_context_map = NULL;
112
+ }
113
+
114
+ BrotliHuffmanTreeGroupRelease(&s->literal_hgroup);
115
+ BrotliHuffmanTreeGroupRelease(&s->insert_copy_hgroup);
116
+ BrotliHuffmanTreeGroupRelease(&s->distance_hgroup);
117
+ s->literal_hgroup.codes = NULL;
118
+ s->literal_hgroup.htrees = NULL;
119
+ s->insert_copy_hgroup.codes = NULL;
120
+ s->insert_copy_hgroup.htrees = NULL;
121
+ s->distance_hgroup.codes = NULL;
122
+ s->distance_hgroup.htrees = NULL;
123
+ }
124
+
125
+ void BrotliStateCleanup(BrotliState* s) {
126
+ if (s->context_modes != 0) {
127
+ free(s->context_modes);
128
+ }
129
+ if (s->context_map != 0) {
130
+ free(s->context_map);
131
+ }
132
+ if (s->dist_context_map != 0) {
133
+ free(s->dist_context_map);
134
+ }
135
+ BrotliHuffmanTreeGroupRelease(&s->literal_hgroup);
136
+ BrotliHuffmanTreeGroupRelease(&s->insert_copy_hgroup);
137
+ BrotliHuffmanTreeGroupRelease(&s->distance_hgroup);
138
+
139
+ if (s->ringbuffer != 0) {
140
+ free(s->ringbuffer);
141
+ }
142
+ if (s->block_type_trees != 0) {
143
+ free(s->block_type_trees);
144
+ }
145
+ }
146
+
147
+ #if defined(__cplusplus) || defined(c_plusplus)
148
+ } /* extern "C" */
149
+ #endif
@@ -0,0 +1,185 @@
1
+ /* Copyright 2015 Google Inc. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ */
15
+
16
+ /* Brotli state for partial streaming decoding. */
17
+
18
+ #ifndef BROTLI_DEC_STATE_H_
19
+ #define BROTLI_DEC_STATE_H_
20
+
21
+ #include <stdio.h>
22
+ #include "./bit_reader.h"
23
+ #include "./huffman.h"
24
+ #include "./streams.h"
25
+ #include "./types.h"
26
+
27
+ #if defined(__cplusplus) || defined(c_plusplus)
28
+ extern "C" {
29
+ #endif
30
+
31
+ typedef enum {
32
+ BROTLI_STATE_UNINITED,
33
+ BROTLI_STATE_BITREADER_WARMUP,
34
+ BROTLI_STATE_METABLOCK_BEGIN,
35
+ BROTLI_STATE_METABLOCK_HEADER_1,
36
+ BROTLI_STATE_METABLOCK_HEADER_2,
37
+ BROTLI_STATE_COMMAND_BEGIN,
38
+ BROTLI_STATE_COMMAND_INNER,
39
+ BROTLI_STATE_UNCOMPRESSED,
40
+ BROTLI_STATE_METADATA,
41
+ BROTLI_STATE_COMMAND_INNER_WRITE,
42
+ BROTLI_STATE_METABLOCK_DONE,
43
+ BROTLI_STATE_COMMAND_POST_WRITE_1,
44
+ BROTLI_STATE_COMMAND_POST_WRITE_2,
45
+ BROTLI_STATE_COMMAND_POST_WRAP_COPY,
46
+ BROTLI_STATE_HUFFMAN_CODE_0,
47
+ BROTLI_STATE_HUFFMAN_CODE_1,
48
+ BROTLI_STATE_HUFFMAN_CODE_2,
49
+ BROTLI_STATE_CONTEXT_MAP_1,
50
+ BROTLI_STATE_CONTEXT_MAP_2,
51
+ BROTLI_STATE_TREE_GROUP,
52
+ BROTLI_STATE_DONE
53
+ } BrotliRunningState;
54
+
55
+ typedef enum {
56
+ BROTLI_STATE_SUB0_NONE,
57
+ BROTLI_STATE_SUB0_UNCOMPRESSED_SHORT,
58
+ BROTLI_STATE_SUB0_UNCOMPRESSED_FILL,
59
+ BROTLI_STATE_SUB0_UNCOMPRESSED_COPY,
60
+ BROTLI_STATE_SUB0_UNCOMPRESSED_WARMUP,
61
+ BROTLI_STATE_SUB0_UNCOMPRESSED_WRITE_1,
62
+ BROTLI_STATE_SUB0_UNCOMPRESSED_WRITE_2,
63
+ BROTLI_STATE_SUB0_UNCOMPRESSED_WRITE_3,
64
+ BROTLI_STATE_SUB0_TREE_GROUP,
65
+ BROTLI_STATE_SUB0_CONTEXT_MAP_HUFFMAN,
66
+ BROTLI_STATE_SUB0_CONTEXT_MAPS
67
+ } BrotliRunningSub0State;
68
+
69
+ typedef enum {
70
+ BROTLI_STATE_SUB1_NONE,
71
+ BROTLI_STATE_SUB1_HUFFMAN_LENGTH_SYMBOLS
72
+ } BrotliRunningSub1State;
73
+
74
+ typedef struct {
75
+ BrotliRunningState state;
76
+ /* This counter is reused for several disjoint loops. */
77
+ BrotliBitReader br;
78
+ int loop_counter;
79
+ int pos;
80
+ int max_backward_distance;
81
+ int max_backward_distance_minus_custom_dict_size;
82
+ int max_distance;
83
+ int ringbuffer_size;
84
+ int ringbuffer_mask;
85
+ int dist_rb_idx;
86
+ int dist_rb[4];
87
+ uint8_t* ringbuffer;
88
+ uint8_t* ringbuffer_end;
89
+ HuffmanCode* htree_command;
90
+ const uint8_t* context_lookup1;
91
+ const uint8_t* context_lookup2;
92
+ uint8_t* context_map_slice;
93
+ uint8_t* dist_context_map_slice;
94
+
95
+ /* This ring buffer holds a few past copy distances that will be used by */
96
+ /* some special distance codes. */
97
+ HuffmanTreeGroup literal_hgroup;
98
+ HuffmanTreeGroup insert_copy_hgroup;
99
+ HuffmanTreeGroup distance_hgroup;
100
+ HuffmanCode* block_type_trees;
101
+ HuffmanCode* block_len_trees;
102
+ /* This is true if the literal context map histogram type always matches the
103
+ block type. It is then not needed to keep the context (faster decoding). */
104
+ int trivial_literal_context;
105
+ int distance_context;
106
+ int meta_block_remaining_len;
107
+ int block_length[3];
108
+ int num_block_types[3];
109
+ int block_type_rb[6];
110
+ int distance_postfix_bits;
111
+ int num_direct_distance_codes;
112
+ int distance_postfix_mask;
113
+ uint8_t* dist_context_map;
114
+ uint8_t literal_htree_index;
115
+ HuffmanCode *literal_htree;
116
+ uint8_t dist_htree_index;
117
+ uint8_t repeat_code_len;
118
+ uint8_t prev_code_len;
119
+
120
+ int copy_length;
121
+ int distance_code;
122
+
123
+ /* For partial write operations */
124
+ int to_write;
125
+ int partially_written;
126
+
127
+ /* For ReadHuffmanCode */
128
+ uint32_t symbol;
129
+ uint32_t repeat;
130
+ uint32_t space;
131
+
132
+ HuffmanCode table[32];
133
+ /* List of of symbol chains. */
134
+ uint16_t* symbol_lists;
135
+ /* Storage from symbol_lists. */
136
+ uint16_t symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1 +
137
+ BROTLI_HUFFMAN_MAX_CODE_LENGTHS_SIZE];
138
+ /* Tails of symbol chains. */
139
+ int next_symbol[32];
140
+ uint8_t code_length_code_lengths[18];
141
+ /* Population counts for the code lengths */
142
+ uint16_t code_length_histo[16];
143
+
144
+ /* For HuffmanTreeGroupDecode */
145
+ int htree_index;
146
+ HuffmanCode* next;
147
+
148
+ /* For DecodeContextMap */
149
+ int context_index;
150
+ int max_run_length_prefix;
151
+ HuffmanCode context_map_table[BROTLI_HUFFMAN_MAX_TABLE_SIZE];
152
+
153
+ /* For InverseMoveToFrontTransform */
154
+ int mtf_upper_bound;
155
+ uint8_t mtf[256];
156
+
157
+ /* For custom dictionaries */
158
+ const uint8_t* custom_dict;
159
+ int custom_dict_size;
160
+
161
+ /* less used attributes are in the end of this struct */
162
+ BrotliRunningSub0State sub0_state; /* State inside function call */
163
+ BrotliRunningSub1State sub1_state; /* State inside function call */
164
+
165
+ int input_end;
166
+ uint32_t window_bits;
167
+
168
+ /* For CopyUncompressedBlockToOutput */
169
+ int nbytes;
170
+
171
+ int num_literal_htrees;
172
+ uint8_t* context_map;
173
+ uint8_t* context_modes;
174
+ } BrotliState;
175
+
176
+ void BrotliStateInit(BrotliState* s);
177
+ void BrotliStateCleanup(BrotliState* s);
178
+ void BrotliStateMetablockBegin(BrotliState* s);
179
+ void BrotliStateCleanupAfterMetablock(BrotliState* s);
180
+
181
+ #if defined(__cplusplus) || defined(c_plusplus)
182
+ } /* extern "C" */
183
+ #endif
184
+
185
+ #endif /* BROTLI_DEC_STATE_H_ */
@@ -0,0 +1,99 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ */
15
+
16
+ /* Functions for streaming input and output. */
17
+
18
+ #include <string.h>
19
+ #ifndef _WIN32
20
+ #include <unistd.h>
21
+ #endif
22
+ #include "./streams.h"
23
+
24
+ #if defined(__cplusplus) || defined(c_plusplus)
25
+ extern "C" {
26
+ #endif
27
+
28
+ int BrotliMemInputFunction(void* data, uint8_t* buf, size_t count) {
29
+ BrotliMemInput* input = (BrotliMemInput*)data;
30
+ if (input->pos > input->length) {
31
+ return -1;
32
+ }
33
+ if (input->pos + count > input->length) {
34
+ count = input->length - input->pos;
35
+ }
36
+ memcpy(buf, input->buffer + input->pos, count);
37
+ input->pos += count;
38
+ return (int)count;
39
+ }
40
+
41
+ BrotliInput BrotliInitMemInput(const uint8_t* buffer, size_t length,
42
+ BrotliMemInput* mem_input) {
43
+ BrotliInput input;
44
+ mem_input->buffer = buffer;
45
+ mem_input->length = length;
46
+ mem_input->pos = 0;
47
+ input.cb_ = &BrotliMemInputFunction;
48
+ input.data_ = mem_input;
49
+ return input;
50
+ }
51
+
52
+ int BrotliMemOutputFunction(void* data, const uint8_t* buf, size_t count) {
53
+ BrotliMemOutput* output = (BrotliMemOutput*)data;
54
+ size_t limit = output->length - output->pos;
55
+ if (count > limit) {
56
+ count = limit;
57
+ }
58
+ memcpy(output->buffer + output->pos, buf, count);
59
+ output->pos += count;
60
+ return (int)count;
61
+ }
62
+
63
+ BrotliOutput BrotliInitMemOutput(uint8_t* buffer, size_t length,
64
+ BrotliMemOutput* mem_output) {
65
+ BrotliOutput output;
66
+ mem_output->buffer = buffer;
67
+ mem_output->length = length;
68
+ mem_output->pos = 0;
69
+ output.cb_ = &BrotliMemOutputFunction;
70
+ output.data_ = mem_output;
71
+ return output;
72
+ }
73
+
74
+ int BrotliFileInputFunction(void* data, uint8_t* buf, size_t count) {
75
+ return (int)fread(buf, 1, count, (FILE*)data);
76
+ }
77
+
78
+ BrotliInput BrotliFileInput(FILE* f) {
79
+ BrotliInput in;
80
+ in.cb_ = BrotliFileInputFunction;
81
+ in.data_ = f;
82
+ return in;
83
+ }
84
+
85
+ int BrotliFileOutputFunction(void* data, const uint8_t* buf, size_t count) {
86
+ return (int)fwrite(buf, 1, count, (FILE*)data);
87
+ }
88
+
89
+ BrotliOutput BrotliFileOutput(FILE* f) {
90
+ BrotliOutput out;
91
+ out.cb_ = BrotliFileOutputFunction;
92
+ out.data_ = f;
93
+ return out;
94
+ }
95
+
96
+
97
+ #if defined(__cplusplus) || defined(c_plusplus)
98
+ } /* extern "C" */
99
+ #endif
@@ -0,0 +1,100 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ */
15
+
16
+ /* Functions for streaming input and output. */
17
+
18
+ #ifndef BROTLI_DEC_STREAMS_H_
19
+ #define BROTLI_DEC_STREAMS_H_
20
+
21
+ #include <stdio.h>
22
+ #include "./port.h"
23
+ #include "./types.h"
24
+
25
+ #if defined(__cplusplus) || defined(c_plusplus)
26
+ extern "C" {
27
+ #endif
28
+
29
+ /* Function pointer type used to read len bytes into buf. Returns the */
30
+ /* number of bytes read or -1 on error. */
31
+ typedef int (*BrotliInputFunction)(void* data, uint8_t* buf, size_t len);
32
+
33
+ /* Input callback function with associated data. */
34
+ typedef struct {
35
+ BrotliInputFunction cb_;
36
+ void* data_;
37
+ } BrotliInput;
38
+
39
+ /* Reads len bytes into buf, using the in callback. */
40
+ static BROTLI_INLINE int BrotliRead(BrotliInput in, uint8_t* buf, size_t len) {
41
+ return in.cb_(in.data_, buf, len);
42
+ }
43
+
44
+ /* Function pointer type used to write len bytes into buf. Returns the */
45
+ /* number of bytes written or -1 on error. */
46
+ typedef int (*BrotliOutputFunction)(void* data, const uint8_t* buf, size_t len);
47
+
48
+ /* Output callback function with associated data. */
49
+ typedef struct {
50
+ BrotliOutputFunction cb_;
51
+ void* data_;
52
+ } BrotliOutput;
53
+
54
+ /* Writes len bytes into buf, using the out callback. */
55
+ static BROTLI_INLINE int BrotliWrite(BrotliOutput out,
56
+ const uint8_t* buf, size_t len) {
57
+ return out.cb_(out.data_, buf, len);
58
+ }
59
+
60
+ /* Memory region with position. */
61
+ typedef struct {
62
+ const uint8_t* buffer;
63
+ size_t length;
64
+ size_t pos;
65
+ } BrotliMemInput;
66
+
67
+ /* Input callback where *data is a BrotliMemInput struct. */
68
+ int BrotliMemInputFunction(void* data, uint8_t* buf, size_t count);
69
+
70
+ /* Returns an input callback that wraps the given memory region. */
71
+ BrotliInput BrotliInitMemInput(const uint8_t* buffer, size_t length,
72
+ BrotliMemInput* mem_input);
73
+
74
+ /* Output buffer with position. */
75
+ typedef struct {
76
+ uint8_t* buffer;
77
+ size_t length;
78
+ size_t pos;
79
+ } BrotliMemOutput;
80
+
81
+ /* Output callback where *data is a BrotliMemOutput struct. */
82
+ int BrotliMemOutputFunction(void* data, const uint8_t* buf, size_t count);
83
+
84
+ /* Returns an output callback that wraps the given memory region. */
85
+ BrotliOutput BrotliInitMemOutput(uint8_t* buffer, size_t length,
86
+ BrotliMemOutput* mem_output);
87
+
88
+ /* Input callback that reads from a file. */
89
+ int BrotliFileInputFunction(void* data, uint8_t* buf, size_t count);
90
+ BrotliInput BrotliFileInput(FILE* f);
91
+
92
+ /* Output callback that writes to a file. */
93
+ int BrotliFileOutputFunction(void* data, const uint8_t* buf, size_t count);
94
+ BrotliOutput BrotliFileOutput(FILE* f);
95
+
96
+ #if defined(__cplusplus) || defined(c_plusplus)
97
+ } /* extern "C" */
98
+ #endif
99
+
100
+ #endif /* BROTLI_DEC_STREAMS_H_ */