ruby-zstds 1.2.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHORS +2 -0
- data/README.md +34 -12
- data/ext/extconf.rb +14 -1
- data/ext/zstds_ext/dictionary.c +233 -45
- data/ext/zstds_ext/dictionary.h +22 -0
- data/ext/zstds_ext/error.c +3 -0
- data/ext/zstds_ext/error.h +1 -0
- data/ext/zstds_ext/gvl.h +2 -2
- data/ext/zstds_ext/macro.h +7 -1
- data/ext/zstds_ext/option.h +14 -0
- data/lib/zstds/dictionary.rb +76 -6
- data/lib/zstds/error.rb +9 -4
- data/lib/zstds/file.rb +17 -27
- data/lib/zstds/option.rb +60 -0
- data/lib/zstds/stream/raw/compressor.rb +12 -76
- data/lib/zstds/stream/raw/decompressor.rb +7 -51
- data/lib/zstds/stream/reader.rb +6 -176
- data/lib/zstds/stream/writer.rb +6 -140
- data/lib/zstds/string.rb +18 -9
- data/lib/zstds/validation.rb +5 -49
- data/lib/zstds/version.rb +1 -1
- metadata +44 -19
- data/lib/zstds/stream/abstract.rb +0 -152
- data/lib/zstds/stream/delegates.rb +0 -36
- data/lib/zstds/stream/raw/abstract.rb +0 -59
- data/lib/zstds/stream/reader_helpers.rb +0 -194
- data/lib/zstds/stream/stat.rb +0 -78
- data/lib/zstds/stream/writer_helpers.rb +0 -91
data/lib/zstds/stream/writer.rb
CHANGED
@@ -1,150 +1,16 @@
|
|
1
1
|
# Ruby bindings for zstd library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
-
|
4
|
+
require "adsp/stream/writer"
|
5
|
+
|
5
6
|
require_relative "raw/compressor"
|
6
|
-
require_relative "writer_helpers"
|
7
7
|
|
8
8
|
module ZSTDS
|
9
9
|
module Stream
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
+
# ZSTDS::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/zstds/string.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
# Ruby bindings for zstd library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require "adsp/string"
|
4
5
|
require "zstds_ext"
|
5
6
|
|
6
7
|
require_relative "option"
|
7
8
|
require_relative "validation"
|
8
9
|
|
9
10
|
module ZSTDS
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
# ZSTDS::String class.
|
12
|
+
class String < ADSP::String
|
13
|
+
# Current option class.
|
14
|
+
Option = ZSTDS::Option
|
15
|
+
|
16
|
+
# Compresses +source+ string using +options+.
|
17
|
+
# Option: +:destination_buffer_length+ destination buffer length.
|
18
|
+
# Option: +:pledged_size+ 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 ZSTDS
|
|
17
24
|
|
18
25
|
options[:pledged_size] = source.bytesize
|
19
26
|
|
20
|
-
|
27
|
+
super source, options
|
21
28
|
end
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
30
|
+
# Bypasses native compress.
|
31
|
+
def self.native_compress_string(*args)
|
32
|
+
ZSTDS._native_compress_string(*args)
|
33
|
+
end
|
27
34
|
|
28
|
-
|
35
|
+
# Bypasses native decompress.
|
36
|
+
def self.native_decompress_string(*args)
|
37
|
+
ZSTDS._native_decompress_string(*args)
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
data/lib/zstds/validation.rb
CHANGED
@@ -1,63 +1,19 @@
|
|
1
1
|
# Ruby bindings for zstd library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
-
|
4
|
+
require "adsp/validation"
|
5
5
|
|
6
6
|
module ZSTDS
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
write
|
11
|
-
readpartial
|
12
|
-
read_nonblock
|
13
|
-
write_nonblock
|
14
|
-
eof?
|
15
|
-
flush
|
16
|
-
close
|
17
|
-
closed?
|
18
|
-
]
|
19
|
-
.freeze
|
20
|
-
|
7
|
+
# ZSTDS::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
13
|
|
14
|
+
# Raises error when +value+ is not integer.
|
25
15
|
def self.validate_integer(value)
|
26
16
|
raise ValidateError, "invalid integer" unless value.is_a? ::Integer
|
27
17
|
end
|
28
|
-
|
29
|
-
def self.validate_positive_integer(value)
|
30
|
-
raise ValidateError, "invalid positive integer" unless value.is_a?(::Integer) && value.positive?
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.validate_not_negative_integer(value)
|
34
|
-
raise ValidateError, "invalid not negative integer" unless value.is_a?(::Integer) && value >= 0
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.validate_string(value)
|
38
|
-
raise ValidateError, "invalid string" unless value.is_a? ::String
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.validate_symbol(value)
|
42
|
-
raise ValidateError, "invalid symbol" unless value.is_a? ::Symbol
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.validate_io(value)
|
46
|
-
raise ValidateError, "invalid io" unless IO_METHODS.all? { |method| value.respond_to? method }
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.validate_array(value)
|
50
|
-
raise ValidateError, "invalid array" unless value.is_a? ::Array
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.validate_hash(value)
|
54
|
-
raise ValidateError, "invalid hash" unless value.is_a? ::Hash
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.validate_proc(value)
|
58
|
-
unless value.is_a?(::Proc) || value.is_a?(::Method) || value.is_a?(::UnboundMethod)
|
59
|
-
raise ValidateError, "invalid proc"
|
60
|
-
end
|
61
|
-
end
|
62
18
|
end
|
63
19
|
end
|
data/lib/zstds/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-zstds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Aladjev
|
8
|
+
- Ivan Takarlikov
|
9
|
+
- Jenner La Fave
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2022-07-06 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: adsp
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.0'
|
13
29
|
- !ruby/object:Gem::Dependency
|
14
30
|
name: codecov
|
15
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +74,14 @@ dependencies:
|
|
58
74
|
requirements:
|
59
75
|
- - "~>"
|
60
76
|
- !ruby/object:Gem::Version
|
61
|
-
version: '5.
|
77
|
+
version: '5.16'
|
62
78
|
type: :development
|
63
79
|
prerelease: false
|
64
80
|
version_requirements: !ruby/object:Gem::Requirement
|
65
81
|
requirements:
|
66
82
|
- - "~>"
|
67
83
|
- !ruby/object:Gem::Version
|
68
|
-
version: '5.
|
84
|
+
version: '5.16'
|
69
85
|
- !ruby/object:Gem::Dependency
|
70
86
|
name: ocg
|
71
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,48 +138,62 @@ dependencies:
|
|
122
138
|
- - ">="
|
123
139
|
- !ruby/object:Gem::Version
|
124
140
|
version: '0'
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: rdoc
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
type: :development
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
125
155
|
- !ruby/object:Gem::Dependency
|
126
156
|
name: rubocop
|
127
157
|
requirement: !ruby/object:Gem::Requirement
|
128
158
|
requirements:
|
129
159
|
- - "~>"
|
130
160
|
- !ruby/object:Gem::Version
|
131
|
-
version: '1.
|
161
|
+
version: '1.31'
|
132
162
|
type: :development
|
133
163
|
prerelease: false
|
134
164
|
version_requirements: !ruby/object:Gem::Requirement
|
135
165
|
requirements:
|
136
166
|
- - "~>"
|
137
167
|
- !ruby/object:Gem::Version
|
138
|
-
version: '1.
|
168
|
+
version: '1.31'
|
139
169
|
- !ruby/object:Gem::Dependency
|
140
170
|
name: rubocop-minitest
|
141
171
|
requirement: !ruby/object:Gem::Requirement
|
142
172
|
requirements:
|
143
173
|
- - "~>"
|
144
174
|
- !ruby/object:Gem::Version
|
145
|
-
version: '0.
|
175
|
+
version: '0.20'
|
146
176
|
type: :development
|
147
177
|
prerelease: false
|
148
178
|
version_requirements: !ruby/object:Gem::Requirement
|
149
179
|
requirements:
|
150
180
|
- - "~>"
|
151
181
|
- !ruby/object:Gem::Version
|
152
|
-
version: '0.
|
182
|
+
version: '0.20'
|
153
183
|
- !ruby/object:Gem::Dependency
|
154
184
|
name: rubocop-performance
|
155
185
|
requirement: !ruby/object:Gem::Requirement
|
156
186
|
requirements:
|
157
187
|
- - "~>"
|
158
188
|
- !ruby/object:Gem::Version
|
159
|
-
version: '1.
|
189
|
+
version: '1.14'
|
160
190
|
type: :development
|
161
191
|
prerelease: false
|
162
192
|
version_requirements: !ruby/object:Gem::Requirement
|
163
193
|
requirements:
|
164
194
|
- - "~>"
|
165
195
|
- !ruby/object:Gem::Version
|
166
|
-
version: '1.
|
196
|
+
version: '1.14'
|
167
197
|
- !ruby/object:Gem::Dependency
|
168
198
|
name: rubocop-rake
|
169
199
|
requirement: !ruby/object:Gem::Requirement
|
@@ -228,23 +258,18 @@ files:
|
|
228
258
|
- lib/zstds/error.rb
|
229
259
|
- lib/zstds/file.rb
|
230
260
|
- lib/zstds/option.rb
|
231
|
-
- lib/zstds/stream/abstract.rb
|
232
|
-
- lib/zstds/stream/delegates.rb
|
233
|
-
- lib/zstds/stream/raw/abstract.rb
|
234
261
|
- lib/zstds/stream/raw/compressor.rb
|
235
262
|
- lib/zstds/stream/raw/decompressor.rb
|
236
263
|
- lib/zstds/stream/reader.rb
|
237
|
-
- lib/zstds/stream/reader_helpers.rb
|
238
|
-
- lib/zstds/stream/stat.rb
|
239
264
|
- lib/zstds/stream/writer.rb
|
240
|
-
- lib/zstds/stream/writer_helpers.rb
|
241
265
|
- lib/zstds/string.rb
|
242
266
|
- lib/zstds/validation.rb
|
243
267
|
- lib/zstds/version.rb
|
244
268
|
homepage: https://github.com/andrew-aladev/ruby-zstds
|
245
269
|
licenses:
|
246
270
|
- MIT
|
247
|
-
metadata:
|
271
|
+
metadata:
|
272
|
+
rubygems_mfa_required: 'true'
|
248
273
|
post_install_message:
|
249
274
|
rdoc_options: []
|
250
275
|
require_paths:
|
@@ -253,14 +278,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
253
278
|
requirements:
|
254
279
|
- - ">="
|
255
280
|
- !ruby/object:Gem::Version
|
256
|
-
version: '2.
|
281
|
+
version: '2.6'
|
257
282
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
258
283
|
requirements:
|
259
284
|
- - ">="
|
260
285
|
- !ruby/object:Gem::Version
|
261
286
|
version: '0'
|
262
287
|
requirements: []
|
263
|
-
rubygems_version: 3.
|
288
|
+
rubygems_version: 3.3.7
|
264
289
|
signing_key:
|
265
290
|
specification_version: 4
|
266
291
|
summary: Ruby bindings for zstd library.
|
@@ -1,152 +0,0 @@
|
|
1
|
-
# Ruby bindings for zstd library.
|
2
|
-
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
|
-
|
4
|
-
require_relative "delegates"
|
5
|
-
require_relative "stat"
|
6
|
-
require_relative "../error"
|
7
|
-
require_relative "../validation"
|
8
|
-
|
9
|
-
module ZSTDS
|
10
|
-
module Stream
|
11
|
-
class Abstract
|
12
|
-
# Native stream is not seekable by design.
|
13
|
-
# Related methods like "seek" and "pos=" can't be implemented.
|
14
|
-
|
15
|
-
# It is not possible to maintain correspondance between bytes
|
16
|
-
# consumed from source and bytes written to destination by design.
|
17
|
-
# We will consume all source bytes and maintain buffer with remaining destination data.
|
18
|
-
|
19
|
-
include Delegates
|
20
|
-
|
21
|
-
attr_reader :io, :stat, :external_encoding, :internal_encoding, :transcode_options, :pos
|
22
|
-
|
23
|
-
alias tell pos
|
24
|
-
|
25
|
-
def initialize(io, options = {})
|
26
|
-
@raw_stream = create_raw_stream
|
27
|
-
|
28
|
-
Validation.validate_io io
|
29
|
-
@io = io
|
30
|
-
|
31
|
-
@stat = Stat.new @io.stat if @io.respond_to? :stat
|
32
|
-
|
33
|
-
set_encoding options[:external_encoding], options[:internal_encoding], options[:transcode_options]
|
34
|
-
reset_buffer
|
35
|
-
reset_io_advise
|
36
|
-
|
37
|
-
@pos = 0
|
38
|
-
end
|
39
|
-
|
40
|
-
# -- buffer --
|
41
|
-
|
42
|
-
protected def reset_buffer
|
43
|
-
@buffer = ::String.new :encoding => ::Encoding::BINARY
|
44
|
-
end
|
45
|
-
|
46
|
-
# -- advise --
|
47
|
-
|
48
|
-
protected def reset_io_advise
|
49
|
-
# Both compressor and decompressor need sequential io access.
|
50
|
-
@io.advise :sequential if @io.respond_to? :advise
|
51
|
-
rescue ::Errno::ESPIPE
|
52
|
-
# ok
|
53
|
-
end
|
54
|
-
|
55
|
-
def advise
|
56
|
-
# Noop
|
57
|
-
nil
|
58
|
-
end
|
59
|
-
|
60
|
-
# -- encoding --
|
61
|
-
|
62
|
-
def set_encoding(*args)
|
63
|
-
external_encoding, internal_encoding, transcode_options = process_set_encoding_arguments(*args)
|
64
|
-
|
65
|
-
set_target_encoding :@external_encoding, external_encoding
|
66
|
-
set_target_encoding :@internal_encoding, internal_encoding
|
67
|
-
@transcode_options = transcode_options
|
68
|
-
|
69
|
-
self
|
70
|
-
end
|
71
|
-
|
72
|
-
protected def process_set_encoding_arguments(*args)
|
73
|
-
external_encoding = args[0]
|
74
|
-
|
75
|
-
unless external_encoding.nil? || external_encoding.is_a?(::Encoding)
|
76
|
-
Validation.validate_string external_encoding
|
77
|
-
|
78
|
-
# First argument can be "external_encoding:internal_encoding".
|
79
|
-
match = %r{(.+?):(.+)}.match external_encoding
|
80
|
-
|
81
|
-
unless match.nil?
|
82
|
-
external_encoding = match[0]
|
83
|
-
internal_encoding = match[1]
|
84
|
-
|
85
|
-
transcode_options = args[1]
|
86
|
-
Validation.validate_hash transcode_options unless transcode_options.nil?
|
87
|
-
|
88
|
-
return [external_encoding, internal_encoding, transcode_options]
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
internal_encoding = args[1]
|
93
|
-
unless internal_encoding.nil? || internal_encoding.is_a?(::Encoding)
|
94
|
-
Validation.validate_string internal_encoding
|
95
|
-
end
|
96
|
-
|
97
|
-
transcode_options = args[2]
|
98
|
-
Validation.validate_hash transcode_options unless transcode_options.nil?
|
99
|
-
|
100
|
-
[external_encoding, internal_encoding, transcode_options]
|
101
|
-
end
|
102
|
-
|
103
|
-
protected def set_target_encoding(name, value)
|
104
|
-
unless value.nil? || value.is_a?(::Encoding)
|
105
|
-
begin
|
106
|
-
value = ::Encoding.find value
|
107
|
-
rescue ::ArgumentError
|
108
|
-
raise ValidateError, "invalid #{name} encoding"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
instance_variable_set name, value
|
113
|
-
end
|
114
|
-
|
115
|
-
protected def target_encoding
|
116
|
-
return @internal_encoding unless @internal_encoding.nil?
|
117
|
-
return @external_encoding unless @external_encoding.nil?
|
118
|
-
|
119
|
-
::Encoding::BINARY
|
120
|
-
end
|
121
|
-
|
122
|
-
# -- etc --
|
123
|
-
|
124
|
-
def rewind
|
125
|
-
@raw_stream = create_raw_stream
|
126
|
-
|
127
|
-
@io.rewind if @io.respond_to? :rewind
|
128
|
-
|
129
|
-
reset_buffer
|
130
|
-
reset_io_advise
|
131
|
-
|
132
|
-
@pos = 0
|
133
|
-
|
134
|
-
0
|
135
|
-
end
|
136
|
-
|
137
|
-
def close
|
138
|
-
@io.close
|
139
|
-
|
140
|
-
nil
|
141
|
-
end
|
142
|
-
|
143
|
-
def closed?
|
144
|
-
@raw_stream.closed? && @io.closed?
|
145
|
-
end
|
146
|
-
|
147
|
-
def to_io
|
148
|
-
self
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# Ruby bindings for zstd library.
|
2
|
-
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
|
-
|
4
|
-
require "forwardable"
|
5
|
-
|
6
|
-
module ZSTDS
|
7
|
-
module Stream
|
8
|
-
module Delegates
|
9
|
-
DELEGATES = %i[
|
10
|
-
autoclose=
|
11
|
-
autoclose?
|
12
|
-
binmode
|
13
|
-
binmode?
|
14
|
-
close_on_exec=
|
15
|
-
close_on_exec?
|
16
|
-
fcntl
|
17
|
-
fdatasync
|
18
|
-
fileno
|
19
|
-
fsync
|
20
|
-
ioctl
|
21
|
-
isatty
|
22
|
-
pid
|
23
|
-
sync
|
24
|
-
sync=
|
25
|
-
to_i
|
26
|
-
tty?
|
27
|
-
]
|
28
|
-
.freeze
|
29
|
-
|
30
|
-
def self.included(klass)
|
31
|
-
klass.extend ::Forwardable
|
32
|
-
klass.def_delegators :@io, *DELEGATES
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# Ruby bindings for zstd library.
|
2
|
-
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
|
-
|
4
|
-
require "zstds_ext"
|
5
|
-
|
6
|
-
require_relative "../../error"
|
7
|
-
require_relative "../../validation"
|
8
|
-
|
9
|
-
module ZSTDS
|
10
|
-
module Stream
|
11
|
-
module Raw
|
12
|
-
class Abstract
|
13
|
-
def initialize(native_stream)
|
14
|
-
@native_stream = native_stream
|
15
|
-
@is_closed = false
|
16
|
-
end
|
17
|
-
|
18
|
-
# -- write --
|
19
|
-
|
20
|
-
def flush(&writer)
|
21
|
-
write_result(&writer)
|
22
|
-
|
23
|
-
nil
|
24
|
-
end
|
25
|
-
|
26
|
-
protected def more_destination(&writer)
|
27
|
-
result_bytesize = write_result(&writer)
|
28
|
-
raise NotEnoughDestinationError, "not enough destination" if result_bytesize.zero?
|
29
|
-
end
|
30
|
-
|
31
|
-
protected def write_result(&_writer)
|
32
|
-
result = @native_stream.read_result
|
33
|
-
yield result
|
34
|
-
|
35
|
-
result.bytesize
|
36
|
-
end
|
37
|
-
|
38
|
-
# -- close --
|
39
|
-
|
40
|
-
protected def do_not_use_after_close
|
41
|
-
raise UsedAfterCloseError, "used after close" if closed?
|
42
|
-
end
|
43
|
-
|
44
|
-
def close(&writer)
|
45
|
-
write_result(&writer)
|
46
|
-
|
47
|
-
@native_stream.close
|
48
|
-
@is_closed = true
|
49
|
-
|
50
|
-
nil
|
51
|
-
end
|
52
|
-
|
53
|
-
def closed?
|
54
|
-
@is_closed
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|