ruby-brs 1.3.2 → 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.
- checksums.yaml +4 -4
- data/README.md +11 -11
- data/lib/brs/error.rb +9 -4
- data/lib/brs/file.rb +17 -27
- data/lib/brs/option.rb +36 -0
- data/lib/brs/stream/raw/compressor.rb +12 -76
- data/lib/brs/stream/raw/decompressor.rb +7 -51
- data/lib/brs/stream/reader.rb +6 -185
- data/lib/brs/stream/writer.rb +6 -164
- data/lib/brs/string.rb +18 -9
- data/lib/brs/validation.rb +4 -28
- data/lib/brs/version.rb +1 -1
- metadata +39 -17
- data/lib/brs/stream/abstract.rb +0 -156
- data/lib/brs/stream/delegates.rb +0 -36
- data/lib/brs/stream/raw/abstract.rb +0 -59
- data/lib/brs/stream/reader_helpers.rb +0 -194
- data/lib/brs/stream/stat.rb +0 -78
- data/lib/brs/stream/writer_helpers.rb +0 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6acc107214aae47c21bea586f3281f3b16ad01e03a5f13990667603b625ebd3
|
4
|
+
data.tar.gz: 7cf0a0aacb4bb52457f009a1ceffc6a6c9b6fb80bdf289b86efaabeed261de3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 703c614f49408c3aeb4203aa6f1a5f6abd341d3e0f88275d6c88d52e66e0f1a2f49e00908675e9a4bebcefd0851b33b3f7a115b7e3577d2718acb90d6d2ae551
|
7
|
+
data.tar.gz: d4984cf3b656386c7ab0dfecaebed8be95e5b2b0a24c48a21413e4908fd50d9862883baf887dddb980378f9604346b3da2bc5a9b09c0b430882247ec72a22a87
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Ruby bindings for brotli library
|
2
2
|
|
3
|
-
| AppVeyor |
|
4
|
-
| :------: |
|
5
|
-
| [](https://ci.appveyor.com/project/andrew-aladev/ruby-brs/branch/master) | [](https://ci.appveyor.com/project/andrew-aladev/ruby-brs/branch/master) | [](http://37.187.122.190:58182/job/ruby-brs) | [](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
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
Operating systems: GNU/Linux, FreeBSD, OSX
|
11
|
+
Operating systems: GNU/Linux, FreeBSD, OSX.
|
12
12
|
|
13
13
|
Dependencies: [brotli](https://github.com/google/brotli) 1.0.0+ version.
|
14
14
|
|
@@ -18,7 +18,6 @@ Dependencies: [brotli](https://github.com/google/brotli) 1.0.0+ version.
|
|
18
18
|
| CentOS | `brotli-devel` |
|
19
19
|
| ArchLinux | `brotli` |
|
20
20
|
| OSX | `brotli` |
|
21
|
-
| Windows | `mingw-w64-x86_64-brotli` |
|
22
21
|
|
23
22
|
```sh
|
24
23
|
gem install ruby-brs
|
@@ -133,6 +132,10 @@ Parallel.each large_datas do |large_data|
|
|
133
132
|
end
|
134
133
|
```
|
135
134
|
|
135
|
+
# Docs
|
136
|
+
|
137
|
+
Please review [rdoc generated docs](https://andrew-aladev.github.io/ruby-brs).
|
138
|
+
|
136
139
|
## Options
|
137
140
|
|
138
141
|
| Option | Values | Default | Description |
|
@@ -144,8 +147,8 @@ end
|
|
144
147
|
| `quality` | 0 - 11 | 11 | compression level |
|
145
148
|
| `lgwin` | 10 - 24 | 22 | compressor window size |
|
146
149
|
| `lgblock` | 16 - 24 | nil (auto) | compressor input block size |
|
147
|
-
| `npostfix` | 0 - 3 | nil (auto) |
|
148
|
-
| `ndirect` | 0 - 120 | nil (auto) |
|
150
|
+
| `npostfix` | 0 - 3 | nil (auto) | recommended number of postfix bits |
|
151
|
+
| `ndirect` | 0 - 120 | nil (auto) | recommended number of direct distance codes (step 1 << npostfix, max 15 << npostfix) |
|
149
152
|
| `disable_literal_context_modeling` | true/false | false | disables literal context modeling format |
|
150
153
|
| `disable_ring_buffer_reallocation` | true/false | false | disables ring buffer reallocation |
|
151
154
|
| `size_hint` | 0 - inf | 0 (auto) | size of input (if known) |
|
@@ -292,14 +295,11 @@ Special asynchronous methods missing in `Zlib::GzipWriter`.
|
|
292
295
|
So it is possible to have asynchronous variants for these synchronous methods.
|
293
296
|
Behaviour is the same as `IO#write_nonblock` method.
|
294
297
|
|
295
|
-
All nonblock operations for file will raise `EBADF` error on Windows.
|
296
|
-
Setting file into nonblocking mode is [not available on Windows](https://github.com/ruby/ruby/blob/master/win32/win32.c#L4388).
|
297
|
-
|
298
298
|
```
|
299
299
|
#<<(object)
|
300
300
|
#print(*objects)
|
301
301
|
#printf(*args)
|
302
|
-
#putc(object, encoding
|
302
|
+
#putc(object, :encoding => 'ASCII-8BIT')
|
303
303
|
#puts(*objects)
|
304
304
|
```
|
305
305
|
|
data/lib/brs/error.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
# Ruby bindings for brotli library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require "adsp"
|
5
|
+
|
4
6
|
module BRS
|
5
7
|
class BaseError < ::StandardError; end
|
6
8
|
|
7
9
|
class AllocateError < BaseError; end
|
8
|
-
class ValidateError < BaseError; end
|
9
10
|
|
10
|
-
class UsedAfterCloseError < BaseError; end
|
11
11
|
class NotEnoughSourceBufferError < BaseError; end
|
12
12
|
class NotEnoughDestinationBufferError < BaseError; end
|
13
|
-
class NotEnoughDestinationError < BaseError; end
|
14
13
|
class DecompressorCorruptedSourceError < BaseError; end
|
15
14
|
|
16
15
|
class AccessIOError < BaseError; end
|
17
16
|
class ReadIOError < BaseError; end
|
18
17
|
class WriteIOError < BaseError; end
|
19
18
|
|
20
|
-
|
19
|
+
ValidateError = ADSP::ValidateError
|
20
|
+
|
21
|
+
NotEnoughDestinationError = ADSP::NotEnoughDestinationError
|
22
|
+
UsedAfterCloseError = ADSP::UsedAfterCloseError
|
23
|
+
|
24
|
+
NotImplementedError = ADSP::NotImplementedError
|
25
|
+
UnexpectedError = ADSP::UnexpectedError
|
21
26
|
end
|
data/lib/brs/file.rb
CHANGED
@@ -1,50 +1,40 @@
|
|
1
1
|
# Ruby bindings for brotli library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require "adsp/file"
|
4
5
|
require "brs_ext"
|
5
6
|
|
6
|
-
require_relative "error"
|
7
7
|
require_relative "option"
|
8
8
|
require_relative "validation"
|
9
9
|
|
10
10
|
module BRS
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
# BRS::File class.
|
12
|
+
class File < ADSP::File
|
13
|
+
# Current option class.
|
14
|
+
Option = BRS::Option
|
15
|
+
|
16
|
+
# Compresses data from +source+ file path to +destination+ file path.
|
17
|
+
# Option: +:source_buffer_length+ source buffer length.
|
18
|
+
# Option: +:destination_buffer_length+ destination buffer length.
|
19
|
+
# Option: +:size_hint+ source bytesize.
|
14
20
|
def self.compress(source, destination, options = {})
|
15
21
|
Validation.validate_string source
|
16
|
-
Validation.validate_string destination
|
17
22
|
|
18
23
|
options = Option.get_compressor_options options, BUFFER_LENGTH_NAMES
|
19
24
|
|
20
25
|
options[:size_hint] = ::File.size source
|
21
26
|
|
22
|
-
|
23
|
-
BRS._native_compress_io source_io, destination_io, options
|
24
|
-
end
|
25
|
-
|
26
|
-
nil
|
27
|
+
super source, destination, options
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
options = Option.get_decompressor_options options, BUFFER_LENGTH_NAMES
|
34
|
-
|
35
|
-
open_files source, destination do |source_io, destination_io|
|
36
|
-
BRS._native_decompress_io source_io, destination_io, options
|
37
|
-
end
|
38
|
-
|
39
|
-
nil
|
30
|
+
# Bypass native compress.
|
31
|
+
def self.native_compress_io(*args)
|
32
|
+
BRS._native_compress_io(*args)
|
40
33
|
end
|
41
34
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
yield source_io, destination_io
|
46
|
-
end
|
47
|
-
end
|
35
|
+
# Bypass native decompress.
|
36
|
+
def self.native_decompress_io(*args)
|
37
|
+
BRS._native_decompress_io(*args)
|
48
38
|
end
|
49
39
|
end
|
50
40
|
end
|
data/lib/brs/option.rb
CHANGED
@@ -7,29 +7,58 @@ require_relative "error"
|
|
7
7
|
require_relative "validation"
|
8
8
|
|
9
9
|
module BRS
|
10
|
+
# BRS::Option module.
|
10
11
|
module Option
|
12
|
+
# Current default buffer length.
|
11
13
|
DEFAULT_BUFFER_LENGTH = 0
|
12
14
|
|
15
|
+
# Current compressor defaults.
|
13
16
|
COMPRESSOR_DEFAULTS = {
|
17
|
+
# Enables global VM lock where possible.
|
14
18
|
:gvl => false,
|
19
|
+
# Compressor mode.
|
15
20
|
:mode => nil,
|
21
|
+
# Compression level.
|
16
22
|
:quality => nil,
|
23
|
+
# Compressor window size.
|
17
24
|
:lgwin => nil,
|
25
|
+
# Compressor input block size.
|
18
26
|
:lgblock => nil,
|
27
|
+
# Recommended number of postfix bits.
|
19
28
|
:npostfix => nil,
|
29
|
+
# Recommended number of direct distance codes (step 1 << npostfix, max 15 << npostfix).
|
20
30
|
:ndirect => nil,
|
31
|
+
# Disables literal context modeling format.
|
21
32
|
:disable_literal_context_modeling => nil,
|
33
|
+
# Enables large window.
|
22
34
|
:large_window => nil
|
23
35
|
}
|
24
36
|
.freeze
|
25
37
|
|
38
|
+
# Current decompressor defaults.
|
26
39
|
DECOMPRESSOR_DEFAULTS = {
|
40
|
+
# Enables global VM lock where possible.
|
27
41
|
:gvl => false,
|
42
|
+
# Disables ring buffer reallocation.
|
28
43
|
:disable_ring_buffer_reallocation => nil,
|
44
|
+
# Enables large window.
|
29
45
|
:large_window => nil
|
30
46
|
}
|
31
47
|
.freeze
|
32
48
|
|
49
|
+
# Processes compressor +options+ and +buffer_length_names+.
|
50
|
+
# Option: +:source_buffer_length+ source buffer length.
|
51
|
+
# Option: +:destination_buffer_length+ destination buffer length.
|
52
|
+
# Option: +:gvl+ enables global VM lock where possible.
|
53
|
+
# Option: +:mode+ compressor mode.
|
54
|
+
# Option: +:quality+ compression level.
|
55
|
+
# Option: +:lgwin+ compressor window size.
|
56
|
+
# Option: +:lgblock+ compressor input block size.
|
57
|
+
# Option: +:npostfix+ recommended number of postfix bits.
|
58
|
+
# Option: +:ndirect+ recommended number of direct distance codes (step 1 << npostfix, max 15 << npostfix).
|
59
|
+
# Option: +:disable_literal_context_modeling+ Disables literal context modeling format.
|
60
|
+
# Option: +:large_window+ enables large window.
|
61
|
+
# Returns processed compressor options.
|
33
62
|
def self.get_compressor_options(options, buffer_length_names)
|
34
63
|
Validation.validate_hash options
|
35
64
|
|
@@ -94,6 +123,13 @@ module BRS
|
|
94
123
|
options
|
95
124
|
end
|
96
125
|
|
126
|
+
# Processes decompressor +options+ and +buffer_length_names+.
|
127
|
+
# Option: +:source_buffer_length+ source buffer length.
|
128
|
+
# Option: +:destination_buffer_length+ destination buffer length.
|
129
|
+
# Option: +:gvl+ enables global VM lock where possible.
|
130
|
+
# Option: +:disable_ring_buffer_reallocation+ disables ring buffer reallocation.
|
131
|
+
# Option: +:large_window+ enables large window.
|
132
|
+
# Returns processed decompressor options.
|
97
133
|
def self.get_decompressor_options(options, buffer_length_names)
|
98
134
|
Validation.validate_hash options
|
99
135
|
|
@@ -1,97 +1,33 @@
|
|
1
1
|
# Ruby bindings for brotli library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require "adsp/stream/raw/compressor"
|
4
5
|
require "brs_ext"
|
5
6
|
|
6
|
-
require_relative "abstract"
|
7
|
-
require_relative "../../error"
|
8
7
|
require_relative "../../option"
|
9
8
|
require_relative "../../validation"
|
10
9
|
|
11
10
|
module BRS
|
12
11
|
module Stream
|
13
12
|
module Raw
|
14
|
-
|
15
|
-
|
13
|
+
# BRS::Stream::Raw::Compressor class.
|
14
|
+
class Compressor < ADSP::Stream::Raw::Compressor
|
15
|
+
# Current native compressor class.
|
16
|
+
NativeCompressor = Stream::NativeCompressor
|
16
17
|
|
18
|
+
# Current option class.
|
19
|
+
Option = BRS::Option
|
20
|
+
|
21
|
+
# Initializes compressor.
|
22
|
+
# Option: +:destination_buffer_length+ destination buffer length.
|
23
|
+
# Option: +:size_hint+ source bytesize.
|
17
24
|
def initialize(options = {})
|
18
25
|
options = Option.get_compressor_options options, BUFFER_LENGTH_NAMES
|
19
26
|
|
20
27
|
size_hint = options[:size_hint]
|
21
28
|
Validation.validate_not_negative_integer size_hint unless size_hint.nil?
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
super native_stream
|
26
|
-
end
|
27
|
-
|
28
|
-
def write(source, &writer)
|
29
|
-
do_not_use_after_close
|
30
|
-
|
31
|
-
Validation.validate_string source
|
32
|
-
Validation.validate_proc writer
|
33
|
-
|
34
|
-
total_bytes_written = 0
|
35
|
-
|
36
|
-
loop do
|
37
|
-
bytes_written, need_more_destination = @native_stream.write source
|
38
|
-
total_bytes_written += bytes_written
|
39
|
-
|
40
|
-
if need_more_destination
|
41
|
-
source = source.byteslice bytes_written, source.bytesize - bytes_written
|
42
|
-
more_destination(&writer)
|
43
|
-
next
|
44
|
-
end
|
45
|
-
|
46
|
-
unless bytes_written == source.bytesize
|
47
|
-
# :nocov:
|
48
|
-
# Compressor write should eat all provided "source" without remainder.
|
49
|
-
raise UnexpectedError, "unexpected error"
|
50
|
-
# :nocov:
|
51
|
-
end
|
52
|
-
|
53
|
-
break
|
54
|
-
end
|
55
|
-
|
56
|
-
total_bytes_written
|
57
|
-
end
|
58
|
-
|
59
|
-
def flush(&writer)
|
60
|
-
do_not_use_after_close
|
61
|
-
|
62
|
-
Validation.validate_proc writer
|
63
|
-
|
64
|
-
loop do
|
65
|
-
need_more_destination = @native_stream.flush
|
66
|
-
|
67
|
-
if need_more_destination
|
68
|
-
more_destination(&writer)
|
69
|
-
next
|
70
|
-
end
|
71
|
-
|
72
|
-
break
|
73
|
-
end
|
74
|
-
|
75
|
-
super
|
76
|
-
end
|
77
|
-
|
78
|
-
def close(&writer)
|
79
|
-
return nil if closed?
|
80
|
-
|
81
|
-
Validation.validate_proc writer
|
82
|
-
|
83
|
-
loop do
|
84
|
-
need_more_destination = @native_stream.finish
|
85
|
-
|
86
|
-
if need_more_destination
|
87
|
-
more_destination(&writer)
|
88
|
-
next
|
89
|
-
end
|
90
|
-
|
91
|
-
break
|
92
|
-
end
|
93
|
-
|
94
|
-
super
|
30
|
+
super options
|
95
31
|
end
|
96
32
|
end
|
97
33
|
end
|
@@ -1,65 +1,21 @@
|
|
1
1
|
# Ruby bindings for brotli library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require "adsp/stream/raw/decompressor"
|
4
5
|
require "brs_ext"
|
5
6
|
|
6
|
-
require_relative "abstract"
|
7
7
|
require_relative "../../option"
|
8
|
-
require_relative "../../validation"
|
9
8
|
|
10
9
|
module BRS
|
11
10
|
module Stream
|
12
11
|
module Raw
|
13
|
-
|
14
|
-
|
12
|
+
# BRS::Stream::Raw::Decompressor class.
|
13
|
+
class Decompressor < ADSP::Stream::Raw::Decompressor
|
14
|
+
# Current native decompressor class.
|
15
|
+
NativeDecompressor = Stream::NativeDecompressor
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
native_stream = NativeDecompressor.new options
|
19
|
-
|
20
|
-
super native_stream
|
21
|
-
end
|
22
|
-
|
23
|
-
def read(source, &writer)
|
24
|
-
do_not_use_after_close
|
25
|
-
|
26
|
-
Validation.validate_string source
|
27
|
-
Validation.validate_proc writer
|
28
|
-
|
29
|
-
total_bytes_read = 0
|
30
|
-
|
31
|
-
loop do
|
32
|
-
bytes_read, need_more_destination = @native_stream.read source
|
33
|
-
total_bytes_read += bytes_read
|
34
|
-
|
35
|
-
if need_more_destination
|
36
|
-
source = source.byteslice bytes_read, source.bytesize - bytes_read
|
37
|
-
more_destination(&writer)
|
38
|
-
next
|
39
|
-
end
|
40
|
-
|
41
|
-
break
|
42
|
-
end
|
43
|
-
|
44
|
-
# Please remember that "total_bytes_read" can not be equal to "source.bytesize".
|
45
|
-
total_bytes_read
|
46
|
-
end
|
47
|
-
|
48
|
-
def flush(&writer)
|
49
|
-
do_not_use_after_close
|
50
|
-
|
51
|
-
Validation.validate_proc writer
|
52
|
-
|
53
|
-
super
|
54
|
-
end
|
55
|
-
|
56
|
-
def close(&writer)
|
57
|
-
return nil if closed?
|
58
|
-
|
59
|
-
Validation.validate_proc writer
|
60
|
-
|
61
|
-
super
|
62
|
-
end
|
17
|
+
# Current option class.
|
18
|
+
Option = BRS::Option
|
63
19
|
end
|
64
20
|
end
|
65
21
|
end
|
data/lib/brs/stream/reader.rb
CHANGED
@@ -1,195 +1,16 @@
|
|
1
1
|
# Ruby bindings for brotli library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
raise ValidateError, "io should be responsible to read and eof" unless
|
58
|
-
@io.respond_to?(:read) && @io.respond_to?(:eof?)
|
59
|
-
|
60
|
-
unless bytes_to_read.nil?
|
61
|
-
return ::String.new :encoding => ::Encoding::BINARY if bytes_to_read.zero?
|
62
|
-
return nil if eof?
|
63
|
-
|
64
|
-
append_io_data @io.read(@source_buffer_length) while @buffer.bytesize < bytes_to_read && !@io.eof?
|
65
|
-
flush_io_data if @buffer.bytesize < bytes_to_read
|
66
|
-
|
67
|
-
return read_bytes_from_buffer bytes_to_read, out_buffer
|
68
|
-
end
|
69
|
-
|
70
|
-
append_io_data @io.read(@source_buffer_length) until @io.eof?
|
71
|
-
flush_io_data
|
72
|
-
|
73
|
-
read_buffer out_buffer
|
74
|
-
end
|
75
|
-
|
76
|
-
def rewind
|
77
|
-
raw_wrapper :close
|
78
|
-
|
79
|
-
reset_io_remainder
|
80
|
-
reset_need_to_flush
|
81
|
-
|
82
|
-
super
|
83
|
-
end
|
84
|
-
|
85
|
-
def close
|
86
|
-
raw_wrapper :close
|
87
|
-
|
88
|
-
super
|
89
|
-
end
|
90
|
-
|
91
|
-
def eof?
|
92
|
-
raise ValidateError, "io should be responsible to eof" unless @io.respond_to? :eof?
|
93
|
-
|
94
|
-
empty? && @io.eof?
|
95
|
-
end
|
96
|
-
|
97
|
-
# -- asynchronous --
|
98
|
-
|
99
|
-
def readpartial(bytes_to_read, out_buffer = nil)
|
100
|
-
raise ValidateError, "io should be responsible to readpartial" unless @io.respond_to? :readpartial
|
101
|
-
|
102
|
-
read_more_nonblock(bytes_to_read, out_buffer) { @io.readpartial @source_buffer_length }
|
103
|
-
end
|
104
|
-
|
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
|
-
|
108
|
-
read_more_nonblock(bytes_to_read, out_buffer) { @io.read_nonblock(@source_buffer_length, *options) }
|
109
|
-
end
|
110
|
-
|
111
|
-
protected def read_more_nonblock(bytes_to_read, out_buffer, &_block)
|
112
|
-
Validation.validate_not_negative_integer bytes_to_read
|
113
|
-
Validation.validate_string out_buffer unless out_buffer.nil?
|
114
|
-
|
115
|
-
return ::String.new :encoding => ::Encoding::BINARY if bytes_to_read.zero?
|
116
|
-
|
117
|
-
io_provided_eof_error = false
|
118
|
-
|
119
|
-
if @buffer.bytesize < bytes_to_read
|
120
|
-
begin
|
121
|
-
append_io_data yield
|
122
|
-
rescue ::EOFError
|
123
|
-
io_provided_eof_error = true
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
flush_io_data if @buffer.bytesize < bytes_to_read
|
128
|
-
raise ::EOFError if empty? && io_provided_eof_error
|
129
|
-
|
130
|
-
read_bytes_from_buffer bytes_to_read, out_buffer
|
131
|
-
end
|
132
|
-
|
133
|
-
# -- common --
|
134
|
-
|
135
|
-
protected def append_io_data(io_data)
|
136
|
-
io_portion = @io_remainder + io_data
|
137
|
-
bytes_read = raw_wrapper :read, io_portion
|
138
|
-
@io_remainder = io_portion.byteslice bytes_read, io_portion.bytesize - bytes_read
|
139
|
-
|
140
|
-
# Even empty io data may require flush.
|
141
|
-
@need_to_flush = true
|
142
|
-
end
|
143
|
-
|
144
|
-
protected def flush_io_data
|
145
|
-
raw_wrapper :flush
|
146
|
-
|
147
|
-
@need_to_flush = false
|
148
|
-
end
|
149
|
-
|
150
|
-
protected def empty?
|
151
|
-
!@need_to_flush && @buffer.bytesize.zero?
|
152
|
-
end
|
153
|
-
|
154
|
-
protected def read_bytes_from_buffer(bytes_to_read, out_buffer)
|
155
|
-
bytes_read = [@buffer.bytesize, bytes_to_read].min
|
156
|
-
|
157
|
-
# Result uses buffer binary encoding.
|
158
|
-
result = @buffer.byteslice 0, bytes_read
|
159
|
-
@buffer = @buffer.byteslice bytes_read, @buffer.bytesize - bytes_read
|
160
|
-
@pos += bytes_read
|
161
|
-
|
162
|
-
result = out_buffer.replace result unless out_buffer.nil?
|
163
|
-
result
|
164
|
-
end
|
165
|
-
|
166
|
-
protected def read_buffer(out_buffer)
|
167
|
-
result = @buffer
|
168
|
-
reset_buffer
|
169
|
-
@pos += result.bytesize
|
170
|
-
|
171
|
-
result.force_encoding @external_encoding unless @external_encoding.nil?
|
172
|
-
result = transcode_to_internal result
|
173
|
-
|
174
|
-
result = out_buffer.replace result unless out_buffer.nil?
|
175
|
-
result
|
176
|
-
end
|
177
|
-
|
178
|
-
protected def transcode_to_internal(data)
|
179
|
-
data = data.encode @internal_encoding, **@transcode_options unless @internal_encoding.nil?
|
180
|
-
data
|
181
|
-
end
|
182
|
-
|
183
|
-
# We should be able to return data back to buffer.
|
184
|
-
# We won't use any transcode options because transcoded data should be backward compatible.
|
185
|
-
protected def transcode_to_external(data)
|
186
|
-
data = data.encode @external_encoding unless @external_encoding.nil?
|
187
|
-
data
|
188
|
-
end
|
189
|
-
|
190
|
-
protected def raw_wrapper(method_name, *args)
|
191
|
-
@raw_stream.send(method_name, *args) { |portion| @buffer << portion }
|
192
|
-
end
|
10
|
+
# BRS::Stream::Reader class.
|
11
|
+
class Reader < ADSP::Stream::Reader
|
12
|
+
# Current raw stream class.
|
13
|
+
RawDecompressor = Raw::Decompressor
|
193
14
|
end
|
194
15
|
end
|
195
16
|
end
|