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
data/ext/brotli/brotli.cc DELETED
@@ -1,181 +0,0 @@
1
- #include "brotli.h"
2
- #include "ruby/thread.h"
3
-
4
- #define CSTR2SYM(x) ID2SYM(rb_intern(x))
5
-
6
- static VALUE rb_mBrotli;
7
- static VALUE rb_eBrotli;
8
-
9
- static void*
10
- brotli_alloc(void* opaque, size_t size)
11
- {
12
- return xmalloc(size);
13
- }
14
-
15
- static void
16
- brotli_free(void* opaque, void* address)
17
- {
18
- if (address) {
19
- xfree(address);
20
- }
21
- }
22
-
23
- static VALUE
24
- brotli_inflate(VALUE self, VALUE str)
25
- {
26
- StringValue(str);
27
-
28
- uint8_t output[BUFSIZ];
29
- BrotliResult result = BROTLI_RESULT_ERROR;
30
- size_t available_in = (size_t)RSTRING_LEN(str);
31
- const uint8_t* next_in = (uint8_t*)RSTRING_PTR(str);
32
- size_t available_out = BUFSIZ;
33
- uint8_t* next_out = output;
34
- size_t total_out = 0;
35
- VALUE value = rb_str_buf_new(available_in);
36
-
37
- BrotliState* s = BrotliCreateState(brotli_alloc, brotli_free, NULL);
38
-
39
- for (;;) {
40
- result = BrotliDecompressStream(&available_in,
41
- &next_in,
42
- &available_out,
43
- &next_out,
44
- &total_out,
45
- s);
46
- // success, error or needs more input
47
- if (result != BROTLI_RESULT_NEEDS_MORE_OUTPUT) {
48
- break;
49
- }
50
- rb_str_buf_cat(value, (const char*)output, BUFSIZ);
51
- available_out = BUFSIZ;
52
- next_out = output;
53
- }
54
-
55
- if (next_out != output) {
56
- rb_str_buf_cat(value, (const char*)output, next_out - output);
57
- }
58
-
59
- if (result == BROTLI_RESULT_ERROR) {
60
- const char* error = BrotliErrorString(BrotliGetErrorCode(s));
61
- BrotliDestroyState(s);
62
- rb_raise(rb_eBrotli, "%s", error);
63
- }
64
-
65
- BrotliDestroyState(s);
66
-
67
- if (result == BROTLI_RESULT_NEEDS_MORE_INPUT) {
68
- rb_raise(rb_eBrotli, "Needs more input");
69
- } else if (result == BROTLI_RESULT_NEEDS_MORE_OUTPUT) {
70
- rb_raise(rb_eBrotli, "Needs more output");
71
- }
72
-
73
- return value;
74
- }
75
-
76
- static void
77
- brotli_deflate_parse_options(brotli::BrotliParams& params, VALUE opts)
78
- {
79
- VALUE tmp;
80
-
81
- tmp = rb_hash_aref(opts, CSTR2SYM("mode"));
82
- if (!NIL_P(tmp)) {
83
- if (tmp == CSTR2SYM("generic")) {
84
- params.mode = brotli::BrotliParams::MODE_GENERIC;
85
- } else if (tmp == CSTR2SYM("text")) {
86
- params.mode = brotli::BrotliParams::MODE_TEXT;
87
- } else if (tmp == CSTR2SYM("font")) {
88
- params.mode = brotli::BrotliParams::MODE_FONT;
89
- } else {
90
- rb_raise(rb_eArgError, "invalid mode");
91
- }
92
- }
93
-
94
- tmp = rb_hash_aref(opts, CSTR2SYM("quality"));
95
- if (!NIL_P(tmp)) {
96
- int value = NUM2INT(tmp);
97
- if (0 <= value && value <= 11) {
98
- params.quality = value;
99
- } else {
100
- rb_raise(rb_eArgError, "invalid quality value. Should be 0 to 11.");
101
- }
102
- }
103
-
104
- tmp = rb_hash_aref(opts, CSTR2SYM("lgwin"));
105
- if (!NIL_P(tmp)) {
106
- int value = NUM2INT(tmp);
107
- if (10 <= value && value <= 24) {
108
- params.lgwin = value;
109
- } else {
110
- rb_raise(rb_eArgError, "invalid lgwin value. Should be 10 to 24.");
111
- }
112
- }
113
-
114
- tmp = rb_hash_aref(opts, CSTR2SYM("lgblock"));
115
- if (!NIL_P(tmp)) {
116
- int value = NUM2INT(tmp);
117
- if ((value == 0) || (16 <= value && value <= 24)) {
118
- params.lgblock = value;
119
- } else {
120
- rb_raise(rb_eArgError, "invalid lgblock value. Should be 0 or 16 to 24.");
121
- }
122
- }
123
- }
124
-
125
- struct brotli_deflate_args_t
126
- {
127
- char *str;
128
- size_t str_length;
129
- brotli::BrotliParams *params;
130
- std::string buf;
131
-
132
- } brotli_deflate_args_t;
133
-
134
- static void *
135
- brotli_deflate_no_gvl(void *arg)
136
- {
137
- struct brotli_deflate_args_t *args = (struct brotli_deflate_args_t *)arg;
138
-
139
- brotli::BrotliMemIn in(args->str, args->str_length);
140
- args->buf.reserve(args->str_length * 2 + 1);
141
- brotli::BrotliStringOut out(&args->buf, args->buf.capacity());
142
-
143
- return (void *)(bool)brotli::BrotliCompress(*(args->params), &in, &out);
144
- }
145
-
146
- static VALUE
147
- brotli_deflate(int argc, VALUE *argv, VALUE self)
148
- {
149
- VALUE str, opts;
150
- rb_scan_args(argc, argv, "11", &str, &opts);
151
-
152
- StringValue(str);
153
-
154
- brotli::BrotliParams params;
155
- if (!NIL_P(opts)) {
156
- brotli_deflate_parse_options(params, opts);
157
- }
158
-
159
- struct brotli_deflate_args_t args = {
160
- RSTRING_PTR(str),
161
- RSTRING_LEN(str),
162
- &params
163
- };
164
- if (!rb_thread_call_without_gvl(brotli_deflate_no_gvl, (void *)&args, NULL, NULL)) {
165
- rb_raise(rb_eBrotli, "ERROR");
166
- }
167
-
168
-
169
- return rb_str_new(args.buf.c_str(), args.buf.size());
170
- }
171
-
172
- extern "C" {
173
- void
174
- Init_brotli(void)
175
- {
176
- rb_mBrotli = rb_define_module("Brotli");
177
- rb_eBrotli = rb_define_class_under(rb_mBrotli, "Error", rb_eStandardError);
178
- rb_define_singleton_method(rb_mBrotli, "deflate", RUBY_METHOD_FUNC(brotli_deflate), -1);
179
- rb_define_singleton_method(rb_mBrotli, "inflate", RUBY_METHOD_FUNC(brotli_inflate), 1);
180
- }
181
- }
@@ -1,12 +0,0 @@
1
- #brotli/dec
2
-
3
- include ../shared.mk
4
-
5
- CFLAGS += -Wall
6
-
7
- OBJS = bit_reader.o decode.o dictionary.o huffman.o state.o
8
-
9
- all : $(OBJS)
10
-
11
- clean :
12
- rm -f $(OBJS)