ruby-brs 1.2.0 → 1.2.1
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.
- checksums.yaml +4 -4
- data/README.md +35 -14
- data/ext/brs_ext/error.c +11 -11
- data/ext/extconf.rb +1 -1
- data/lib/brs/file.rb +2 -2
- data/lib/brs/option.rb +10 -4
- data/lib/brs/stream/abstract.rb +5 -3
- data/lib/brs/stream/reader.rb +3 -2
- data/lib/brs/stream/reader_helpers.rb +1 -1
- data/lib/brs/validation.rb +3 -1
- data/lib/brs/version.rb +1 -1
- metadata +55 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7c98f5678a0545688d9a0bb7537d2eb55507559c2f6d61855796983e4b8a763
|
4
|
+
data.tar.gz: 19bbed82c75ecf25c17a7848b97890dfad5387a3d9244b16db2447bb21425c1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7a82e47ac99a515794cc5e56153d10993b5b87fdb9f091dd04a685689dadcee2aec961b2cefbd1fd9531c457cd45af5d0d05af87178642b5bb545fa2f9f9246
|
7
|
+
data.tar.gz: 481e233bfd17fe958a384787b2dd0f469b9017d7005cb9c1b88bdf48cad578767c5003e52b53ce6fcda35635a57339115a6cd21f0768281626df99995ee308ee
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Ruby bindings for brotli library
|
2
2
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
| [](https://ci.appveyor.com/project/andrew-aladev/ruby-brs/branch/master) | [](https://circleci.com/gh/andrew-aladev/ruby-brs/tree/master) | [](https://github.com/andrew-aladev/ruby-brs/actions) | [](https://codecov.io/gh/andrew-aladev/ruby-brs) | [](https://rubygems.org/gems/ruby-brs) |
|
6
6
|
|
7
7
|
See [brotli library](https://github.com/google/brotli).
|
8
8
|
|
@@ -61,7 +61,7 @@ ensure
|
|
61
61
|
end
|
62
62
|
```
|
63
63
|
|
64
|
-
You can create and read `tar.br` archives with [minitar](https://github.com/halostatue/minitar)
|
64
|
+
You can create and read `tar.br` archives with [minitar](https://github.com/halostatue/minitar).
|
65
65
|
|
66
66
|
```ruby
|
67
67
|
require "brs"
|
@@ -95,6 +95,18 @@ get "/" do
|
|
95
95
|
end
|
96
96
|
```
|
97
97
|
|
98
|
+
All functionality (including streaming) can be used inside multiple threads with [parallel](https://github.com/grosser/parallel).
|
99
|
+
This code will provide heavy load for your CPU.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
require "brs"
|
103
|
+
require "parallel"
|
104
|
+
|
105
|
+
Parallel.each large_datas do |large_data|
|
106
|
+
BRS::String.compress large_data
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
98
110
|
## Options
|
99
111
|
|
100
112
|
| Option | Values | Default | Description |
|
@@ -186,7 +198,7 @@ File maintains both source and destination buffers, it accepts both `source_buff
|
|
186
198
|
|
187
199
|
## Stream::Writer
|
188
200
|
|
189
|
-
Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib
|
201
|
+
Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
|
190
202
|
|
191
203
|
Writer maintains destination buffer only, so it accepts `destination_buffer_length` option only.
|
192
204
|
|
@@ -224,7 +236,7 @@ Set another encodings, `nil` is just for compatibility with `IO`.
|
|
224
236
|
#tell
|
225
237
|
```
|
226
238
|
|
227
|
-
See [`IO`](https://ruby-doc.org/core
|
239
|
+
See [`IO`](https://ruby-doc.org/core/IO.html) docs.
|
228
240
|
|
229
241
|
```
|
230
242
|
#write(*objects)
|
@@ -234,7 +246,7 @@ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
|
234
246
|
#closed?
|
235
247
|
```
|
236
248
|
|
237
|
-
See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib
|
249
|
+
See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
|
238
250
|
|
239
251
|
```
|
240
252
|
#write_nonblock(object, *options)
|
@@ -248,6 +260,9 @@ Special asynchronous methods missing in `Zlib::GzipWriter`.
|
|
248
260
|
So it is possible to have asynchronous variants for these synchronous methods.
|
249
261
|
Behaviour is the same as `IO#write_nonblock` method.
|
250
262
|
|
263
|
+
All nonblock operations for file will raise `EBADF` error on Windows.
|
264
|
+
Setting file into nonblocking mode is [not available on Windows](https://github.com/ruby/ruby/blob/master/win32/win32.c#L4388).
|
265
|
+
|
251
266
|
```
|
252
267
|
#<<(object)
|
253
268
|
#print(*objects)
|
@@ -256,11 +271,11 @@ Behaviour is the same as `IO#write_nonblock` method.
|
|
256
271
|
#puts(*objects)
|
257
272
|
```
|
258
273
|
|
259
|
-
Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib
|
274
|
+
Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
|
260
275
|
|
261
276
|
## Stream::Reader
|
262
277
|
|
263
|
-
Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib
|
278
|
+
Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipReader.html).
|
264
279
|
|
265
280
|
Reader maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
|
266
281
|
|
@@ -295,7 +310,7 @@ Set another encodings.
|
|
295
310
|
#tell
|
296
311
|
```
|
297
312
|
|
298
|
-
See [`IO`](https://ruby-doc.org/core
|
313
|
+
See [`IO`](https://ruby-doc.org/core/IO.html) docs.
|
299
314
|
|
300
315
|
```
|
301
316
|
#read(bytes_to_read = nil, out_buffer = nil)
|
@@ -305,14 +320,14 @@ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
|
305
320
|
#closed?
|
306
321
|
```
|
307
322
|
|
308
|
-
See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib
|
323
|
+
See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
|
309
324
|
|
310
325
|
```
|
311
326
|
#readpartial(bytes_to_read = nil, out_buffer = nil)
|
312
327
|
#read_nonblock(bytes_to_read, out_buffer = nil, *options)
|
313
328
|
```
|
314
329
|
|
315
|
-
See [`IO`](https://ruby-doc.org/core
|
330
|
+
See [`IO`](https://ruby-doc.org/core/IO.html) docs.
|
316
331
|
|
317
332
|
```
|
318
333
|
#getbyte
|
@@ -335,7 +350,7 @@ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
|
335
350
|
#ungetline(line)
|
336
351
|
```
|
337
352
|
|
338
|
-
Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib
|
353
|
+
Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
|
339
354
|
|
340
355
|
## Thread safety
|
341
356
|
|
@@ -343,11 +358,17 @@ Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libd
|
|
343
358
|
Please be careful: bindings are not thread safe.
|
344
359
|
You should lock all shared data between threads.
|
345
360
|
|
361
|
+
For example: you should not use same compressor/decompressor inside multiple threads.
|
362
|
+
Please verify that you are using each processor inside single thread at the same time.
|
363
|
+
|
364
|
+
## Operating systems
|
365
|
+
|
366
|
+
GNU/Linux, FreeBSD, OSX, Windows (MinGW).
|
367
|
+
|
346
368
|
## CI
|
347
369
|
|
348
370
|
Please visit [scripts/test-images](scripts/test-images).
|
349
371
|
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
350
|
-
You can run this script using many native and cross images.
|
351
372
|
|
352
373
|
## License
|
353
374
|
|
data/ext/brs_ext/error.c
CHANGED
@@ -39,7 +39,7 @@ brs_ext_result_t brs_ext_get_decompressor_error(BrotliDecoderErrorCode error_cod
|
|
39
39
|
}
|
40
40
|
}
|
41
41
|
|
42
|
-
static inline NORETURN(void
|
42
|
+
static inline NORETURN(void raise_error(const char* name, const char* description))
|
43
43
|
{
|
44
44
|
VALUE module = rb_define_module(BRS_EXT_MODULE_NAME);
|
45
45
|
VALUE error = rb_const_get(module, rb_intern(name));
|
@@ -50,28 +50,28 @@ void brs_ext_raise_error(brs_ext_result_t ext_result)
|
|
50
50
|
{
|
51
51
|
switch (ext_result) {
|
52
52
|
case BRS_EXT_ERROR_ALLOCATE_FAILED:
|
53
|
-
|
53
|
+
raise_error("AllocateError", "allocate error");
|
54
54
|
case BRS_EXT_ERROR_VALIDATE_FAILED:
|
55
|
-
|
55
|
+
raise_error("ValidateError", "validate error");
|
56
56
|
|
57
57
|
case BRS_EXT_ERROR_USED_AFTER_CLOSE:
|
58
|
-
|
58
|
+
raise_error("UsedAfterCloseError", "used after closed");
|
59
59
|
case BRS_EXT_ERROR_NOT_ENOUGH_SOURCE_BUFFER:
|
60
|
-
|
60
|
+
raise_error("NotEnoughSourceBufferError", "not enough source buffer");
|
61
61
|
case BRS_EXT_ERROR_NOT_ENOUGH_DESTINATION_BUFFER:
|
62
|
-
|
62
|
+
raise_error("NotEnoughDestinationBufferError", "not enough destination buffer");
|
63
63
|
case BRS_EXT_ERROR_DECOMPRESSOR_CORRUPTED_SOURCE:
|
64
|
-
|
64
|
+
raise_error("DecompressorCorruptedSourceError", "decompressor received corrupted source");
|
65
65
|
|
66
66
|
case BRS_EXT_ERROR_ACCESS_IO:
|
67
|
-
|
67
|
+
raise_error("AccessIOError", "failed to access IO");
|
68
68
|
case BRS_EXT_ERROR_READ_IO:
|
69
|
-
|
69
|
+
raise_error("ReadIOError", "failed to read IO");
|
70
70
|
case BRS_EXT_ERROR_WRITE_IO:
|
71
|
-
|
71
|
+
raise_error("WriteIOError", "failed to write IO");
|
72
72
|
|
73
73
|
default:
|
74
74
|
// BRS_EXT_ERROR_UNEXPECTED
|
75
|
-
|
75
|
+
raise_error("UnexpectedError", "unexpected error");
|
76
76
|
}
|
77
77
|
}
|
data/ext/extconf.rb
CHANGED
data/lib/brs/file.rb
CHANGED
@@ -19,7 +19,7 @@ module BRS
|
|
19
19
|
|
20
20
|
options[:size_hint] = ::File.size source
|
21
21
|
|
22
|
-
open_files
|
22
|
+
open_files source, destination do |source_io, destination_io|
|
23
23
|
BRS._native_compress_io source_io, destination_io, options
|
24
24
|
end
|
25
25
|
|
@@ -32,7 +32,7 @@ module BRS
|
|
32
32
|
|
33
33
|
options = Option.get_decompressor_options options, BUFFER_LENGTH_NAMES
|
34
34
|
|
35
|
-
open_files
|
35
|
+
open_files source, destination do |source_io, destination_io|
|
36
36
|
BRS._native_decompress_io source_io, destination_io, options
|
37
37
|
end
|
38
38
|
|
data/lib/brs/option.rb
CHANGED
@@ -31,8 +31,11 @@ module BRS
|
|
31
31
|
def self.get_compressor_options(options, buffer_length_names)
|
32
32
|
Validation.validate_hash options
|
33
33
|
|
34
|
-
buffer_length_defaults = buffer_length_names.each_with_object({})
|
35
|
-
|
34
|
+
buffer_length_defaults = buffer_length_names.each_with_object({}) do |name, defaults|
|
35
|
+
defaults[name] = DEFAULT_BUFFER_LENGTH
|
36
|
+
end
|
37
|
+
|
38
|
+
options = COMPRESSOR_DEFAULTS.merge(buffer_length_defaults).merge options
|
36
39
|
|
37
40
|
buffer_length_names.each { |name| Validation.validate_not_negative_integer options[name] }
|
38
41
|
|
@@ -74,8 +77,11 @@ module BRS
|
|
74
77
|
def self.get_decompressor_options(options, buffer_length_names)
|
75
78
|
Validation.validate_hash options
|
76
79
|
|
77
|
-
buffer_length_defaults = buffer_length_names.each_with_object({})
|
78
|
-
|
80
|
+
buffer_length_defaults = buffer_length_names.each_with_object({}) do |name, defaults|
|
81
|
+
defaults[name] = DEFAULT_BUFFER_LENGTH
|
82
|
+
end
|
83
|
+
|
84
|
+
options = DECOMPRESSOR_DEFAULTS.merge(buffer_length_defaults).merge options
|
79
85
|
|
80
86
|
buffer_length_names.each { |name| Validation.validate_not_negative_integer options[name] }
|
81
87
|
|
data/lib/brs/stream/abstract.rb
CHANGED
@@ -12,7 +12,8 @@ module BRS
|
|
12
12
|
# Native stream is not seekable by design.
|
13
13
|
# Related methods like "seek" and "pos=" can't be implemented.
|
14
14
|
|
15
|
-
# It is not possible to maintain correspondance between bytes
|
15
|
+
# It is not possible to maintain correspondance between bytes
|
16
|
+
# consumed from source and bytes written to destination by design.
|
16
17
|
# We will consume all source bytes and maintain buffer with remaining destination data.
|
17
18
|
|
18
19
|
include Delegates
|
@@ -89,8 +90,9 @@ module BRS
|
|
89
90
|
end
|
90
91
|
|
91
92
|
internal_encoding = args[1]
|
92
|
-
|
93
|
-
|
93
|
+
unless internal_encoding.nil? || internal_encoding.is_a?(::Encoding)
|
94
|
+
Validation.validate_string internal_encoding
|
95
|
+
end
|
94
96
|
|
95
97
|
transcode_options = args[2]
|
96
98
|
Validation.validate_hash transcode_options unless transcode_options.nil?
|
data/lib/brs/stream/reader.rb
CHANGED
@@ -33,8 +33,9 @@ module BRS
|
|
33
33
|
source_buffer_length = @options[:source_buffer_length]
|
34
34
|
Validation.validate_not_negative_integer source_buffer_length unless source_buffer_length.nil?
|
35
35
|
|
36
|
-
source_buffer_length
|
37
|
-
|
36
|
+
if source_buffer_length.nil? || source_buffer_length.zero?
|
37
|
+
source_buffer_length = Buffer::DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR
|
38
|
+
end
|
38
39
|
|
39
40
|
@source_buffer_length = source_buffer_length
|
40
41
|
end
|
data/lib/brs/validation.rb
CHANGED
@@ -47,7 +47,9 @@ module BRS
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def self.validate_proc(value)
|
50
|
-
|
50
|
+
unless value.is_a?(::Proc) || value.is_a?(::Method) || value.is_a?(::UnboundMethod)
|
51
|
+
raise ValidateError, "invalid proc"
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
data/lib/brs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-brs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Aladjev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codecov
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitar
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +72,14 @@ dependencies:
|
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
75
|
+
version: '1.3'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
82
|
+
version: '1.3'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: parallel
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,28 +128,56 @@ dependencies:
|
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
131
|
+
version: '1.16'
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
138
|
+
version: '1.16'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-minitest
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.12'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.12'
|
125
153
|
- !ruby/object:Gem::Dependency
|
126
154
|
name: rubocop-performance
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
128
156
|
requirements:
|
129
157
|
- - "~>"
|
130
158
|
- !ruby/object:Gem::Version
|
131
|
-
version: '1.
|
159
|
+
version: '1.11'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.11'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop-rake
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.5'
|
132
174
|
type: :development
|
133
175
|
prerelease: false
|
134
176
|
version_requirements: !ruby/object:Gem::Requirement
|
135
177
|
requirements:
|
136
178
|
- - "~>"
|
137
179
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
180
|
+
version: '0.5'
|
139
181
|
- !ruby/object:Gem::Dependency
|
140
182
|
name: simplecov
|
141
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,7 +192,7 @@ dependencies:
|
|
150
192
|
- - ">="
|
151
193
|
- !ruby/object:Gem::Version
|
152
194
|
version: '0'
|
153
|
-
description:
|
195
|
+
description:
|
154
196
|
email: aladjev.andrew@gmail.com
|
155
197
|
executables: []
|
156
198
|
extensions:
|
@@ -200,7 +242,7 @@ homepage: https://github.com/andrew-aladev/ruby-brs
|
|
200
242
|
licenses:
|
201
243
|
- MIT
|
202
244
|
metadata: {}
|
203
|
-
post_install_message:
|
245
|
+
post_install_message:
|
204
246
|
rdoc_options: []
|
205
247
|
require_paths:
|
206
248
|
- lib
|
@@ -215,8 +257,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
257
|
- !ruby/object:Gem::Version
|
216
258
|
version: '0'
|
217
259
|
requirements: []
|
218
|
-
rubygems_version: 3.
|
219
|
-
signing_key:
|
260
|
+
rubygems_version: 3.2.15
|
261
|
+
signing_key:
|
220
262
|
specification_version: 4
|
221
263
|
summary: Ruby bindings for brotli library.
|
222
264
|
test_files: []
|