brotli 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +11 -3
  4. data/Gemfile +2 -0
  5. data/ext/brotli/brotli.c +279 -0
  6. data/ext/brotli/brotli.h +2 -0
  7. data/ext/brotli/buffer.c +95 -0
  8. data/ext/brotli/buffer.h +19 -0
  9. data/ext/brotli/extconf.rb +21 -81
  10. data/lib/brotli/version.rb +1 -1
  11. data/vendor/brotli/dec/bit_reader.c +5 -5
  12. data/vendor/brotli/dec/bit_reader.h +15 -15
  13. data/vendor/brotli/dec/context.h +1 -1
  14. data/vendor/brotli/dec/decode.c +433 -348
  15. data/vendor/brotli/dec/decode.h +74 -48
  16. data/vendor/brotli/dec/huffman.c +5 -4
  17. data/vendor/brotli/dec/huffman.h +4 -4
  18. data/vendor/brotli/dec/port.h +2 -95
  19. data/vendor/brotli/dec/prefix.h +5 -3
  20. data/vendor/brotli/dec/state.c +15 -27
  21. data/vendor/brotli/dec/state.h +21 -17
  22. data/vendor/brotli/dec/transform.h +1 -1
  23. data/vendor/brotli/enc/backward_references.c +892 -0
  24. data/vendor/brotli/enc/backward_references.h +85 -102
  25. data/vendor/brotli/enc/backward_references_inc.h +147 -0
  26. data/vendor/brotli/enc/bit_cost.c +35 -0
  27. data/vendor/brotli/enc/bit_cost.h +23 -121
  28. data/vendor/brotli/enc/bit_cost_inc.h +127 -0
  29. data/vendor/brotli/enc/block_encoder_inc.h +33 -0
  30. data/vendor/brotli/enc/block_splitter.c +197 -0
  31. data/vendor/brotli/enc/block_splitter.h +40 -50
  32. data/vendor/brotli/enc/block_splitter_inc.h +432 -0
  33. data/vendor/brotli/enc/brotli_bit_stream.c +1334 -0
  34. data/vendor/brotli/enc/brotli_bit_stream.h +95 -167
  35. data/vendor/brotli/enc/cluster.c +56 -0
  36. data/vendor/brotli/enc/cluster.h +23 -305
  37. data/vendor/brotli/enc/cluster_inc.h +315 -0
  38. data/vendor/brotli/enc/command.h +83 -76
  39. data/vendor/brotli/enc/compress_fragment.c +747 -0
  40. data/vendor/brotli/enc/compress_fragment.h +48 -37
  41. data/vendor/brotli/enc/compress_fragment_two_pass.c +557 -0
  42. data/vendor/brotli/enc/compress_fragment_two_pass.h +37 -26
  43. data/vendor/brotli/enc/compressor.cc +139 -0
  44. data/vendor/brotli/enc/compressor.h +146 -0
  45. data/vendor/brotli/enc/context.h +102 -96
  46. data/vendor/brotli/enc/dictionary_hash.h +9 -5
  47. data/vendor/brotli/enc/encode.c +1562 -0
  48. data/vendor/brotli/enc/encode.h +211 -199
  49. data/vendor/brotli/enc/encode_parallel.cc +161 -151
  50. data/vendor/brotli/enc/encode_parallel.h +7 -8
  51. data/vendor/brotli/enc/entropy_encode.c +501 -0
  52. data/vendor/brotli/enc/entropy_encode.h +107 -89
  53. data/vendor/brotli/enc/entropy_encode_static.h +29 -62
  54. data/vendor/brotli/enc/fast_log.h +26 -20
  55. data/vendor/brotli/enc/find_match_length.h +23 -20
  56. data/vendor/brotli/enc/hash.h +614 -871
  57. data/vendor/brotli/enc/hash_forgetful_chain_inc.h +249 -0
  58. data/vendor/brotli/enc/hash_longest_match_inc.h +241 -0
  59. data/vendor/brotli/enc/hash_longest_match_quickly_inc.h +230 -0
  60. data/vendor/brotli/enc/histogram.c +95 -0
  61. data/vendor/brotli/enc/histogram.h +49 -83
  62. data/vendor/brotli/enc/histogram_inc.h +51 -0
  63. data/vendor/brotli/enc/literal_cost.c +178 -0
  64. data/vendor/brotli/enc/literal_cost.h +16 -10
  65. data/vendor/brotli/enc/memory.c +181 -0
  66. data/vendor/brotli/enc/memory.h +62 -0
  67. data/vendor/brotli/enc/metablock.c +515 -0
  68. data/vendor/brotli/enc/metablock.h +87 -57
  69. data/vendor/brotli/enc/metablock_inc.h +183 -0
  70. data/vendor/brotli/enc/port.h +73 -47
  71. data/vendor/brotli/enc/prefix.h +34 -61
  72. data/vendor/brotli/enc/quality.h +130 -0
  73. data/vendor/brotli/enc/ringbuffer.h +137 -122
  74. data/vendor/brotli/enc/{static_dict.cc → static_dict.c} +162 -139
  75. data/vendor/brotli/enc/static_dict.h +23 -18
  76. data/vendor/brotli/enc/static_dict_lut.h +11223 -12037
  77. data/vendor/brotli/enc/streams.cc +7 -7
  78. data/vendor/brotli/enc/streams.h +32 -32
  79. data/vendor/brotli/enc/{utf8_util.cc → utf8_util.c} +22 -20
  80. data/vendor/brotli/enc/utf8_util.h +16 -9
  81. data/vendor/brotli/enc/write_bits.h +49 -43
  82. metadata +34 -25
  83. data/ext/brotli/brotli.cc +0 -181
  84. data/vendor/brotli/dec/Makefile +0 -12
  85. data/vendor/brotli/dec/dictionary.c +0 -9466
  86. data/vendor/brotli/dec/dictionary.h +0 -38
  87. data/vendor/brotli/dec/types.h +0 -38
  88. data/vendor/brotli/enc/Makefile +0 -14
  89. data/vendor/brotli/enc/backward_references.cc +0 -858
  90. data/vendor/brotli/enc/block_splitter.cc +0 -505
  91. data/vendor/brotli/enc/brotli_bit_stream.cc +0 -1181
  92. data/vendor/brotli/enc/compress_fragment.cc +0 -701
  93. data/vendor/brotli/enc/compress_fragment_two_pass.cc +0 -524
  94. data/vendor/brotli/enc/dictionary.cc +0 -9466
  95. data/vendor/brotli/enc/dictionary.h +0 -41
  96. data/vendor/brotli/enc/encode.cc +0 -1180
  97. data/vendor/brotli/enc/entropy_encode.cc +0 -480
  98. data/vendor/brotli/enc/histogram.cc +0 -67
  99. data/vendor/brotli/enc/literal_cost.cc +0 -165
  100. data/vendor/brotli/enc/metablock.cc +0 -539
  101. data/vendor/brotli/enc/transform.h +0 -248
  102. data/vendor/brotli/enc/types.h +0 -29
@@ -4,206 +4,218 @@
4
4
  See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
5
  */
6
6
 
7
- // API for Brotli compression
7
+ /* API for Brotli compression. */
8
8
 
9
9
  #ifndef BROTLI_ENC_ENCODE_H_
10
10
  #define BROTLI_ENC_ENCODE_H_
11
11
 
12
- #include <string>
13
- #include <vector>
14
- #include "./command.h"
15
- #include "./hash.h"
16
- #include "./ringbuffer.h"
17
- #include "./static_dict.h"
18
- #include "./streams.h"
19
- #include "./types.h"
20
-
21
- namespace brotli {
22
-
23
- static const int kMaxWindowBits = 24;
24
- static const int kMinWindowBits = 10;
25
- static const int kMinInputBlockBits = 16;
26
- static const int kMaxInputBlockBits = 24;
27
-
28
- struct BrotliParams {
29
- BrotliParams(void)
30
- : mode(MODE_GENERIC),
31
- quality(11),
32
- lgwin(22),
33
- lgblock(0),
34
- enable_dictionary(true),
35
- enable_transforms(false),
36
- greedy_block_split(false),
37
- enable_context_modeling(true) {}
38
-
39
- enum Mode {
40
- // Default compression mode. The compressor does not know anything in
41
- // advance about the properties of the input.
42
- MODE_GENERIC = 0,
43
- // Compression mode for UTF-8 format text input.
44
- MODE_TEXT = 1,
45
- // Compression mode used in WOFF 2.0.
46
- MODE_FONT = 2
47
- };
48
- Mode mode;
49
-
50
- // Controls the compression-speed vs compression-density tradeoffs. The higher
51
- // the quality, the slower the compression. Range is 0 to 11.
52
- int quality;
53
- // Base 2 logarithm of the sliding window size. Range is 10 to 24.
54
- int lgwin;
55
- // Base 2 logarithm of the maximum input block size. Range is 16 to 24.
56
- // If set to 0, the value will be set based on the quality.
57
- int lgblock;
58
-
59
- // These settings are deprecated and will be ignored.
60
- // All speed vs. size compromises are controlled by the quality param.
61
- bool enable_dictionary;
62
- bool enable_transforms;
63
- bool greedy_block_split;
64
- bool enable_context_modeling;
65
- };
66
-
67
- // An instance can not be reused for multiple brotli streams.
68
- class BrotliCompressor {
69
- public:
70
- explicit BrotliCompressor(BrotliParams params);
71
- ~BrotliCompressor(void);
72
-
73
- // The maximum input size that can be processed at once.
74
- size_t input_block_size(void) const { return size_t(1) << params_.lgblock; }
75
-
76
- // Encodes the data in input_buffer as a meta-block and writes it to
77
- // encoded_buffer (*encoded_size should be set to the size of
78
- // encoded_buffer) and sets *encoded_size to the number of bytes that
79
- // was written. The input_size must be <= input_block_size().
80
- // Returns 0 if there was an error and 1 otherwise.
81
- bool WriteMetaBlock(const size_t input_size,
82
- const uint8_t* input_buffer,
83
- const bool is_last,
84
- size_t* encoded_size,
85
- uint8_t* encoded_buffer);
86
-
87
- // Writes a metadata meta-block containing the given input to encoded_buffer.
88
- // *encoded_size should be set to the size of the encoded_buffer.
89
- // Sets *encoded_size to the number of bytes that was written.
90
- // Note that the given input data will not be part of the sliding window and
91
- // thus no backward references can be made to this data from subsequent
92
- // metablocks.
93
- bool WriteMetadata(const size_t input_size,
94
- const uint8_t* input_buffer,
95
- const bool is_last,
96
- size_t* encoded_size,
97
- uint8_t* encoded_buffer);
98
-
99
- // Writes a zero-length meta-block with end-of-input bit set to the
100
- // internal output buffer and copies the output buffer to encoded_buffer
101
- // (*encoded_size should be set to the size of encoded_buffer) and sets
102
- // *encoded_size to the number of bytes written. Returns false if there was
103
- // an error and true otherwise.
104
- bool FinishStream(size_t* encoded_size, uint8_t* encoded_buffer);
105
-
106
- // Copies the given input data to the internal ring buffer of the compressor.
107
- // No processing of the data occurs at this time and this function can be
108
- // called multiple times before calling WriteBrotliData() to process the
109
- // accumulated input. At most input_block_size() bytes of input data can be
110
- // copied to the ring buffer, otherwise the next WriteBrotliData() will fail.
111
- void CopyInputToRingBuffer(const size_t input_size,
112
- const uint8_t* input_buffer);
113
-
114
- // Processes the accumulated input data and sets *out_size to the length of
115
- // the new output meta-block, or to zero if no new output meta-block was
116
- // created (in this case the processed input data is buffered internally).
117
- // If *out_size is positive, *output points to the start of the output data.
118
- // If is_last or force_flush is true, an output meta-block is always created.
119
- // Returns false if the size of the input data is larger than
120
- // input_block_size().
121
- bool WriteBrotliData(const bool is_last, const bool force_flush,
122
- size_t* out_size, uint8_t** output);
123
-
124
- // Fills the new state with a dictionary for LZ77, warming up the ringbuffer,
125
- // e.g. for custom static dictionaries for data formats.
126
- // Not to be confused with the built-in transformable dictionary of Brotli.
127
- // To decode, use BrotliSetCustomDictionary of the decoder with the same
128
- // dictionary.
129
- void BrotliSetCustomDictionary(size_t size, const uint8_t* dict);
130
-
131
- // No-op, but we keep it here for API backward-compatibility.
132
- void WriteStreamHeader(void) {}
133
-
134
- private:
135
- uint8_t* GetBrotliStorage(size_t size);
136
-
137
- // Allocates and clears a hash table using memory in "*this",
138
- // stores the number of buckets in "*table_size" and returns a pointer to
139
- // the base of the hash table.
140
- int* GetHashTable(int quality,
141
- size_t input_size, size_t* table_size);
142
-
143
- BrotliParams params_;
144
- Hashers* hashers_;
145
- int hash_type_;
146
- uint64_t input_pos_;
147
- RingBuffer* ringbuffer_;
148
- size_t cmd_alloc_size_;
149
- Command* commands_;
150
- size_t num_commands_;
151
- size_t num_literals_;
152
- size_t last_insert_len_;
153
- uint64_t last_flush_pos_;
154
- uint64_t last_processed_pos_;
155
- int dist_cache_[4];
156
- int saved_dist_cache_[4];
157
- uint8_t last_byte_;
158
- uint8_t last_byte_bits_;
159
- uint8_t prev_byte_;
160
- uint8_t prev_byte2_;
161
- size_t storage_size_;
162
- uint8_t* storage_;
163
- // Hash table for quality 0 mode.
164
- int small_table_[1 << 10]; // 2KB
165
- int* large_table_; // Allocated only when needed
166
- // Command and distance prefix codes (each 64 symbols, stored back-to-back)
167
- // used for the next block in quality 0. The command prefix code is over a
168
- // smaller alphabet with the following 64 symbols:
169
- // 0 - 15: insert length code 0, copy length code 0 - 15, same distance
170
- // 16 - 39: insert length code 0, copy length code 0 - 23
171
- // 40 - 63: insert length code 0 - 23, copy length code 0
172
- // Note that symbols 16 and 40 represent the same code in the full alphabet,
173
- // but we do not use either of them in quality 0.
174
- uint8_t cmd_depths_[128];
175
- uint16_t cmd_bits_[128];
176
- // The compressed form of the command and distance prefix codes for the next
177
- // block in quality 0.
178
- uint8_t cmd_code_[512];
179
- size_t cmd_code_numbits_;
180
- // Command and literal buffers for quality 1.
181
- uint32_t* command_buf_;
182
- uint8_t* literal_buf_;
183
-
184
- int is_last_block_emitted_;
185
- };
186
-
187
- // Compresses the data in input_buffer into encoded_buffer, and sets
188
- // *encoded_size to the compressed length.
189
- // Returns 0 if there was an error and 1 otherwise.
190
- int BrotliCompressBuffer(BrotliParams params,
191
- size_t input_size,
192
- const uint8_t* input_buffer,
193
- size_t* encoded_size,
194
- uint8_t* encoded_buffer);
195
-
196
- // Same as above, but uses the specified input and output classes instead
197
- // of reading from and writing to pre-allocated memory buffers.
198
- int BrotliCompress(BrotliParams params, BrotliIn* in, BrotliOut* out);
199
-
200
- // Before compressing the data, sets a custom LZ77 dictionary with
201
- // BrotliCompressor::BrotliSetCustomDictionary.
202
- int BrotliCompressWithCustomDictionary(size_t dictsize, const uint8_t* dict,
203
- BrotliParams params,
204
- BrotliIn* in, BrotliOut* out);
205
-
206
-
207
- } // namespace brotli
208
-
209
- #endif // BROTLI_ENC_ENCODE_H_
12
+ #include "../common/types.h"
13
+
14
+ #if defined(__cplusplus) || defined(c_plusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+ static const int kBrotliMaxWindowBits = 24;
19
+ static const int kBrotliMinWindowBits = 10;
20
+ static const int kBrotliMinInputBlockBits = 16;
21
+ static const int kBrotliMaxInputBlockBits = 24;
22
+
23
+ #define BROTLI_MIN_QUALITY 0
24
+ #define BROTLI_MAX_QUALITY 11
25
+
26
+ typedef enum BrotliEncoderMode {
27
+ /* Default compression mode. The compressor does not know anything in
28
+ advance about the properties of the input. */
29
+ BROTLI_MODE_GENERIC = 0,
30
+ /* Compression mode for UTF-8 format text input. */
31
+ BROTLI_MODE_TEXT = 1,
32
+ /* Compression mode used in WOFF 2.0. */
33
+ BROTLI_MODE_FONT = 2
34
+ } BrotliEncoderMode;
35
+
36
+ #define BROTLI_DEFAULT_QUALITY 11
37
+ #define BROTLI_DEFAULT_WINDOW 22
38
+ #define BROTLI_DEFAULT_MODE BROTLI_MODE_GENERIC
39
+
40
+ typedef enum BrotliEncoderOperation {
41
+ BROTLI_OPERATION_PROCESS = 0,
42
+ /* Request output stream to flush. Performed when input stream is depleted
43
+ and there is enough space in output stream. */
44
+ BROTLI_OPERATION_FLUSH = 1,
45
+ /* Request output stream to finish. Performed when input stream is depleted
46
+ and there is enough space in output stream. */
47
+ BROTLI_OPERATION_FINISH = 2
48
+ } BrotliEncoderOperation;
49
+
50
+ typedef enum BrotliEncoderParameter {
51
+ BROTLI_PARAM_MODE = 0,
52
+ /* Controls the compression-speed vs compression-density tradeoffs. The higher
53
+ the quality, the slower the compression. Range is 0 to 11. */
54
+ BROTLI_PARAM_QUALITY = 1,
55
+ /* Base 2 logarithm of the sliding window size. Range is 10 to 24. */
56
+ BROTLI_PARAM_LGWIN = 2,
57
+ /* Base 2 logarithm of the maximum input block size. Range is 16 to 24.
58
+ If set to 0, the value will be set based on the quality. */
59
+ BROTLI_PARAM_LGBLOCK = 3
60
+ } BrotliEncoderParameter;
61
+
62
+ /* A state can not be reused for multiple brotli streams. */
63
+ typedef struct BrotliEncoderStateStruct BrotliEncoderState;
64
+
65
+ BROTLI_BOOL BrotliEncoderSetParameter(
66
+ BrotliEncoderState* state, BrotliEncoderParameter p, uint32_t value);
67
+
68
+ /* Creates the instance of BrotliEncoderState and initializes it.
69
+ |alloc_func| and |free_func| MUST be both zero or both non-zero. In the case
70
+ they are both zero, default memory allocators are used. |opaque| is passed to
71
+ |alloc_func| and |free_func| when they are called. */
72
+ BrotliEncoderState* BrotliEncoderCreateInstance(brotli_alloc_func alloc_func,
73
+ brotli_free_func free_func,
74
+ void* opaque);
75
+
76
+ /* Deinitializes and frees BrotliEncoderState instance. */
77
+ void BrotliEncoderDestroyInstance(BrotliEncoderState* state);
78
+ /* The maximum input size that can be processed at once. */
79
+ size_t BrotliEncoderInputBlockSize(BrotliEncoderState* state);
80
+
81
+ /* Encodes the data in |input_buffer| as a meta-block and writes it to
82
+ |encoded_buffer| (|*encoded_size should| be set to the size of
83
+ |encoded_buffer|) and sets |*encoded_size| to the number of bytes that
84
+ was written. The |input_size| must not be greater than input_block_size().
85
+ Returns false if there was an error and true otherwise. */
86
+ BROTLI_BOOL BrotliEncoderWriteMetaBlock(
87
+ BrotliEncoderState* state, const size_t input_size,
88
+ const uint8_t* input_buffer, const BROTLI_BOOL is_last,
89
+ size_t* encoded_size, uint8_t* encoded_buffer);
90
+
91
+ /* Writes a metadata meta-block containing the given input to encoded_buffer.
92
+ |*encoded_size| should be set to the size of the encoded_buffer.
93
+ Sets |*encoded_size| to the number of bytes that was written.
94
+ Note that the given input data will not be part of the sliding window and
95
+ thus no backward references can be made to this data from subsequent
96
+ metablocks. |input_size| must not be greater than 2^24 and provided
97
+ |*encoded_size| must not be less than |input_size| + 6.
98
+ Returns false if there was an error and true otherwise. */
99
+ BROTLI_BOOL BrotliEncoderWriteMetadata(
100
+ BrotliEncoderState* state, const size_t input_size,
101
+ const uint8_t* input_buffer, const BROTLI_BOOL is_last,
102
+ size_t* encoded_size, uint8_t* encoded_buffer);
103
+
104
+ /* Writes a zero-length meta-block with end-of-input bit set to the
105
+ internal output buffer and copies the output buffer to |encoded_buffer|
106
+ (|*encoded_size| should be set to the size of |encoded_buffer|) and sets
107
+ |*encoded_size| to the number of bytes written.
108
+ Returns false if there was an error and true otherwise. */
109
+ BROTLI_BOOL BrotliEncoderFinishStream(
110
+ BrotliEncoderState* state, size_t* encoded_size, uint8_t* encoded_buffer);
111
+
112
+ /* Copies the given input data to the internal ring buffer of the compressor.
113
+ No processing of the data occurs at this time and this function can be
114
+ called multiple times before calling WriteBrotliData() to process the
115
+ accumulated input. At most input_block_size() bytes of input data can be
116
+ copied to the ring buffer, otherwise the next WriteBrotliData() will fail.
117
+ */
118
+ void BrotliEncoderCopyInputToRingBuffer(BrotliEncoderState* state,
119
+ const size_t input_size,
120
+ const uint8_t* input_buffer);
121
+
122
+ /* Processes the accumulated input data and sets |*out_size| to the length of
123
+ the new output meta-block, or to zero if no new output meta-block has been
124
+ created (in this case the processed input data is buffered internally).
125
+ If |*out_size| is positive, |*output| points to the start of the output
126
+ data. If |is_last| or |force_flush| is 1, an output meta-block is always
127
+ created. However, until |is_last| is 1 encoder may retain up to 7 bits
128
+ of the last byte of output. To force encoder to dump the remaining bits
129
+ use WriteMetadata() to append an empty meta-data block.
130
+ Returns false if the size of the input data is larger than
131
+ input_block_size(). */
132
+ BROTLI_BOOL BrotliEncoderWriteData(
133
+ BrotliEncoderState* state, const BROTLI_BOOL is_last,
134
+ const BROTLI_BOOL force_flush, size_t* out_size, uint8_t** output);
135
+
136
+ /* Fills the new state with a dictionary for LZ77, warming up the ringbuffer,
137
+ e.g. for custom static dictionaries for data formats.
138
+ Not to be confused with the built-in transformable dictionary of Brotli.
139
+ To decode, use BrotliSetCustomDictionary() of the decoder with the same
140
+ dictionary. */
141
+ void BrotliEncoderSetCustomDictionary(BrotliEncoderState* state, size_t size,
142
+ const uint8_t* dict);
143
+
144
+ /* Returns buffer size that is large enough to contain BrotliEncoderCompress
145
+ output for any input.
146
+ Returns 0 if result does not fit size_t. */
147
+ size_t BrotliEncoderMaxCompressedSize(size_t input_size);
148
+
149
+ /* Compresses the data in |input_buffer| into |encoded_buffer|, and sets
150
+ |*encoded_size| to the compressed length.
151
+ BROTLI_DEFAULT_QUALITY, BROTLI_DEFAULT_WINDOW and BROTLI_DEFAULT_MODE should
152
+ be used as |quality|, |lgwin| and |mode| if there are no specific
153
+ requirements to encoder speed and compression ratio.
154
+ If compression fails, |*encoded_size| is set to 0.
155
+ If BrotliEncoderMaxCompressedSize(|input_size|) is not zero, then
156
+ |*encoded_size| is never set to the bigger value.
157
+ Returns false if there was an error and true otherwise. */
158
+ BROTLI_BOOL BrotliEncoderCompress(
159
+ int quality, int lgwin, BrotliEncoderMode mode, size_t input_size,
160
+ const uint8_t* input_buffer, size_t* encoded_size, uint8_t* encoded_buffer);
161
+
162
+ /* Progressively compress input stream and push produced bytes to output stream.
163
+ Internally workflow consists of 3 tasks:
164
+ * (optional) copy input data to internal buffer
165
+ * actually compress data and (optionally) store it to internal buffer
166
+ * (optional) copy compressed bytes from internal buffer to output stream
167
+ Whenever all 3 tasks can't move forward anymore, or error occurs, this
168
+ method returns.
169
+
170
+ |available_in| and |next_in| represent input stream; when X bytes of input
171
+ are consumed, X is subtracted from |available_in| and added to |next_in|.
172
+ |available_out| and |next_out| represent output stream; when Y bytes are
173
+ pushed to output, Y is subtracted from |available_out| and added to
174
+ |next_out|. |total_out|, if it is not a null-pointer, is assigned to the
175
+ total amount of bytes pushed by the instance of encoder to output.
176
+
177
+ |op| is used to perform flush or finish the stream.
178
+
179
+ Flushing the stream means forcing encoding of all input passed to encoder and
180
+ completing the current output block, so it could be fully decoded by stream
181
+ decoder. To perform flush |op| must be set to BROTLI_OPERATION_FLUSH. Under
182
+ some circumstances (e.g. lack of output stream capacity) this operation would
183
+ require several calls to BrotliEncoderCompressStream. The method must be
184
+ called again until both input stream is depleted and encoder has no more
185
+ output (see BrotliEncoderHasMoreOutput) after the method is called.
186
+
187
+ Finishing the stream means encoding of all input passed to encoder and
188
+ adding specific "final" marks, so stream decoder could determine that stream
189
+ is complete. To perform finish |op| must be set to BROTLI_OPERATION_FINISH.
190
+ Under some circumstances (e.g. lack of output stream capacity) this operation
191
+ would require several calls to BrotliEncoderCompressStream. The method must
192
+ be called again until both input stream is depleted and encoder has no more
193
+ output (see BrotliEncoderHasMoreOutput) after the method is called.
194
+
195
+ WARNING: when flushing and finishing, |op| should not change until operation
196
+ is complete; input stream should not be refilled as well.
197
+
198
+ Returns false if there was an error and true otherwise.
199
+ */
200
+ BROTLI_BOOL BrotliEncoderCompressStream(
201
+ BrotliEncoderState* s, BrotliEncoderOperation op, size_t* available_in,
202
+ const uint8_t** next_in, size_t* available_out, uint8_t** next_out,
203
+ size_t* total_out);
204
+
205
+ /* Check if encoder is in "finished" state, i.e. no more input is acceptable and
206
+ no more output will be produced.
207
+ Works only with BrotliEncoderCompressStream workflow.
208
+ Returns 1 if stream is finished and 0 otherwise. */
209
+ BROTLI_BOOL BrotliEncoderIsFinished(BrotliEncoderState* s);
210
+
211
+ /* Check if encoder has more output bytes in internal buffer.
212
+ Works only with BrotliEncoderCompressStream workflow.
213
+ Returns 1 if has more output (in internal buffer) and 0 otherwise. */
214
+ BROTLI_BOOL BrotliEncoderHasMoreOutput(BrotliEncoderState* s);
215
+
216
+
217
+ #if defined(__cplusplus) || defined(c_plusplus)
218
+ } /* extern "C" */
219
+ #endif
220
+
221
+ #endif /* BROTLI_ENC_ENCODE_H_ */