brotli 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +7 -3
- data/brotli.gemspec +1 -1
- data/ext/brotli/brotli.c +4 -4
- data/ext/brotli/brotli.h +2 -2
- data/ext/brotli/extconf.rb +9 -16
- data/lib/brotli/version.rb +1 -1
- data/vendor/brotli/{common → c/common}/constants.h +11 -1
- data/vendor/brotli/c/common/dictionary.bin +432 -0
- data/vendor/brotli/c/common/dictionary.c +5905 -0
- data/vendor/brotli/c/common/dictionary.h +64 -0
- data/vendor/brotli/c/common/version.h +19 -0
- data/vendor/brotli/{dec → c/dec}/bit_reader.c +2 -2
- data/vendor/brotli/{dec → c/dec}/bit_reader.h +11 -34
- data/vendor/brotli/{dec → c/dec}/context.h +1 -1
- data/vendor/brotli/{dec → c/dec}/decode.c +389 -356
- data/vendor/brotli/{dec → c/dec}/huffman.c +24 -23
- data/vendor/brotli/{dec → c/dec}/huffman.h +1 -1
- data/vendor/brotli/{dec → c/dec}/port.h +19 -10
- data/vendor/brotli/{dec → c/dec}/prefix.h +1 -1
- data/vendor/brotli/{dec → c/dec}/state.c +23 -19
- data/vendor/brotli/{dec → c/dec}/state.h +18 -17
- data/vendor/brotli/{dec → c/dec}/transform.h +2 -2
- data/vendor/brotli/c/enc/backward_references.c +134 -0
- data/vendor/brotli/c/enc/backward_references.h +39 -0
- data/vendor/brotli/{enc/backward_references.c → c/enc/backward_references_hq.c} +144 -232
- data/vendor/brotli/{enc/backward_references.h → c/enc/backward_references_hq.h} +28 -31
- data/vendor/brotli/{enc → c/enc}/backward_references_inc.h +37 -31
- data/vendor/brotli/{enc → c/enc}/bit_cost.c +1 -1
- data/vendor/brotli/{enc → c/enc}/bit_cost.h +1 -1
- data/vendor/brotli/{enc → c/enc}/bit_cost_inc.h +0 -0
- data/vendor/brotli/{enc → c/enc}/block_encoder_inc.h +0 -0
- data/vendor/brotli/{enc → c/enc}/block_splitter.c +2 -4
- data/vendor/brotli/{enc → c/enc}/block_splitter.h +1 -1
- data/vendor/brotli/{enc → c/enc}/block_splitter_inc.h +6 -7
- data/vendor/brotli/{enc → c/enc}/brotli_bit_stream.c +22 -26
- data/vendor/brotli/{enc → c/enc}/brotli_bit_stream.h +1 -5
- data/vendor/brotli/{enc → c/enc}/cluster.c +1 -1
- data/vendor/brotli/{enc → c/enc}/cluster.h +1 -1
- data/vendor/brotli/{enc → c/enc}/cluster_inc.h +2 -0
- data/vendor/brotli/{enc → c/enc}/command.h +34 -17
- data/vendor/brotli/{enc → c/enc}/compress_fragment.c +97 -53
- data/vendor/brotli/{enc → c/enc}/compress_fragment.h +5 -2
- data/vendor/brotli/{enc → c/enc}/compress_fragment_two_pass.c +106 -51
- data/vendor/brotli/{enc → c/enc}/compress_fragment_two_pass.h +5 -2
- data/vendor/brotli/{enc → c/enc}/context.h +3 -3
- data/vendor/brotli/c/enc/dictionary_hash.c +1120 -0
- data/vendor/brotli/c/enc/dictionary_hash.h +24 -0
- data/vendor/brotli/{enc → c/enc}/encode.c +442 -240
- data/vendor/brotli/{enc → c/enc}/entropy_encode.c +9 -9
- data/vendor/brotli/{enc → c/enc}/entropy_encode.h +4 -4
- data/vendor/brotli/{enc → c/enc}/entropy_encode_static.h +4 -4
- data/vendor/brotli/{enc → c/enc}/fast_log.h +3 -3
- data/vendor/brotli/{enc → c/enc}/find_match_length.h +8 -8
- data/vendor/brotli/c/enc/hash.h +446 -0
- data/vendor/brotli/{enc → c/enc}/hash_forgetful_chain_inc.h +72 -68
- data/vendor/brotli/c/enc/hash_longest_match64_inc.h +266 -0
- data/vendor/brotli/c/enc/hash_longest_match_inc.h +258 -0
- data/vendor/brotli/{enc → c/enc}/hash_longest_match_quickly_inc.h +81 -77
- data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +326 -0
- data/vendor/brotli/{enc → c/enc}/histogram.c +4 -2
- data/vendor/brotli/{enc → c/enc}/histogram.h +1 -1
- data/vendor/brotli/{enc → c/enc}/histogram_inc.h +0 -0
- data/vendor/brotli/{enc → c/enc}/literal_cost.c +4 -7
- data/vendor/brotli/{enc → c/enc}/literal_cost.h +2 -2
- data/vendor/brotli/{enc → c/enc}/memory.c +1 -1
- data/vendor/brotli/{enc → c/enc}/memory.h +3 -2
- data/vendor/brotli/{enc → c/enc}/metablock.c +136 -123
- data/vendor/brotli/{enc → c/enc}/metablock.h +2 -12
- data/vendor/brotli/{enc → c/enc}/metablock_inc.h +0 -0
- data/vendor/brotli/{enc → c/enc}/port.h +49 -33
- data/vendor/brotli/{enc → c/enc}/prefix.h +4 -2
- data/vendor/brotli/{enc → c/enc}/quality.h +47 -17
- data/vendor/brotli/{enc → c/enc}/ringbuffer.h +6 -6
- data/vendor/brotli/{enc → c/enc}/static_dict.c +26 -22
- data/vendor/brotli/{enc → c/enc}/static_dict.h +3 -1
- data/vendor/brotli/c/enc/static_dict_lut.h +5864 -0
- data/vendor/brotli/{enc → c/enc}/utf8_util.c +1 -1
- data/vendor/brotli/{enc → c/enc}/utf8_util.h +2 -2
- data/vendor/brotli/{enc → c/enc}/write_bits.h +3 -3
- data/vendor/brotli/c/include/brotli/decode.h +339 -0
- data/vendor/brotli/c/include/brotli/encode.h +402 -0
- data/vendor/brotli/c/include/brotli/port.h +146 -0
- data/vendor/brotli/c/include/brotli/types.h +90 -0
- metadata +80 -79
- data/vendor/brotli/common/dictionary.c +0 -9474
- data/vendor/brotli/common/dictionary.h +0 -29
- data/vendor/brotli/common/port.h +0 -107
- data/vendor/brotli/common/types.h +0 -58
- data/vendor/brotli/dec/decode.h +0 -188
- data/vendor/brotli/enc/compressor.cc +0 -139
- data/vendor/brotli/enc/compressor.h +0 -161
- data/vendor/brotli/enc/dictionary_hash.h +0 -4121
- data/vendor/brotli/enc/encode.h +0 -221
- data/vendor/brotli/enc/encode_parallel.cc +0 -289
- data/vendor/brotli/enc/encode_parallel.h +0 -27
- data/vendor/brotli/enc/hash.h +0 -717
- data/vendor/brotli/enc/hash_longest_match_inc.h +0 -241
- data/vendor/brotli/enc/static_dict_lut.h +0 -11241
- data/vendor/brotli/enc/streams.cc +0 -114
- data/vendor/brotli/enc/streams.h +0 -121
@@ -1,29 +0,0 @@
|
|
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
|
-
/* Collection of static dictionary words. */
|
8
|
-
|
9
|
-
#ifndef BROTLI_COMMON_DICTIONARY_H_
|
10
|
-
#define BROTLI_COMMON_DICTIONARY_H_
|
11
|
-
|
12
|
-
#include "./types.h"
|
13
|
-
|
14
|
-
#if defined(__cplusplus) || defined(c_plusplus)
|
15
|
-
extern "C" {
|
16
|
-
#endif
|
17
|
-
|
18
|
-
extern const uint8_t kBrotliDictionary[122784];
|
19
|
-
extern const uint32_t kBrotliDictionaryOffsetsByLength[25];
|
20
|
-
extern const uint8_t kBrotliDictionarySizeBitsByLength[25];
|
21
|
-
|
22
|
-
#define kBrotliMinDictionaryWordLength 4
|
23
|
-
#define kBrotliMaxDictionaryWordLength 24
|
24
|
-
|
25
|
-
#if defined(__cplusplus) || defined(c_plusplus)
|
26
|
-
} /* extern "C" */
|
27
|
-
#endif
|
28
|
-
|
29
|
-
#endif /* BROTLI_COMMON_DICTIONARY_H_ */
|
data/vendor/brotli/common/port.h
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
/* Copyright 2016 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
|
-
/* Macros for compiler / platform specific features and build options. */
|
8
|
-
|
9
|
-
#ifndef BROTLI_COMMON_PORT_H_
|
10
|
-
#define BROTLI_COMMON_PORT_H_
|
11
|
-
|
12
|
-
/* Compatibility with non-clang compilers. */
|
13
|
-
#ifndef __has_builtin
|
14
|
-
#define __has_builtin(x) 0
|
15
|
-
#endif
|
16
|
-
|
17
|
-
#ifndef __has_attribute
|
18
|
-
#define __has_attribute(x) 0
|
19
|
-
#endif
|
20
|
-
|
21
|
-
#ifndef __has_feature
|
22
|
-
#define __has_feature(x) 0
|
23
|
-
#endif
|
24
|
-
|
25
|
-
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
|
26
|
-
#define BROTLI_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
27
|
-
#else
|
28
|
-
#define BROTLI_GCC_VERSION 0
|
29
|
-
#endif
|
30
|
-
|
31
|
-
#if defined(__ICC)
|
32
|
-
#define BROTLI_ICC_VERSION __ICC
|
33
|
-
#else
|
34
|
-
#define BROTLI_ICC_VERSION 0
|
35
|
-
#endif
|
36
|
-
|
37
|
-
#if defined(BROTLI_BUILD_MODERN_COMPILER)
|
38
|
-
#define BROTLI_MODERN_COMPILER 1
|
39
|
-
#elif BROTLI_GCC_VERSION > 300 || BROTLI_ICC_VERSION >= 1600
|
40
|
-
#define BROTLI_MODERN_COMPILER 1
|
41
|
-
#else
|
42
|
-
#define BROTLI_MODERN_COMPILER 0
|
43
|
-
#endif
|
44
|
-
|
45
|
-
/* Define "PREDICT_TRUE" and "PREDICT_FALSE" macros for capable compilers.
|
46
|
-
|
47
|
-
To apply compiler hint, enclose the branching condition into macros, like this:
|
48
|
-
|
49
|
-
if (PREDICT_TRUE(zero == 0)) {
|
50
|
-
// main execution path
|
51
|
-
} else {
|
52
|
-
// compiler should place this code outside of main execution path
|
53
|
-
}
|
54
|
-
|
55
|
-
OR:
|
56
|
-
|
57
|
-
if (PREDICT_FALSE(something_rare_or_unexpected_happens)) {
|
58
|
-
// compiler should place this code outside of main execution path
|
59
|
-
}
|
60
|
-
|
61
|
-
*/
|
62
|
-
#if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_expect)
|
63
|
-
#define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
|
64
|
-
#define PREDICT_FALSE(x) (__builtin_expect(x, 0))
|
65
|
-
#else
|
66
|
-
#define PREDICT_FALSE(x) (x)
|
67
|
-
#define PREDICT_TRUE(x) (x)
|
68
|
-
#endif
|
69
|
-
|
70
|
-
#if BROTLI_MODERN_COMPILER || __has_attribute(always_inline)
|
71
|
-
#define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
|
72
|
-
#else
|
73
|
-
#define ATTRIBUTE_ALWAYS_INLINE
|
74
|
-
#endif
|
75
|
-
|
76
|
-
#if defined(_WIN32) || defined(__CYGWIN__)
|
77
|
-
#define ATTRIBUTE_VISIBILITY_HIDDEN
|
78
|
-
#elif BROTLI_MODERN_COMPILER || __has_attribute(visibility)
|
79
|
-
#define ATTRIBUTE_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden")))
|
80
|
-
#else
|
81
|
-
#define ATTRIBUTE_VISIBILITY_HIDDEN
|
82
|
-
#endif
|
83
|
-
|
84
|
-
#ifndef BROTLI_INTERNAL
|
85
|
-
#define BROTLI_INTERNAL ATTRIBUTE_VISIBILITY_HIDDEN
|
86
|
-
#endif
|
87
|
-
|
88
|
-
#ifndef _MSC_VER
|
89
|
-
#if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
|
90
|
-
__STDC_VERSION__ >= 199901L
|
91
|
-
#define BROTLI_INLINE inline ATTRIBUTE_ALWAYS_INLINE
|
92
|
-
#else
|
93
|
-
#define BROTLI_INLINE
|
94
|
-
#endif
|
95
|
-
#else /* _MSC_VER */
|
96
|
-
#define BROTLI_INLINE __forceinline
|
97
|
-
#endif /* _MSC_VER */
|
98
|
-
|
99
|
-
#if BROTLI_MODERN_COMPILER || __has_attribute(noinline)
|
100
|
-
#define BROTLI_NOINLINE __attribute__((noinline))
|
101
|
-
#else
|
102
|
-
#define BROTLI_NOINLINE
|
103
|
-
#endif
|
104
|
-
|
105
|
-
#define BROTLI_UNUSED(X) (void)(X)
|
106
|
-
|
107
|
-
#endif /* BROTLI_COMMON_PORT_H_ */
|
@@ -1,58 +0,0 @@
|
|
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
|
-
/* Common types */
|
8
|
-
|
9
|
-
#ifndef BROTLI_COMMON_TYPES_H_
|
10
|
-
#define BROTLI_COMMON_TYPES_H_
|
11
|
-
|
12
|
-
#include <stddef.h> /* for size_t */
|
13
|
-
|
14
|
-
#if defined(_MSC_VER) && (_MSC_VER < 1600)
|
15
|
-
typedef __int8 int8_t;
|
16
|
-
typedef unsigned __int8 uint8_t;
|
17
|
-
typedef __int16 int16_t;
|
18
|
-
typedef unsigned __int16 uint16_t;
|
19
|
-
typedef __int32 int32_t;
|
20
|
-
typedef unsigned __int32 uint32_t;
|
21
|
-
typedef unsigned __int64 uint64_t;
|
22
|
-
typedef __int64 int64_t;
|
23
|
-
#else
|
24
|
-
#include <stdint.h>
|
25
|
-
#endif /* defined(_MSC_VER) && (_MSC_VER < 1600) */
|
26
|
-
|
27
|
-
#if (!defined(_MSC_VER) || (_MSC_VER >= 1800)) && \
|
28
|
-
(defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L))
|
29
|
-
#include <stdbool.h>
|
30
|
-
#define BROTLI_BOOL bool
|
31
|
-
#define BROTLI_TRUE true
|
32
|
-
#define BROTLI_FALSE false
|
33
|
-
#define TO_BROTLI_BOOL(X) (!!(X))
|
34
|
-
#else
|
35
|
-
typedef enum {
|
36
|
-
BROTLI_FALSE = 0,
|
37
|
-
BROTLI_TRUE = !BROTLI_FALSE
|
38
|
-
} BROTLI_BOOL;
|
39
|
-
#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
|
40
|
-
#endif
|
41
|
-
|
42
|
-
#define MAKE_UINT64_T(high, low) ((((uint64_t)(high)) << 32) | low)
|
43
|
-
|
44
|
-
#define BROTLI_UINT32_MAX (~((uint32_t)0))
|
45
|
-
#define BROTLI_SIZE_MAX (~((size_t)0))
|
46
|
-
|
47
|
-
/* Allocating function pointer. Function MUST return 0 in the case of failure.
|
48
|
-
Otherwise it MUST return a valid pointer to a memory region of at least
|
49
|
-
size length. Neither items nor size are allowed to be 0.
|
50
|
-
opaque argument is a pointer provided by client and could be used to bind
|
51
|
-
function to specific object (memory pool). */
|
52
|
-
typedef void* (*brotli_alloc_func)(void* opaque, size_t size);
|
53
|
-
|
54
|
-
/* Deallocating function pointer. Function SHOULD be no-op in the case the
|
55
|
-
address is 0. */
|
56
|
-
typedef void (*brotli_free_func)(void* opaque, void* address);
|
57
|
-
|
58
|
-
#endif /* BROTLI_COMMON_TYPES_H_ */
|
data/vendor/brotli/dec/decode.h
DELETED
@@ -1,188 +0,0 @@
|
|
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
|
-
/* API for Brotli decompression */
|
8
|
-
|
9
|
-
#ifndef BROTLI_DEC_DECODE_H_
|
10
|
-
#define BROTLI_DEC_DECODE_H_
|
11
|
-
|
12
|
-
#include "../common/types.h"
|
13
|
-
|
14
|
-
#if defined(__cplusplus) || defined(c_plusplus)
|
15
|
-
extern "C" {
|
16
|
-
#endif
|
17
|
-
|
18
|
-
typedef struct BrotliDecoderStateStruct BrotliDecoderState;
|
19
|
-
|
20
|
-
typedef enum {
|
21
|
-
/* Decoding error, e.g. corrupt input or memory allocation problem */
|
22
|
-
BROTLI_DECODER_RESULT_ERROR = 0,
|
23
|
-
/* Decoding successfully completed */
|
24
|
-
BROTLI_DECODER_RESULT_SUCCESS = 1,
|
25
|
-
/* Partially done; should be called again with more input */
|
26
|
-
BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT = 2,
|
27
|
-
/* Partially done; should be called again with more output */
|
28
|
-
BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT = 3
|
29
|
-
} BrotliDecoderResult;
|
30
|
-
|
31
|
-
#define BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE, SEPARATOR) \
|
32
|
-
BROTLI_ERROR_CODE(_, NO_ERROR, 0) SEPARATOR \
|
33
|
-
/* Same as BrotliDecoderResult values */ \
|
34
|
-
BROTLI_ERROR_CODE(_, SUCCESS, 1) SEPARATOR \
|
35
|
-
BROTLI_ERROR_CODE(_, NEEDS_MORE_INPUT, 2) SEPARATOR \
|
36
|
-
BROTLI_ERROR_CODE(_, NEEDS_MORE_OUTPUT, 3) SEPARATOR \
|
37
|
-
\
|
38
|
-
/* Errors caused by invalid input */ \
|
39
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_NIBBLE, -1) SEPARATOR \
|
40
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, RESERVED, -2) SEPARATOR \
|
41
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_META_NIBBLE, -3) SEPARATOR \
|
42
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_ALPHABET, -4) SEPARATOR \
|
43
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_SAME, -5) SEPARATOR \
|
44
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, CL_SPACE, -6) SEPARATOR \
|
45
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, HUFFMAN_SPACE, -7) SEPARATOR \
|
46
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, CONTEXT_MAP_REPEAT, -8) SEPARATOR \
|
47
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_1, -9) SEPARATOR \
|
48
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_2, -10) SEPARATOR \
|
49
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, TRANSFORM, -11) SEPARATOR \
|
50
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, DICTIONARY, -12) SEPARATOR \
|
51
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, WINDOW_BITS, -13) SEPARATOR \
|
52
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_1, -14) SEPARATOR \
|
53
|
-
BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_2, -15) SEPARATOR \
|
54
|
-
\
|
55
|
-
/* -16..-20 codes are reserved */ \
|
56
|
-
\
|
57
|
-
/* Memory allocation problems */ \
|
58
|
-
BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MODES, -21) SEPARATOR \
|
59
|
-
/* Literal, insert and distance trees together */ \
|
60
|
-
BROTLI_ERROR_CODE(_ERROR_ALLOC_, TREE_GROUPS, -22) SEPARATOR \
|
61
|
-
/* -23..-24 codes are reserved for distinct tree groups */ \
|
62
|
-
BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MAP, -25) SEPARATOR \
|
63
|
-
BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_1, -26) SEPARATOR \
|
64
|
-
BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_2, -27) SEPARATOR \
|
65
|
-
/* -28..-29 codes are reserved for dynamic ringbuffer allocation */ \
|
66
|
-
BROTLI_ERROR_CODE(_ERROR_ALLOC_, BLOCK_TYPE_TREES, -30) SEPARATOR \
|
67
|
-
\
|
68
|
-
/* "Impossible" states */ \
|
69
|
-
BROTLI_ERROR_CODE(_ERROR_, UNREACHABLE, -31)
|
70
|
-
|
71
|
-
typedef enum {
|
72
|
-
#define _BROTLI_COMMA ,
|
73
|
-
#define _BROTLI_ERROR_CODE_ENUM_ITEM(PREFIX, NAME, CODE) \
|
74
|
-
BROTLI_DECODER ## PREFIX ## NAME = CODE
|
75
|
-
BROTLI_DECODER_ERROR_CODES_LIST(_BROTLI_ERROR_CODE_ENUM_ITEM, _BROTLI_COMMA)
|
76
|
-
#undef _BROTLI_ERROR_CODE_ENUM_ITEM
|
77
|
-
#undef _BROTLI_COMMA
|
78
|
-
} BrotliDecoderErrorCode;
|
79
|
-
|
80
|
-
#define BROTLI_LAST_ERROR_CODE BROTLI_DECODER_ERROR_UNREACHABLE
|
81
|
-
|
82
|
-
/* Creates the instance of BrotliDecoderState and initializes it. |alloc_func|
|
83
|
-
and |free_func| MUST be both zero or both non-zero. In the case they are both
|
84
|
-
zero, default memory allocators are used. |opaque| is passed to |alloc_func|
|
85
|
-
and |free_func| when they are called. */
|
86
|
-
BrotliDecoderState* BrotliDecoderCreateInstance(
|
87
|
-
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
|
88
|
-
|
89
|
-
/* Deinitializes and frees BrotliDecoderState instance. */
|
90
|
-
void BrotliDecoderDestroyInstance(BrotliDecoderState* state);
|
91
|
-
|
92
|
-
/* Decompresses the data in |encoded_buffer| into |decoded_buffer|, and sets
|
93
|
-
|*decoded_size| to the decompressed length. */
|
94
|
-
BrotliDecoderResult BrotliDecoderDecompress(
|
95
|
-
size_t encoded_size, const uint8_t* encoded_buffer, size_t* decoded_size,
|
96
|
-
uint8_t* decoded_buffer);
|
97
|
-
|
98
|
-
/* Decompresses the data. Supports partial input and output.
|
99
|
-
|
100
|
-
Must be called with an allocated input buffer in |*next_in| and an allocated
|
101
|
-
output buffer in |*next_out|. The values |*available_in| and |*available_out|
|
102
|
-
must specify the allocated size in |*next_in| and |*next_out| respectively.
|
103
|
-
|
104
|
-
After each call, |*available_in| will be decremented by the amount of input
|
105
|
-
bytes consumed, and the |*next_in| pointer will be incremented by that
|
106
|
-
amount. Similarly, |*available_out| will be decremented by the amount of
|
107
|
-
output bytes written, and the |*next_out| pointer will be incremented by that
|
108
|
-
amount. |total_out|, if it is not a null-pointer, will be set to the number
|
109
|
-
of bytes decompressed since the last state initialization.
|
110
|
-
|
111
|
-
Input is never overconsumed, so |next_in| and |available_in| could be passed
|
112
|
-
to the next consumer after decoding is complete. */
|
113
|
-
BrotliDecoderResult BrotliDecoderDecompressStream(
|
114
|
-
BrotliDecoderState* s, size_t* available_in, const uint8_t** next_in,
|
115
|
-
size_t* available_out, uint8_t** next_out, size_t* total_out);
|
116
|
-
|
117
|
-
/* Fills the new state with a dictionary for LZ77, warming up the ringbuffer,
|
118
|
-
e.g. for custom static dictionaries for data formats.
|
119
|
-
Not to be confused with the built-in transformable dictionary of Brotli.
|
120
|
-
|size| should be less or equal to 2^24 (16MiB), otherwise the dictionary will
|
121
|
-
be ignored. The dictionary must exist in memory until decoding is done and
|
122
|
-
is owned by the caller. To use:
|
123
|
-
1) Allocate and initialize state with BrotliCreateInstance
|
124
|
-
2) Use BrotliSetCustomDictionary
|
125
|
-
3) Use BrotliDecompressStream
|
126
|
-
4) Clean up and free state with BrotliDestroyState
|
127
|
-
*/
|
128
|
-
void BrotliDecoderSetCustomDictionary(
|
129
|
-
BrotliDecoderState* s, size_t size, const uint8_t* dict);
|
130
|
-
|
131
|
-
/* Returns true, if decoder has some unconsumed output.
|
132
|
-
Otherwise returns false. */
|
133
|
-
BROTLI_BOOL BrotliDecoderHasMoreOutput(const BrotliDecoderState* s);
|
134
|
-
|
135
|
-
/* Returns true, if decoder has already received some input bytes.
|
136
|
-
Otherwise returns false. */
|
137
|
-
BROTLI_BOOL BrotliDecoderIsUsed(const BrotliDecoderState* s);
|
138
|
-
|
139
|
-
/* Returns true, if decoder is in a state where we reached the end of the input
|
140
|
-
and produced all of the output; returns false otherwise. */
|
141
|
-
BROTLI_BOOL BrotliDecoderIsFinished(const BrotliDecoderState* s);
|
142
|
-
|
143
|
-
/* Returns detailed error code after BrotliDecompressStream returns
|
144
|
-
BROTLI_DECODER_RESULT_ERROR. */
|
145
|
-
BrotliDecoderErrorCode BrotliDecoderGetErrorCode(const BrotliDecoderState* s);
|
146
|
-
|
147
|
-
const char* BrotliDecoderErrorString(BrotliDecoderErrorCode c);
|
148
|
-
|
149
|
-
/* DEPRECATED >>> */
|
150
|
-
typedef enum {
|
151
|
-
BROTLI_RESULT_ERROR = 0,
|
152
|
-
BROTLI_RESULT_SUCCESS = 1,
|
153
|
-
BROTLI_RESULT_NEEDS_MORE_INPUT = 2,
|
154
|
-
BROTLI_RESULT_NEEDS_MORE_OUTPUT = 3
|
155
|
-
} BrotliResult;
|
156
|
-
typedef enum {
|
157
|
-
#define _BROTLI_COMMA ,
|
158
|
-
#define _BROTLI_ERROR_CODE_ENUM_ITEM(PREFIX, NAME, CODE) \
|
159
|
-
BROTLI ## PREFIX ## NAME = CODE
|
160
|
-
BROTLI_DECODER_ERROR_CODES_LIST(_BROTLI_ERROR_CODE_ENUM_ITEM, _BROTLI_COMMA)
|
161
|
-
#undef _BROTLI_ERROR_CODE_ENUM_ITEM
|
162
|
-
#undef _BROTLI_COMMA
|
163
|
-
} BrotliErrorCode;
|
164
|
-
typedef struct BrotliStateStruct BrotliState;
|
165
|
-
BrotliState* BrotliCreateState(
|
166
|
-
brotli_alloc_func alloc, brotli_free_func free, void* opaque);
|
167
|
-
void BrotliDestroyState(BrotliState* state);
|
168
|
-
BROTLI_BOOL BrotliDecompressedSize(
|
169
|
-
size_t encoded_size, const uint8_t* encoded_buffer, size_t* decoded_size);
|
170
|
-
BrotliResult BrotliDecompressBuffer(
|
171
|
-
size_t encoded_size, const uint8_t* encoded_buffer, size_t* decoded_size,
|
172
|
-
uint8_t* decoded_buffer);
|
173
|
-
BrotliResult BrotliDecompressStream(
|
174
|
-
size_t* available_in, const uint8_t** next_in, size_t* available_out,
|
175
|
-
uint8_t** next_out, size_t* total_out, BrotliState* s);
|
176
|
-
void BrotliSetCustomDictionary(
|
177
|
-
size_t size, const uint8_t* dict, BrotliState* s);
|
178
|
-
BROTLI_BOOL BrotliStateIsStreamStart(const BrotliState* s);
|
179
|
-
BROTLI_BOOL BrotliStateIsStreamEnd(const BrotliState* s);
|
180
|
-
BrotliErrorCode BrotliGetErrorCode(const BrotliState* s);
|
181
|
-
const char* BrotliErrorString(BrotliErrorCode c);
|
182
|
-
/* <<< DEPRECATED */
|
183
|
-
|
184
|
-
#if defined(__cplusplus) || defined(c_plusplus)
|
185
|
-
} /* extern "C" */
|
186
|
-
#endif
|
187
|
-
|
188
|
-
#endif /* BROTLI_DEC_DECODE_H_ */
|
@@ -1,139 +0,0 @@
|
|
1
|
-
/* Copyright 2016 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
|
-
/* Brotli compressor API C++ wrapper and utilities. */
|
8
|
-
|
9
|
-
#include "./compressor.h"
|
10
|
-
|
11
|
-
#include <cstdlib> /* exit */
|
12
|
-
|
13
|
-
namespace brotli {
|
14
|
-
|
15
|
-
static void SetParams(const BrotliParams* from, BrotliEncoderState* to) {
|
16
|
-
BrotliEncoderMode mode = BROTLI_MODE_GENERIC;
|
17
|
-
if (from->mode == BrotliParams::MODE_TEXT) {
|
18
|
-
mode = BROTLI_MODE_TEXT;
|
19
|
-
} else if (from->mode == BrotliParams::MODE_FONT) {
|
20
|
-
mode = BROTLI_MODE_FONT;
|
21
|
-
}
|
22
|
-
BrotliEncoderSetParameter(to, BROTLI_PARAM_MODE, (uint32_t)mode);
|
23
|
-
BrotliEncoderSetParameter(to, BROTLI_PARAM_QUALITY, (uint32_t)from->quality);
|
24
|
-
BrotliEncoderSetParameter(to, BROTLI_PARAM_LGWIN, (uint32_t)from->lgwin);
|
25
|
-
BrotliEncoderSetParameter(to, BROTLI_PARAM_LGBLOCK, (uint32_t)from->lgblock);
|
26
|
-
}
|
27
|
-
|
28
|
-
BrotliCompressor::BrotliCompressor(BrotliParams params) {
|
29
|
-
state_ = BrotliEncoderCreateInstance(0, 0, 0);
|
30
|
-
if (state_ == 0) std::exit(EXIT_FAILURE); /* OOM */
|
31
|
-
SetParams(¶ms, state_);
|
32
|
-
}
|
33
|
-
|
34
|
-
BrotliCompressor::~BrotliCompressor(void) {
|
35
|
-
BrotliEncoderDestroyInstance(state_);
|
36
|
-
}
|
37
|
-
|
38
|
-
bool BrotliCompressor::WriteMetaBlock(const size_t input_size,
|
39
|
-
const uint8_t* input_buffer,
|
40
|
-
const bool is_last, size_t* encoded_size,
|
41
|
-
uint8_t* encoded_buffer) {
|
42
|
-
return !!BrotliEncoderWriteMetaBlock(state_, input_size, input_buffer,
|
43
|
-
TO_BROTLI_BOOL(is_last), encoded_size,
|
44
|
-
encoded_buffer);
|
45
|
-
}
|
46
|
-
|
47
|
-
bool BrotliCompressor::WriteMetadata(const size_t input_size,
|
48
|
-
const uint8_t* input_buffer,
|
49
|
-
const bool is_last, size_t* encoded_size,
|
50
|
-
uint8_t* encoded_buffer) {
|
51
|
-
return !!BrotliEncoderWriteMetadata(state_, input_size, input_buffer,
|
52
|
-
TO_BROTLI_BOOL(is_last), encoded_size,
|
53
|
-
encoded_buffer);
|
54
|
-
}
|
55
|
-
|
56
|
-
bool BrotliCompressor::FinishStream(size_t* encoded_size,
|
57
|
-
uint8_t* encoded_buffer) {
|
58
|
-
return !!BrotliEncoderFinishStream(state_, encoded_size, encoded_buffer);
|
59
|
-
}
|
60
|
-
|
61
|
-
void BrotliCompressor::CopyInputToRingBuffer(const size_t input_size,
|
62
|
-
const uint8_t* input_buffer) {
|
63
|
-
BrotliEncoderCopyInputToRingBuffer(state_, input_size, input_buffer);
|
64
|
-
}
|
65
|
-
|
66
|
-
bool BrotliCompressor::WriteBrotliData(const bool is_last,
|
67
|
-
const bool force_flush, size_t* out_size,
|
68
|
-
uint8_t** output) {
|
69
|
-
return !!BrotliEncoderWriteData(state_, TO_BROTLI_BOOL(is_last),
|
70
|
-
TO_BROTLI_BOOL(force_flush), out_size, output);
|
71
|
-
}
|
72
|
-
|
73
|
-
void BrotliCompressor::BrotliSetCustomDictionary(size_t size,
|
74
|
-
const uint8_t* dict) {
|
75
|
-
BrotliEncoderSetCustomDictionary(state_, size, dict);
|
76
|
-
}
|
77
|
-
|
78
|
-
int BrotliCompressBuffer(BrotliParams params, size_t input_size,
|
79
|
-
const uint8_t* input_buffer, size_t* encoded_size,
|
80
|
-
uint8_t* encoded_buffer) {
|
81
|
-
return BrotliEncoderCompress(params.quality, params.lgwin,
|
82
|
-
(BrotliEncoderMode)params.mode, input_size, input_buffer,
|
83
|
-
encoded_size, encoded_buffer);
|
84
|
-
}
|
85
|
-
|
86
|
-
int BrotliCompress(BrotliParams params, BrotliIn* in, BrotliOut* out) {
|
87
|
-
return BrotliCompressWithCustomDictionary(0, 0, params, in, out);
|
88
|
-
}
|
89
|
-
|
90
|
-
int BrotliCompressWithCustomDictionary(size_t dictsize, const uint8_t* dict,
|
91
|
-
BrotliParams params, BrotliIn* in,
|
92
|
-
BrotliOut* out) {
|
93
|
-
const size_t kOutputBufferSize = 65536;
|
94
|
-
uint8_t* output_buffer;
|
95
|
-
bool result = true;
|
96
|
-
size_t available_in = 0;
|
97
|
-
const uint8_t* next_in = NULL;
|
98
|
-
size_t total_out = 0;
|
99
|
-
bool end_of_input = false;
|
100
|
-
BrotliEncoderState* s;
|
101
|
-
|
102
|
-
s = BrotliEncoderCreateInstance(0, 0, 0);
|
103
|
-
if (!s) return 0;
|
104
|
-
SetParams(¶ms, s);
|
105
|
-
BrotliEncoderSetCustomDictionary(s, dictsize, dict);
|
106
|
-
output_buffer = new uint8_t[kOutputBufferSize];
|
107
|
-
|
108
|
-
while (true) {
|
109
|
-
if (available_in == 0 && !end_of_input) {
|
110
|
-
next_in = reinterpret_cast<const uint8_t*>(
|
111
|
-
in->Read(BrotliEncoderInputBlockSize(s), &available_in));
|
112
|
-
if (!next_in) {
|
113
|
-
end_of_input = true;
|
114
|
-
available_in = 0;
|
115
|
-
} else if (available_in == 0) {
|
116
|
-
continue;
|
117
|
-
}
|
118
|
-
}
|
119
|
-
size_t available_out = kOutputBufferSize;
|
120
|
-
uint8_t* next_out = output_buffer;
|
121
|
-
result = !!BrotliEncoderCompressStream(
|
122
|
-
s, end_of_input ? BROTLI_OPERATION_FINISH : BROTLI_OPERATION_PROCESS,
|
123
|
-
&available_in, &next_in, &available_out, &next_out, &total_out);
|
124
|
-
if (!result) break;
|
125
|
-
size_t used_output = kOutputBufferSize - available_out;
|
126
|
-
if (used_output != 0) {
|
127
|
-
result = out->Write(output_buffer, used_output);
|
128
|
-
if (!result) break;
|
129
|
-
}
|
130
|
-
if (BrotliEncoderIsFinished(s)) break;
|
131
|
-
}
|
132
|
-
|
133
|
-
delete[] output_buffer;
|
134
|
-
BrotliEncoderDestroyInstance(s);
|
135
|
-
return result ? 1 : 0;
|
136
|
-
}
|
137
|
-
|
138
|
-
|
139
|
-
} /* namespace brotli */
|