ruby-brs 1.3.0 → 1.3.3

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.
@@ -1,186 +1,16 @@
1
1
  # Ruby bindings for brotli library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
- require_relative "abstract"
4
+ require "adsp/stream/reader"
5
+
5
6
  require_relative "raw/decompressor"
6
- require_relative "reader_helpers"
7
- require_relative "../validation"
8
7
 
9
8
  module BRS
10
9
  module Stream
11
- class Reader < Abstract
12
- include ReaderHelpers
13
-
14
- attr_accessor :lineno
15
-
16
- def initialize(source_io, options = {}, *args)
17
- @options = options
18
-
19
- super source_io, *args
20
-
21
- initialize_source_buffer_length
22
- reset_io_remainder
23
- reset_need_to_flush
24
-
25
- @lineno = 0
26
- end
27
-
28
- protected def create_raw_stream
29
- Raw::Decompressor.new @options
30
- end
31
-
32
- protected def initialize_source_buffer_length
33
- source_buffer_length = @options[:source_buffer_length]
34
- Validation.validate_not_negative_integer source_buffer_length unless source_buffer_length.nil?
35
-
36
- if source_buffer_length.nil? || source_buffer_length.zero?
37
- source_buffer_length = Buffer::DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR
38
- end
39
-
40
- @source_buffer_length = source_buffer_length
41
- end
42
-
43
- protected def reset_io_remainder
44
- @io_remainder = ::String.new :encoding => ::Encoding::BINARY
45
- end
46
-
47
- protected def reset_need_to_flush
48
- @need_to_flush = false
49
- end
50
-
51
- # -- synchronous --
52
-
53
- def read(bytes_to_read = nil, out_buffer = nil)
54
- Validation.validate_not_negative_integer bytes_to_read unless bytes_to_read.nil?
55
- Validation.validate_string out_buffer unless out_buffer.nil?
56
-
57
- unless bytes_to_read.nil?
58
- return ::String.new :encoding => ::Encoding::BINARY if bytes_to_read.zero?
59
- return nil if eof?
60
-
61
- append_io_data @io.read(@source_buffer_length) while @buffer.bytesize < bytes_to_read && !@io.eof?
62
- flush_io_data if @buffer.bytesize < bytes_to_read
63
-
64
- return read_bytes_from_buffer bytes_to_read, out_buffer
65
- end
66
-
67
- append_io_data @io.read(@source_buffer_length) until @io.eof?
68
- flush_io_data
69
-
70
- read_buffer out_buffer
71
- end
72
-
73
- def rewind
74
- raw_wrapper :close
75
-
76
- reset_io_remainder
77
- reset_need_to_flush
78
-
79
- super
80
- end
81
-
82
- def close
83
- raw_wrapper :close
84
-
85
- super
86
- end
87
-
88
- def eof?
89
- empty? && @io.eof?
90
- end
91
-
92
- # -- asynchronous --
93
-
94
- def readpartial(bytes_to_read, out_buffer = nil)
95
- read_more_nonblock(bytes_to_read, out_buffer) { @io.readpartial @source_buffer_length }
96
- end
97
-
98
- def read_nonblock(bytes_to_read, out_buffer = nil, *options)
99
- read_more_nonblock(bytes_to_read, out_buffer) { @io.read_nonblock(@source_buffer_length, *options) }
100
- end
101
-
102
- protected def read_more_nonblock(bytes_to_read, out_buffer, &_block)
103
- Validation.validate_not_negative_integer bytes_to_read
104
- Validation.validate_string out_buffer unless out_buffer.nil?
105
-
106
- return ::String.new :encoding => ::Encoding::BINARY if bytes_to_read.zero?
107
-
108
- io_provided_eof_error = false
109
-
110
- if @buffer.bytesize < bytes_to_read
111
- begin
112
- append_io_data yield
113
- rescue ::EOFError
114
- io_provided_eof_error = true
115
- end
116
- end
117
-
118
- flush_io_data if @buffer.bytesize < bytes_to_read
119
- raise ::EOFError if empty? && io_provided_eof_error
120
-
121
- read_bytes_from_buffer bytes_to_read, out_buffer
122
- end
123
-
124
- # -- common --
125
-
126
- protected def append_io_data(io_data)
127
- io_portion = @io_remainder + io_data
128
- bytes_read = raw_wrapper :read, io_portion
129
- @io_remainder = io_portion.byteslice bytes_read, io_portion.bytesize - bytes_read
130
-
131
- # Even empty io data may require flush.
132
- @need_to_flush = true
133
- end
134
-
135
- protected def flush_io_data
136
- raw_wrapper :flush
137
-
138
- @need_to_flush = false
139
- end
140
-
141
- protected def empty?
142
- !@need_to_flush && @buffer.bytesize.zero?
143
- end
144
-
145
- protected def read_bytes_from_buffer(bytes_to_read, out_buffer)
146
- bytes_read = [@buffer.bytesize, bytes_to_read].min
147
-
148
- # Result uses buffer binary encoding.
149
- result = @buffer.byteslice 0, bytes_read
150
- @buffer = @buffer.byteslice bytes_read, @buffer.bytesize - bytes_read
151
- @pos += bytes_read
152
-
153
- result = out_buffer.replace result unless out_buffer.nil?
154
- result
155
- end
156
-
157
- protected def read_buffer(out_buffer)
158
- result = @buffer
159
- reset_buffer
160
- @pos += result.bytesize
161
-
162
- result.force_encoding @external_encoding unless @external_encoding.nil?
163
- result = transcode_to_internal result
164
-
165
- result = out_buffer.replace result unless out_buffer.nil?
166
- result
167
- end
168
-
169
- protected def transcode_to_internal(data)
170
- data = data.encode @internal_encoding, **@transcode_options unless @internal_encoding.nil?
171
- data
172
- end
173
-
174
- # We should be able to return data back to buffer.
175
- # We won't use any transcode options because transcoded data should be backward compatible.
176
- protected def transcode_to_external(data)
177
- data = data.encode @external_encoding unless @external_encoding.nil?
178
- data
179
- end
180
-
181
- protected def raw_wrapper(method_name, *args)
182
- @raw_stream.send(method_name, *args) { |portion| @buffer << portion }
183
- end
10
+ # BRS::Stream::Reader class.
11
+ class Reader < ADSP::Stream::Reader
12
+ # Current raw stream class.
13
+ RawDecompressor = Raw::Decompressor
184
14
  end
185
15
  end
186
16
  end
@@ -1,150 +1,16 @@
1
1
  # Ruby bindings for brotli library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
- require_relative "abstract"
4
+ require "adsp/stream/writer"
5
+
5
6
  require_relative "raw/compressor"
6
- require_relative "writer_helpers"
7
7
 
8
8
  module BRS
9
9
  module Stream
10
- class Writer < Abstract
11
- include WriterHelpers
12
-
13
- def initialize(destination_io, options = {}, *args)
14
- @options = options
15
-
16
- super destination_io, *args
17
- end
18
-
19
- protected def create_raw_stream
20
- Raw::Compressor.new @options
21
- end
22
-
23
- # -- synchronous --
24
-
25
- def write(*objects)
26
- write_remaining_buffer
27
-
28
- bytes_written = 0
29
-
30
- objects.each do |object|
31
- source = transcode object.to_s
32
- bytes_written += raw_wrapper :write, source
33
- end
34
-
35
- @pos += bytes_written
36
-
37
- bytes_written
38
- end
39
-
40
- def flush
41
- finish :flush
42
-
43
- @io.flush
44
-
45
- self
46
- end
47
-
48
- def rewind
49
- finish :close
50
-
51
- super
52
- end
53
-
54
- def close
55
- finish :close
56
-
57
- super
58
- end
59
-
60
- protected def finish(method_name)
61
- write_remaining_buffer
62
-
63
- raw_wrapper method_name
64
- end
65
-
66
- protected def write_remaining_buffer
67
- return nil if @buffer.bytesize.zero?
68
-
69
- @io.write @buffer
70
-
71
- reset_buffer
72
- end
73
-
74
- protected def raw_wrapper(method_name, *args)
75
- @raw_stream.send(method_name, *args) { |portion| @io.write portion }
76
- end
77
-
78
- # -- asynchronous --
79
-
80
- # IO write nonblock can raise wait writable error.
81
- # After resolving this error user may provide same content again.
82
- # It is not possible to revert accepted content after error.
83
- # So we have to accept content after processing IO write nonblock.
84
- # It means that first write nonblock won't call IO write nonblock.
85
- def write_nonblock(object, *options)
86
- return 0 unless write_remaining_buffer_nonblock(*options)
87
-
88
- source = transcode object.to_s
89
- bytes_written = raw_nonblock_wrapper :write, source
90
- @pos += bytes_written
91
-
92
- bytes_written
93
- end
94
-
95
- def flush_nonblock(*options)
96
- return false unless finish_nonblock :flush, *options
97
-
98
- @io.flush
99
-
100
- true
101
- end
102
-
103
- def rewind_nonblock(*options)
104
- return false unless finish_nonblock :close, *options
105
-
106
- method(:rewind).super_method.call
107
-
108
- true
109
- end
110
-
111
- def close_nonblock(*options)
112
- return false unless finish_nonblock :close, *options
113
-
114
- method(:close).super_method.call
115
-
116
- true
117
- end
118
-
119
- protected def finish_nonblock(method_name, *options)
120
- return false unless write_remaining_buffer_nonblock(*options)
121
-
122
- raw_nonblock_wrapper method_name
123
-
124
- write_remaining_buffer_nonblock(*options)
125
- end
126
-
127
- protected def write_remaining_buffer_nonblock(*options)
128
- return true if @buffer.bytesize.zero?
129
-
130
- bytes_written = @io.write_nonblock @buffer, *options
131
- return false if bytes_written.zero?
132
-
133
- @buffer = @buffer.byteslice bytes_written, @buffer.bytesize - bytes_written
134
-
135
- @buffer.bytesize.zero?
136
- end
137
-
138
- protected def raw_nonblock_wrapper(method_name, *args)
139
- @raw_stream.send(method_name, *args) { |portion| @buffer << portion }
140
- end
141
-
142
- # -- common --
143
-
144
- protected def transcode(data)
145
- data = data.encode @external_encoding, **@transcode_options unless @external_encoding.nil?
146
- data
147
- end
10
+ # BRS::Stream::Writer class.
11
+ class Writer < ADSP::Stream::Writer
12
+ # Current raw stream class.
13
+ RawCompressor = Raw::Compressor
148
14
  end
149
15
  end
150
16
  end
data/lib/brs/string.rb CHANGED
@@ -1,15 +1,22 @@
1
1
  # Ruby bindings for brotli library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
+ require "adsp/string"
4
5
  require "brs_ext"
5
6
 
6
7
  require_relative "option"
7
8
  require_relative "validation"
8
9
 
9
10
  module BRS
10
- module String
11
- BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
12
-
11
+ # BRS::String class.
12
+ class String < ADSP::String
13
+ # Current option class.
14
+ Option = BRS::Option
15
+
16
+ # Compresses +source+ string using +options+.
17
+ # Option: +:destination_buffer_length+ destination buffer length.
18
+ # Option: +:size_hint+ source bytesize.
19
+ # Returns compressed string.
13
20
  def self.compress(source, options = {})
14
21
  Validation.validate_string source
15
22
 
@@ -17,15 +24,17 @@ module BRS
17
24
 
18
25
  options[:size_hint] = source.bytesize
19
26
 
20
- BRS._native_compress_string source, options
27
+ super source, options
21
28
  end
22
29
 
23
- def self.decompress(source, options = {})
24
- Validation.validate_string source
25
-
26
- options = Option.get_decompressor_options options, BUFFER_LENGTH_NAMES
30
+ # Bypasses native compress.
31
+ def self.native_compress_string(*args)
32
+ BRS._native_compress_string(*args)
33
+ end
27
34
 
28
- BRS._native_decompress_string source, options
35
+ # Bypasses native decompress.
36
+ def self.native_decompress_string(*args)
37
+ BRS._native_decompress_string(*args)
29
38
  end
30
39
  end
31
40
  end
@@ -1,55 +1,14 @@
1
1
  # Ruby bindings for brotli library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
- require_relative "error"
4
+ require "adsp/validation"
5
5
 
6
6
  module BRS
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
-
7
+ # BRS::Validation class.
8
+ class Validation < ADSP::Validation
9
+ # Raises error when +value+ is not boolean.
21
10
  def self.validate_bool(value)
22
11
  raise ValidateError, "invalid bool" unless value.is_a?(::TrueClass) || value.is_a?(::FalseClass)
23
12
  end
24
-
25
- def self.validate_positive_integer(value)
26
- raise ValidateError, "invalid positive integer" unless value.is_a?(::Integer) && value.positive?
27
- end
28
-
29
- def self.validate_not_negative_integer(value)
30
- raise ValidateError, "invalid not negative integer" unless value.is_a?(::Integer) && value >= 0
31
- end
32
-
33
- def self.validate_string(value)
34
- raise ValidateError, "invalid string" unless value.is_a? ::String
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
47
- end
48
-
49
- def self.validate_proc(value)
50
- unless value.is_a?(::Proc) || value.is_a?(::Method) || value.is_a?(::UnboundMethod)
51
- raise ValidateError, "invalid proc"
52
- end
53
- end
54
13
  end
55
14
  end
data/lib/brs/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  module BRS
5
- VERSION = "1.3.0".freeze
5
+ VERSION = "1.3.3".freeze
6
6
  end
metadata CHANGED
@@ -1,15 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-brs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.3
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: 2021-09-30 00:00:00.000000000 Z
12
+ date: 2022-07-06 00:00:00.000000000 Z
12
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: adsp
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
13
28
  - !ruby/object:Gem::Dependency
14
29
  name: codecov
15
30
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +73,14 @@ dependencies:
58
73
  requirements:
59
74
  - - "~>"
60
75
  - !ruby/object:Gem::Version
61
- version: '5.14'
76
+ version: '5.16'
62
77
  type: :development
63
78
  prerelease: false
64
79
  version_requirements: !ruby/object:Gem::Requirement
65
80
  requirements:
66
81
  - - "~>"
67
82
  - !ruby/object:Gem::Version
68
- version: '5.14'
83
+ version: '5.16'
69
84
  - !ruby/object:Gem::Dependency
70
85
  name: ocg
71
86
  requirement: !ruby/object:Gem::Requirement
@@ -122,48 +137,62 @@ dependencies:
122
137
  - - ">="
123
138
  - !ruby/object:Gem::Version
124
139
  version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rdoc
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
125
154
  - !ruby/object:Gem::Dependency
126
155
  name: rubocop
127
156
  requirement: !ruby/object:Gem::Requirement
128
157
  requirements:
129
158
  - - "~>"
130
159
  - !ruby/object:Gem::Version
131
- version: '1.22'
160
+ version: '1.31'
132
161
  type: :development
133
162
  prerelease: false
134
163
  version_requirements: !ruby/object:Gem::Requirement
135
164
  requirements:
136
165
  - - "~>"
137
166
  - !ruby/object:Gem::Version
138
- version: '1.22'
167
+ version: '1.31'
139
168
  - !ruby/object:Gem::Dependency
140
169
  name: rubocop-minitest
141
170
  requirement: !ruby/object:Gem::Requirement
142
171
  requirements:
143
172
  - - "~>"
144
173
  - !ruby/object:Gem::Version
145
- version: '0.15'
174
+ version: '0.20'
146
175
  type: :development
147
176
  prerelease: false
148
177
  version_requirements: !ruby/object:Gem::Requirement
149
178
  requirements:
150
179
  - - "~>"
151
180
  - !ruby/object:Gem::Version
152
- version: '0.15'
181
+ version: '0.20'
153
182
  - !ruby/object:Gem::Dependency
154
183
  name: rubocop-performance
155
184
  requirement: !ruby/object:Gem::Requirement
156
185
  requirements:
157
186
  - - "~>"
158
187
  - !ruby/object:Gem::Version
159
- version: '1.11'
188
+ version: '1.14'
160
189
  type: :development
161
190
  prerelease: false
162
191
  version_requirements: !ruby/object:Gem::Requirement
163
192
  requirements:
164
193
  - - "~>"
165
194
  - !ruby/object:Gem::Version
166
- version: '1.11'
195
+ version: '1.14'
167
196
  - !ruby/object:Gem::Dependency
168
197
  name: rubocop-rake
169
198
  requirement: !ruby/object:Gem::Requirement
@@ -225,23 +254,18 @@ files:
225
254
  - lib/brs/error.rb
226
255
  - lib/brs/file.rb
227
256
  - lib/brs/option.rb
228
- - lib/brs/stream/abstract.rb
229
- - lib/brs/stream/delegates.rb
230
- - lib/brs/stream/raw/abstract.rb
231
257
  - lib/brs/stream/raw/compressor.rb
232
258
  - lib/brs/stream/raw/decompressor.rb
233
259
  - lib/brs/stream/reader.rb
234
- - lib/brs/stream/reader_helpers.rb
235
- - lib/brs/stream/stat.rb
236
260
  - lib/brs/stream/writer.rb
237
- - lib/brs/stream/writer_helpers.rb
238
261
  - lib/brs/string.rb
239
262
  - lib/brs/validation.rb
240
263
  - lib/brs/version.rb
241
264
  homepage: https://github.com/andrew-aladev/ruby-brs
242
265
  licenses:
243
266
  - MIT
244
- metadata: {}
267
+ metadata:
268
+ rubygems_mfa_required: 'true'
245
269
  post_install_message:
246
270
  rdoc_options: []
247
271
  require_paths:
@@ -250,14 +274,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
274
  requirements:
251
275
  - - ">="
252
276
  - !ruby/object:Gem::Version
253
- version: '2.5'
277
+ version: '2.6'
254
278
  required_rubygems_version: !ruby/object:Gem::Requirement
255
279
  requirements:
256
280
  - - ">="
257
281
  - !ruby/object:Gem::Version
258
282
  version: '0'
259
283
  requirements: []
260
- rubygems_version: 3.2.22
284
+ rubygems_version: 3.3.7
261
285
  signing_key:
262
286
  specification_version: 4
263
287
  summary: Ruby bindings for brotli library.