brotli 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +113 -1
  3. data/ext/brotli/brotli.c +908 -288
  4. data/ext/brotli/brotli.h +0 -5
  5. data/ext/brotli/buffer.c +43 -65
  6. data/ext/brotli/buffer.h +6 -9
  7. data/ext/brotli/extconf.rb +115 -50
  8. data/lib/brotli/reader.rb +167 -0
  9. data/lib/brotli/version.rb +1 -1
  10. data/lib/brotli/writer.rb +81 -0
  11. data/lib/brotli.rb +2 -0
  12. data/vendor/brotli/c/common/constants.c +7 -7
  13. data/vendor/brotli/c/common/constants.h +2 -5
  14. data/vendor/brotli/c/common/context.c +2 -2
  15. data/vendor/brotli/c/common/context.h +1 -2
  16. data/vendor/brotli/c/common/dictionary.c +4 -5856
  17. data/vendor/brotli/c/common/dictionary.h +1 -2
  18. data/vendor/brotli/c/common/dictionary_inc.h +5847 -0
  19. data/vendor/brotli/c/common/platform.c +0 -4
  20. data/vendor/brotli/c/common/platform.h +182 -43
  21. data/vendor/brotli/c/common/shared_dictionary.c +3 -7
  22. data/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
  23. data/vendor/brotli/c/common/static_init.h +56 -0
  24. data/vendor/brotli/c/common/transform.c +6 -4
  25. data/vendor/brotli/c/common/transform.h +1 -2
  26. data/vendor/brotli/c/common/version.h +3 -3
  27. data/vendor/brotli/c/dec/bit_reader.c +2 -3
  28. data/vendor/brotli/c/dec/bit_reader.h +0 -4
  29. data/vendor/brotli/c/dec/decode.c +128 -39
  30. data/vendor/brotli/c/dec/huffman.c +2 -5
  31. data/vendor/brotli/c/dec/huffman.h +0 -2
  32. data/vendor/brotli/c/dec/prefix.c +67 -0
  33. data/vendor/brotli/c/dec/prefix.h +18 -708
  34. data/vendor/brotli/c/dec/prefix_inc.h +707 -0
  35. data/vendor/brotli/c/dec/state.c +18 -15
  36. data/vendor/brotli/c/dec/state.h +2 -6
  37. data/vendor/brotli/c/dec/static_init.c +53 -0
  38. data/vendor/brotli/c/dec/static_init.h +30 -0
  39. data/vendor/brotli/c/enc/backward_references.c +32 -8
  40. data/vendor/brotli/c/enc/backward_references.h +1 -5
  41. data/vendor/brotli/c/enc/backward_references_hq.c +15 -15
  42. data/vendor/brotli/c/enc/backward_references_hq.h +1 -5
  43. data/vendor/brotli/c/enc/bit_cost.c +28 -4
  44. data/vendor/brotli/c/enc/bit_cost.h +8 -40
  45. data/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
  46. data/vendor/brotli/c/enc/block_splitter.c +9 -12
  47. data/vendor/brotli/c/enc/block_splitter.h +0 -3
  48. data/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
  49. data/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
  50. data/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
  51. data/vendor/brotli/c/enc/cluster.c +0 -2
  52. data/vendor/brotli/c/enc/cluster.h +0 -2
  53. data/vendor/brotli/c/enc/command.c +1 -1
  54. data/vendor/brotli/c/enc/command.h +8 -10
  55. data/vendor/brotli/c/enc/compound_dictionary.c +3 -5
  56. data/vendor/brotli/c/enc/compound_dictionary.h +1 -4
  57. data/vendor/brotli/c/enc/compress_fragment.c +3 -13
  58. data/vendor/brotli/c/enc/compress_fragment.h +0 -2
  59. data/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
  60. data/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
  61. data/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
  62. data/vendor/brotli/c/enc/dictionary_hash.h +23 -3
  63. data/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
  64. data/vendor/brotli/c/enc/encode.c +77 -52
  65. data/vendor/brotli/c/enc/encoder_dict.c +9 -7
  66. data/vendor/brotli/c/enc/encoder_dict.h +2 -4
  67. data/vendor/brotli/c/enc/entropy_encode.c +3 -6
  68. data/vendor/brotli/c/enc/entropy_encode.h +2 -4
  69. data/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
  70. data/vendor/brotli/c/enc/fast_log.c +1 -1
  71. data/vendor/brotli/c/enc/fast_log.h +2 -3
  72. data/vendor/brotli/c/enc/find_match_length.h +0 -2
  73. data/vendor/brotli/c/enc/hash.h +38 -31
  74. data/vendor/brotli/c/enc/hash_base.h +38 -0
  75. data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
  76. data/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
  77. data/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
  78. data/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
  79. data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
  80. data/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
  81. data/vendor/brotli/c/enc/histogram.c +1 -0
  82. data/vendor/brotli/c/enc/histogram.h +0 -4
  83. data/vendor/brotli/c/enc/literal_cost.c +4 -6
  84. data/vendor/brotli/c/enc/literal_cost.h +0 -2
  85. data/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
  86. data/vendor/brotli/c/enc/memory.c +0 -5
  87. data/vendor/brotli/c/enc/memory.h +0 -4
  88. data/vendor/brotli/c/enc/metablock.c +7 -9
  89. data/vendor/brotli/c/enc/metablock.h +3 -3
  90. data/vendor/brotli/c/enc/metablock_inc.h +4 -4
  91. data/vendor/brotli/c/enc/params.h +0 -1
  92. data/vendor/brotli/c/enc/prefix.h +0 -2
  93. data/vendor/brotli/c/enc/quality.h +17 -10
  94. data/vendor/brotli/c/enc/ringbuffer.h +1 -4
  95. data/vendor/brotli/c/enc/state.h +2 -2
  96. data/vendor/brotli/c/enc/static_dict.c +5 -11
  97. data/vendor/brotli/c/enc/static_dict.h +1 -3
  98. data/vendor/brotli/c/enc/static_dict_lut.c +224 -0
  99. data/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
  100. data/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
  101. data/vendor/brotli/c/enc/static_init.c +59 -0
  102. data/vendor/brotli/c/enc/static_init.h +30 -0
  103. data/vendor/brotli/c/enc/utf8_util.c +1 -1
  104. data/vendor/brotli/c/enc/utf8_util.h +0 -2
  105. data/vendor/brotli/c/enc/write_bits.h +0 -2
  106. data/vendor/brotli/c/include/brotli/decode.h +1 -1
  107. data/vendor/brotli/c/include/brotli/encode.h +5 -1
  108. data/vendor/brotli/c/include/brotli/port.h +4 -7
  109. data/vendor/brotli/c/include/brotli/types.h +2 -2
  110. metadata +24 -28
  111. data/.github/workflows/main.yml +0 -37
  112. data/.github/workflows/publish.yml +0 -24
  113. data/.gitignore +0 -18
  114. data/.gitmodules +0 -3
  115. data/.rspec +0 -2
  116. data/Dockerfile +0 -38
  117. data/Gemfile +0 -10
  118. data/Rakefile +0 -42
  119. data/bin/before_install.sh +0 -9
  120. data/bin/console +0 -14
  121. data/bin/setup +0 -8
  122. data/brotli.gemspec +0 -27
  123. data/smoke.sh +0 -8
  124. data/test/brotli_test.rb +0 -183
  125. data/test/brotli_writer_test.rb +0 -93
  126. data/test/test_helper.rb +0 -9
  127. data/vendor/brotli/c/common/dictionary.bin +0 -432
  128. data/vendor/brotli/c/common/dictionary.bin.br +0 -0
data/test/brotli_test.rb DELETED
@@ -1,183 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class BrotliTest < Test::Unit::TestCase
6
- def testdata
7
- @testdata ||= File.binread(
8
- File.expand_path(File.join("..", "vendor", "brotli", "tests", "testdata", "alice29.txt"), __dir__)
9
- )
10
- end
11
-
12
- test "VERSION" do
13
- assert do
14
- ::Brotli.const_defined?(:VERSION)
15
- end
16
- end
17
-
18
- test "well done" do
19
- property_of { string }.check do |string|
20
- assert_equal string, Brotli.inflate(Brotli.deflate(string.dup))
21
- end
22
- end
23
-
24
- test ".version" do
25
- assert do
26
- puts "Brotli version: #{Brotli.version}"
27
- ["1.1.0", "1.0.9"].include? Brotli.version
28
- end
29
- end
30
-
31
- sub_test_case ".deflate" do
32
- test "works" do
33
- property_of {
34
- [choose(nil, :generic, :text, :font), range(0, 11), range(10, 24), range(16, 24)]
35
- }.check do |(mode, quality, lgwin, lgblock)|
36
- assert_nothing_raised ArgumentError do
37
- Brotli.deflate(
38
- testdata,
39
- mode: mode, quality: quality, lgwin: lgwin, lgblock: lgblock
40
- )
41
- end
42
- end
43
- end
44
-
45
- test "raise ArgumentError if given invalid options" do
46
- assert_raise ArgumentError do
47
- Brotli.deflate(testdata, mode: "generic")
48
- end
49
- assert_raise ArgumentError do
50
- Brotli.deflate(testdata, quality: 12)
51
- end
52
- assert_raise ArgumentError do
53
- Brotli.deflate(testdata, lgwin: 9)
54
- end
55
- assert_raise ArgumentError do
56
- Brotli.deflate(testdata, lgwin: 25)
57
- end
58
- assert_raise ArgumentError do
59
- Brotli.deflate(testdata, lgblock: 15)
60
- end
61
- assert_raise ArgumentError do
62
- Brotli.deflate(testdata, lgblock: 25)
63
- end
64
- assert_raise TypeError do
65
- Brotli.deflate(testdata, 42)
66
- end
67
- end
68
- end
69
-
70
- sub_test_case ".inflate" do
71
- def testdata2
72
- @testdata2 ||= File.binread(
73
- File.expand_path(File.join("..", "vendor", "brotli", "tests", "testdata", "alice29.txt.compressed"), __dir__)
74
- )
75
- end
76
-
77
- test "works" do
78
- assert_equal testdata, Brotli.inflate(testdata2)
79
- end
80
-
81
- test "works with StringIO" do
82
- testdata3 = StringIO.new testdata2
83
- assert_equal testdata, Brotli.inflate(testdata3)
84
- end
85
-
86
- test "works with File" do
87
- f = File.open(File.expand_path(File.join("..", "vendor", "brotli", "tests", "testdata", "alice29.txt.compressed"), __dir__))
88
- assert_equal testdata, Brotli.inflate(f)
89
- end
90
-
91
- test "raise error when pass insufficient data" do
92
- assert_raise Brotli::Error do
93
- Brotli.inflate(testdata2[0, 64])
94
- end
95
- end
96
-
97
- test "raise error when pass invalid data" do
98
- assert_raise Brotli::Error do
99
- Brotli.inflate(testdata2.reverse)
100
- end
101
- end
102
- end
103
-
104
- sub_test_case "dictionary support" do
105
- def setup
106
- omit "Dictionary tests are skipped" if Brotli.version < "1.1.0"
107
- end
108
-
109
- def dictionary_data
110
- "The quick brown fox jumps over the lazy dog"
111
- end
112
-
113
- def repetitive_data
114
- dictionary_data * 10
115
- end
116
-
117
- test "deflate with dictionary produces smaller output" do
118
- compressed_no_dict = Brotli.deflate(repetitive_data)
119
- compressed_with_dict = Brotli.deflate(repetitive_data, dictionary: dictionary_data)
120
-
121
- assert compressed_with_dict.bytesize < compressed_no_dict.bytesize
122
- end
123
-
124
- test "inflate with matching dictionary works" do
125
- compressed = Brotli.deflate(repetitive_data, dictionary: dictionary_data)
126
- decompressed = Brotli.inflate(compressed, dictionary: dictionary_data)
127
-
128
- assert_equal repetitive_data, decompressed
129
- end
130
-
131
- test "inflate without dictionary fails on dictionary-compressed data" do
132
- compressed = Brotli.deflate(repetitive_data, dictionary: dictionary_data)
133
-
134
- assert_raise Brotli::Error do
135
- Brotli.inflate(compressed)
136
- end
137
- end
138
-
139
- test "inflate with wrong dictionary fails" do
140
- compressed = Brotli.deflate(repetitive_data, dictionary: dictionary_data)
141
- wrong_dict = "A completely different dictionary"
142
-
143
- assert_raise Brotli::Error do
144
- Brotli.inflate(compressed, dictionary: wrong_dict)
145
- end
146
- end
147
-
148
- test "deflate and inflate work with binary dictionary" do
149
- binary_dict = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09" * 10
150
- data = "Test data " * 100 + binary_dict
151
-
152
- compressed = Brotli.deflate(data, dictionary: binary_dict)
153
- decompressed = Brotli.inflate(compressed, dictionary: binary_dict)
154
-
155
- assert_equal data, decompressed
156
- end
157
-
158
- test "deflate with dictionary and other options" do
159
- compressed = Brotli.deflate(repetitive_data,
160
- dictionary: dictionary_data,
161
- quality: 11,
162
- mode: :text)
163
- decompressed = Brotli.inflate(compressed, dictionary: dictionary_data)
164
-
165
- assert_equal repetitive_data, decompressed
166
- end
167
- end
168
-
169
- sub_test_case "Ractor safe" do
170
- test "able to invoke non-main ractor" do
171
- unless defined? ::Ractor
172
- notify "Ractor not defined"
173
- omit
174
- end
175
- ractors = Array.new(2) do
176
- Ractor.new(testdata) do |testdata|
177
- Brotli.inflate(Brotli.deflate(testdata)) == testdata
178
- end
179
- end
180
- assert_equal [true, true], ractors.map(&:take)
181
- end
182
- end
183
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
- require "tempfile"
5
-
6
- class BrotliWriterTest < Test::Unit::TestCase
7
- def setup
8
- @tempfile = Tempfile.new
9
- end
10
-
11
- def cleanup
12
- @tempfile.close!
13
- end
14
-
15
- def testdata
16
- @testdata ||= File.binread(
17
- File.expand_path(File.join("..", "vendor", "brotli", "tests", "testdata", "alice29.txt"), __dir__)
18
- )
19
- end
20
-
21
- test "works" do
22
- writer = Brotli::Writer.new @tempfile
23
- assert_equal testdata.bytesize, writer.write(testdata)
24
- assert_equal @tempfile, writer.close
25
- assert_equal true, @tempfile.closed?
26
-
27
- @tempfile.open
28
- assert_equal testdata, Brotli.inflate(@tempfile.read)
29
- end
30
-
31
- test "raise" do
32
- assert_raise do
33
- Brotli::Writer.new nil
34
- end
35
- end
36
-
37
- test "works with dictionary" do
38
- omit_if(Brotli.version < "1.1.0", "Dictionary tests are skipped")
39
-
40
- dictionary = "The quick brown fox jumps over the lazy dog"
41
- data = dictionary * 10
42
-
43
- writer = Brotli::Writer.new @tempfile, dictionary: dictionary
44
- assert_equal data.bytesize, writer.write(data)
45
- assert_equal @tempfile, writer.close
46
-
47
- @tempfile.open
48
- compressed = @tempfile.read
49
- decompressed = Brotli.inflate(compressed, dictionary: dictionary)
50
- assert_equal data, decompressed
51
- end
52
-
53
- test "writer with dictionary produces smaller output" do
54
- omit_if(Brotli.version < "1.1.0", "Dictionary tests are skipped")
55
-
56
- dictionary = "The quick brown fox jumps over the lazy dog"
57
- data = dictionary * 10
58
-
59
- # Without dictionary
60
- @tempfile.rewind
61
- writer_no_dict = Brotli::Writer.new @tempfile
62
- writer_no_dict.write(data)
63
- writer_no_dict.close
64
- size_no_dict = @tempfile.size
65
-
66
- # With dictionary
67
- tempfile2 = Tempfile.new
68
- writer_with_dict = Brotli::Writer.new tempfile2, dictionary: dictionary
69
- writer_with_dict.write(data)
70
- writer_with_dict.close
71
- size_with_dict = tempfile2.size
72
-
73
- assert size_with_dict < size_no_dict
74
-
75
- tempfile2.close!
76
- end
77
-
78
- test "writer with dictionary and other options" do
79
- omit_if(Brotli.version < "1.1.0", "Dictionary tests are skipped")
80
-
81
- dictionary = "compression dictionary"
82
- data = "test data " * 100 + dictionary * 5
83
-
84
- writer = Brotli::Writer.new @tempfile, dictionary: dictionary, quality: 11, mode: :text
85
- writer.write(data)
86
- writer.finish
87
- writer.close
88
-
89
- @tempfile.open
90
- decompressed = Brotli.inflate(@tempfile.read, dictionary: dictionary)
91
- assert_equal data, decompressed
92
- end
93
- end
data/test/test_helper.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "brotli"
5
-
6
- require "test-unit"
7
- require "test/unit/rr"
8
- require "rantly/testunit_extensions"
9
- require "stringio"