ruby-brs 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHORS +1 -0
- data/README.md +27 -5
- data/ext/brs_ext/gvl.h +2 -2
- data/ext/brs_ext/macro.h +1 -1
- data/lib/brs/stream/abstract.rb +9 -5
- data/lib/brs/stream/reader.rb +9 -0
- data/lib/brs/stream/writer.rb +26 -2
- data/lib/brs/validation.rb +12 -29
- data/lib/brs/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 614baececc4a64311bdd172a962cb5f9bc721b2ade99ed84216ab79908f5a0ca
|
4
|
+
data.tar.gz: 88899da83cd343c1217652b7558a6770e43bd7722f3db7e1e3023ad54888bb54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efb6e0ec7ee97e4d4c6977b6843ee81ae6ec334af2985674634ea31a24ff00373753cc828bbc250ec137700fa721f84e1071fd6486cbbc2db869e4e6850e7255
|
7
|
+
data.tar.gz: 0ad07a2ebbbbbd27ff47a4e2780e90f297f4d02b36107f2877d45863f538b3f9b32b6aab18451a6376f620c6eee50118b6023b405cdb1f7c8079f1b8a295fd82
|
data/AUTHORS
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,17 @@ See [brotli library](https://github.com/google/brotli).
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
|
11
|
+
Operating systems: GNU/Linux, FreeBSD, OSX, Windows (MinGW).
|
12
|
+
|
13
|
+
Dependencies: [brotli](https://github.com/google/brotli) 1.0.0+ version.
|
14
|
+
|
15
|
+
| Popular OS | Dependencies |
|
16
|
+
|------------|---------------------------|
|
17
|
+
| Ubuntu | `libbrotli-dev` |
|
18
|
+
| CentOS | `brotli-devel` |
|
19
|
+
| ArchLinux | `brotli` |
|
20
|
+
| OSX | `brotli` |
|
21
|
+
| Windows | `mingw-w64-x86_64-brotli` |
|
12
22
|
|
13
23
|
```sh
|
14
24
|
gem install ruby-brs
|
@@ -23,6 +33,22 @@ gem install pkg/ruby-brs-*.gem
|
|
23
33
|
|
24
34
|
You can also use [overlay](https://github.com/andrew-aladev/overlay) for gentoo.
|
25
35
|
|
36
|
+
### Installation in macOS on Apple Silicon
|
37
|
+
|
38
|
+
On M1 Macs, Homebrew installs to /opt/homebrew, so you'll need to specify its
|
39
|
+
include and lib paths when building the native extension for brotli.
|
40
|
+
|
41
|
+
```sh
|
42
|
+
brew install brotli
|
43
|
+
gem install ruby-brs -- --with-opt-include=/opt/homebrew/include --with-opt-lib=/opt/homebrew/lib
|
44
|
+
```
|
45
|
+
|
46
|
+
You can also configure Bundler to use those options when installing:
|
47
|
+
|
48
|
+
```sh
|
49
|
+
bundle config set build.ruby-brs "--with-opt-include=/opt/homebrew/include --with-opt-lib=/opt/homebrew/lib"
|
50
|
+
```
|
51
|
+
|
26
52
|
## Usage
|
27
53
|
|
28
54
|
There are simple APIs: `String` and `File`. Also you can use generic streaming API: `Stream::Writer` and `Stream::Reader`.
|
@@ -367,10 +393,6 @@ You should lock all shared data between threads.
|
|
367
393
|
For example: you should not use same compressor/decompressor inside multiple threads.
|
368
394
|
Please verify that you are using each processor inside single thread at the same time.
|
369
395
|
|
370
|
-
## Operating systems
|
371
|
-
|
372
|
-
GNU/Linux, FreeBSD, OSX, Windows (MinGW).
|
373
|
-
|
374
396
|
## CI
|
375
397
|
|
376
398
|
Please visit [scripts/test-images](scripts/test-images).
|
data/ext/brs_ext/gvl.h
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#if !defined(BRS_EXT_GVL_H)
|
5
5
|
#define BRS_EXT_GVL_H
|
6
6
|
|
7
|
-
#
|
7
|
+
#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
|
8
8
|
|
9
9
|
#include "ruby/thread.h"
|
10
10
|
|
@@ -19,6 +19,6 @@
|
|
19
19
|
|
20
20
|
#define BRS_EXT_GVL_WRAP(_gvl, function, data) function((void*) data);
|
21
21
|
|
22
|
-
#endif
|
22
|
+
#endif // HAVE_RB_THREAD_CALL_WITHOUT_GVL
|
23
23
|
|
24
24
|
#endif // BRS_EXT_GVL_H
|
data/ext/brs_ext/macro.h
CHANGED
data/lib/brs/stream/abstract.rb
CHANGED
@@ -24,9 +24,7 @@ module BRS
|
|
24
24
|
|
25
25
|
def initialize(io, options = {})
|
26
26
|
@raw_stream = create_raw_stream
|
27
|
-
|
28
|
-
Validation.validate_io io
|
29
|
-
@io = io
|
27
|
+
@io = io
|
30
28
|
|
31
29
|
@stat = Stat.new @io.stat if @io.respond_to? :stat
|
32
30
|
|
@@ -135,13 +133,19 @@ module BRS
|
|
135
133
|
end
|
136
134
|
|
137
135
|
def close
|
138
|
-
@io.close
|
136
|
+
@io.close if @io.respond_to? :close
|
139
137
|
|
140
138
|
nil
|
141
139
|
end
|
142
140
|
|
143
141
|
def closed?
|
144
|
-
|
142
|
+
return false unless @raw_stream.closed?
|
143
|
+
|
144
|
+
if @io.respond_to? :closed
|
145
|
+
@io.closed?
|
146
|
+
else
|
147
|
+
true
|
148
|
+
end
|
145
149
|
end
|
146
150
|
|
147
151
|
def to_io
|
data/lib/brs/stream/reader.rb
CHANGED
@@ -54,6 +54,9 @@ module BRS
|
|
54
54
|
Validation.validate_not_negative_integer bytes_to_read unless bytes_to_read.nil?
|
55
55
|
Validation.validate_string out_buffer unless out_buffer.nil?
|
56
56
|
|
57
|
+
raise ValidateError, "io should be responsible to read and eof" unless
|
58
|
+
@io.respond_to?(:read) && @io.respond_to?(:eof?)
|
59
|
+
|
57
60
|
unless bytes_to_read.nil?
|
58
61
|
return ::String.new :encoding => ::Encoding::BINARY if bytes_to_read.zero?
|
59
62
|
return nil if eof?
|
@@ -86,16 +89,22 @@ module BRS
|
|
86
89
|
end
|
87
90
|
|
88
91
|
def eof?
|
92
|
+
raise ValidateError, "io should be responsible to eof" unless @io.respond_to? :eof?
|
93
|
+
|
89
94
|
empty? && @io.eof?
|
90
95
|
end
|
91
96
|
|
92
97
|
# -- asynchronous --
|
93
98
|
|
94
99
|
def readpartial(bytes_to_read, out_buffer = nil)
|
100
|
+
raise ValidateError, "io should be responsible to readpartial" unless @io.respond_to? :readpartial
|
101
|
+
|
95
102
|
read_more_nonblock(bytes_to_read, out_buffer) { @io.readpartial @source_buffer_length }
|
96
103
|
end
|
97
104
|
|
98
105
|
def read_nonblock(bytes_to_read, out_buffer = nil, *options)
|
106
|
+
raise ValidateError, "io should be responsible to read nonblock" unless @io.respond_to? :read_nonblock
|
107
|
+
|
99
108
|
read_more_nonblock(bytes_to_read, out_buffer) { @io.read_nonblock(@source_buffer_length, *options) }
|
100
109
|
end
|
101
110
|
|
data/lib/brs/stream/writer.rb
CHANGED
@@ -23,6 +23,8 @@ module BRS
|
|
23
23
|
# -- synchronous --
|
24
24
|
|
25
25
|
def write(*objects)
|
26
|
+
validate_write
|
27
|
+
|
26
28
|
write_remaining_buffer
|
27
29
|
|
28
30
|
bytes_written = 0
|
@@ -38,20 +40,26 @@ module BRS
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def flush
|
43
|
+
validate_write
|
44
|
+
|
41
45
|
finish :flush
|
42
46
|
|
43
|
-
@io.flush
|
47
|
+
@io.flush if @io.respond_to? :flush
|
44
48
|
|
45
49
|
self
|
46
50
|
end
|
47
51
|
|
48
52
|
def rewind
|
53
|
+
validate_write
|
54
|
+
|
49
55
|
finish :close
|
50
56
|
|
51
57
|
super
|
52
58
|
end
|
53
59
|
|
54
60
|
def close
|
61
|
+
validate_write
|
62
|
+
|
55
63
|
finish :close
|
56
64
|
|
57
65
|
super
|
@@ -75,6 +83,10 @@ module BRS
|
|
75
83
|
@raw_stream.send(method_name, *args) { |portion| @io.write portion }
|
76
84
|
end
|
77
85
|
|
86
|
+
def validate_write
|
87
|
+
raise ValidateError, "io should be responsible to write" unless @io.respond_to? :write
|
88
|
+
end
|
89
|
+
|
78
90
|
# -- asynchronous --
|
79
91
|
|
80
92
|
# IO write nonblock can raise wait writable error.
|
@@ -83,6 +95,8 @@ module BRS
|
|
83
95
|
# So we have to accept content after processing IO write nonblock.
|
84
96
|
# It means that first write nonblock won't call IO write nonblock.
|
85
97
|
def write_nonblock(object, *options)
|
98
|
+
validate_write_nonblock
|
99
|
+
|
86
100
|
return 0 unless write_remaining_buffer_nonblock(*options)
|
87
101
|
|
88
102
|
source = transcode object.to_s
|
@@ -93,14 +107,18 @@ module BRS
|
|
93
107
|
end
|
94
108
|
|
95
109
|
def flush_nonblock(*options)
|
110
|
+
validate_write_nonblock
|
111
|
+
|
96
112
|
return false unless finish_nonblock :flush, *options
|
97
113
|
|
98
|
-
@io.flush
|
114
|
+
@io.flush if @io.respond_to? :flush
|
99
115
|
|
100
116
|
true
|
101
117
|
end
|
102
118
|
|
103
119
|
def rewind_nonblock(*options)
|
120
|
+
validate_write_nonblock
|
121
|
+
|
104
122
|
return false unless finish_nonblock :close, *options
|
105
123
|
|
106
124
|
method(:rewind).super_method.call
|
@@ -109,6 +127,8 @@ module BRS
|
|
109
127
|
end
|
110
128
|
|
111
129
|
def close_nonblock(*options)
|
130
|
+
validate_write_nonblock
|
131
|
+
|
112
132
|
return false unless finish_nonblock :close, *options
|
113
133
|
|
114
134
|
method(:close).super_method.call
|
@@ -139,6 +159,10 @@ module BRS
|
|
139
159
|
@raw_stream.send(method_name, *args) { |portion| @buffer << portion }
|
140
160
|
end
|
141
161
|
|
162
|
+
def validate_write_nonblock
|
163
|
+
raise ValidateError, "io should be responsible to write nonblock" unless @io.respond_to? :write_nonblock
|
164
|
+
end
|
165
|
+
|
142
166
|
# -- common --
|
143
167
|
|
144
168
|
protected def transcode(data)
|
data/lib/brs/validation.rb
CHANGED
@@ -5,45 +5,20 @@ require_relative "error"
|
|
5
5
|
|
6
6
|
module BRS
|
7
7
|
module Validation
|
8
|
-
IO_METHODS = %i[
|
9
|
-
read
|
10
|
-
write
|
11
|
-
readpartial
|
12
|
-
read_nonblock
|
13
|
-
write_nonblock
|
14
|
-
eof?
|
15
|
-
flush
|
16
|
-
close
|
17
|
-
closed?
|
18
|
-
]
|
19
|
-
.freeze
|
20
|
-
|
21
8
|
def self.validate_bool(value)
|
22
9
|
raise ValidateError, "invalid bool" unless value.is_a?(::TrueClass) || value.is_a?(::FalseClass)
|
23
10
|
end
|
24
11
|
|
25
|
-
def self.
|
26
|
-
raise ValidateError, "invalid
|
12
|
+
def self.validate_hash(value)
|
13
|
+
raise ValidateError, "invalid hash" unless value.is_a? ::Hash
|
27
14
|
end
|
28
15
|
|
29
16
|
def self.validate_not_negative_integer(value)
|
30
17
|
raise ValidateError, "invalid not negative integer" unless value.is_a?(::Integer) && value >= 0
|
31
18
|
end
|
32
19
|
|
33
|
-
def self.
|
34
|
-
raise ValidateError, "invalid
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.validate_symbol(value)
|
38
|
-
raise ValidateError, "invalid symbol" unless value.is_a? ::Symbol
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.validate_io(value)
|
42
|
-
raise ValidateError, "invalid io" unless IO_METHODS.all? { |method| value.respond_to? method }
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.validate_hash(value)
|
46
|
-
raise ValidateError, "invalid hash" unless value.is_a? ::Hash
|
20
|
+
def self.validate_positive_integer(value)
|
21
|
+
raise ValidateError, "invalid positive integer" unless value.is_a?(::Integer) && value.positive?
|
47
22
|
end
|
48
23
|
|
49
24
|
def self.validate_proc(value)
|
@@ -51,5 +26,13 @@ module BRS
|
|
51
26
|
raise ValidateError, "invalid proc"
|
52
27
|
end
|
53
28
|
end
|
29
|
+
|
30
|
+
def self.validate_string(value)
|
31
|
+
raise ValidateError, "invalid string" unless value.is_a? ::String
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.validate_symbol(value)
|
35
|
+
raise ValidateError, "invalid symbol" unless value.is_a? ::Symbol
|
36
|
+
end
|
54
37
|
end
|
55
38
|
end
|
data/lib/brs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-brs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Aladjev
|
8
|
+
- Jenner La Fave
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2022-
|
12
|
+
date: 2022-03-18 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: codecov
|
@@ -128,14 +129,14 @@ dependencies:
|
|
128
129
|
requirements:
|
129
130
|
- - "~>"
|
130
131
|
- !ruby/object:Gem::Version
|
131
|
-
version: '1.
|
132
|
+
version: '1.26'
|
132
133
|
type: :development
|
133
134
|
prerelease: false
|
134
135
|
version_requirements: !ruby/object:Gem::Requirement
|
135
136
|
requirements:
|
136
137
|
- - "~>"
|
137
138
|
- !ruby/object:Gem::Version
|
138
|
-
version: '1.
|
139
|
+
version: '1.26'
|
139
140
|
- !ruby/object:Gem::Dependency
|
140
141
|
name: rubocop-minitest
|
141
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -258,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
259
|
- !ruby/object:Gem::Version
|
259
260
|
version: '0'
|
260
261
|
requirements: []
|
261
|
-
rubygems_version: 3.3.
|
262
|
+
rubygems_version: 3.3.7
|
262
263
|
signing_key:
|
263
264
|
specification_version: 4
|
264
265
|
summary: Ruby bindings for brotli library.
|