ruby-zstds 1.3.0 → 1.3.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 +9 -9
- data/ext/zstds_ext/dictionary.c +12 -12
- data/lib/zstds/dictionary.rb +24 -0
- data/lib/zstds/error.rb +9 -5
- 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 -185
- data/lib/zstds/stream/writer.rb +6 -164
- data/lib/zstds/string.rb +18 -9
- data/lib/zstds/validation.rb +5 -32
- data/lib/zstds/version.rb +1 -1
- metadata +39 -17
- data/lib/zstds/stream/abstract.rb +0 -156
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a3bf1ddf3028d59dbfadc868b7dd0049f95213ccede92b223cab2f1af2a847b
|
4
|
+
data.tar.gz: d8dce89cd592e7815aea864900afd336e67a0bc65def9f6b21b30a67b184a7fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b956bba7a80f4456b736748e2355d9e862f230af855d5b539cb0d7034c183238d8e8b68a65c629fb5baae2ec94757d0e8f822572d0bcc694a2740bb173ab6e7d
|
7
|
+
data.tar.gz: 6222867bf832bf0d8b08e8cc94d25be1eec376e87b6f24e1bc2d8c75f36d06bb12a7a601f8737eccafa02bdd1c1c0a3eee65c7d7f2c77fcb9e0b4068d9afaef1
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Ruby bindings for zstd library
|
2
2
|
|
3
|
-
| AppVeyor |
|
4
|
-
| :------: |
|
5
|
-
| [](https://ci.appveyor.com/project/andrew-aladev/ruby-zstds/branch/master) | [](https://ci.appveyor.com/project/andrew-aladev/ruby-zstds/branch/master) | [](http://37.187.122.190:58182/job/ruby-zstds) | [](https://github.com/andrew-aladev/ruby-zstds/actions) | [](https://codecov.io/gh/andrew-aladev/ruby-zstds) | [](https://rubygems.org/gems/ruby-zstds) |
|
6
6
|
|
7
7
|
See [zstd library](https://github.com/facebook/zstd).
|
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: [zstd](https://github.com/facebook/zstd) 1.4.0+ version.
|
14
14
|
|
@@ -18,7 +18,6 @@ Dependencies: [zstd](https://github.com/facebook/zstd) 1.4.0+ version.
|
|
18
18
|
| CentOS | `libzstd-devel` |
|
19
19
|
| ArchLinux | `zstd` |
|
20
20
|
| OSX | `zstd` |
|
21
|
-
| Windows | `mingw-w64-x86_64-zstd` |
|
22
21
|
|
23
22
|
```sh
|
24
23
|
gem install ruby-zstds
|
@@ -151,6 +150,10 @@ Parallel.each large_datas do |large_data|
|
|
151
150
|
end
|
152
151
|
```
|
153
152
|
|
153
|
+
# Docs
|
154
|
+
|
155
|
+
Please review [rdoc generated docs](https://andrew-aladev.github.io/ruby-zstds).
|
156
|
+
|
154
157
|
## Options
|
155
158
|
|
156
159
|
| Option | Values | Default | Description |
|
@@ -344,14 +347,11 @@ Special asynchronous methods missing in `Zlib::GzipWriter`.
|
|
344
347
|
So it is possible to have asynchronous variants for these synchronous methods.
|
345
348
|
Behaviour is the same as `IO#write_nonblock` method.
|
346
349
|
|
347
|
-
All nonblock operations for file will raise `EBADF` error on Windows.
|
348
|
-
Setting file into nonblocking mode is [not available on Windows](https://github.com/ruby/ruby/blob/master/win32/win32.c#L4388).
|
349
|
-
|
350
350
|
```
|
351
351
|
#<<(object)
|
352
352
|
#print(*objects)
|
353
353
|
#printf(*args)
|
354
|
-
#putc(object, encoding
|
354
|
+
#putc(object, :encoding => 'ASCII-8BIT')
|
355
355
|
#puts(*objects)
|
356
356
|
```
|
357
357
|
|
data/ext/zstds_ext/dictionary.c
CHANGED
@@ -203,34 +203,34 @@ static inline void* finalize_wrapper(void* data)
|
|
203
203
|
return NULL;
|
204
204
|
}
|
205
205
|
|
206
|
-
int compressionLevel;
|
207
206
|
zstds_ext_option_t compression_level = args->dictionary_options.compression_level;
|
207
|
+
int compression_level_value;
|
208
208
|
if (compression_level.has_value) {
|
209
|
-
|
209
|
+
compression_level_value = compression_level.value;
|
210
210
|
} else {
|
211
|
-
|
211
|
+
compression_level_value = 0;
|
212
212
|
}
|
213
213
|
|
214
|
-
unsigned int notificationLevel;
|
215
214
|
zstds_ext_option_t notification_level = args->dictionary_options.notification_level;
|
215
|
+
unsigned int notification_level_value;
|
216
216
|
if (notification_level.has_value) {
|
217
|
-
|
217
|
+
notification_level_value = notification_level.value;
|
218
218
|
} else {
|
219
|
-
|
219
|
+
notification_level_value = 0;
|
220
220
|
}
|
221
221
|
|
222
|
-
unsigned int dictID;
|
223
222
|
zstds_ext_option_t dictionary_id = args->dictionary_options.dictionary_id;
|
223
|
+
unsigned int dictionary_id_value;
|
224
224
|
if (dictionary_id.has_value) {
|
225
|
-
|
225
|
+
dictionary_id_value = dictionary_id.value;
|
226
226
|
} else {
|
227
|
-
|
227
|
+
dictionary_id_value = 0;
|
228
228
|
}
|
229
229
|
|
230
230
|
ZDICT_params_t dictionary_params = {
|
231
|
-
.compressionLevel =
|
232
|
-
.notificationLevel =
|
233
|
-
.dictID =
|
231
|
+
.compressionLevel = compression_level_value,
|
232
|
+
.notificationLevel = notification_level_value,
|
233
|
+
.dictID = dictionary_id_value,
|
234
234
|
};
|
235
235
|
|
236
236
|
args->result = ZDICT_finalizeDictionary(
|
data/lib/zstds/dictionary.rb
CHANGED
@@ -7,13 +7,16 @@ require_relative "error"
|
|
7
7
|
require_relative "validation"
|
8
8
|
|
9
9
|
module ZSTDS
|
10
|
+
# ZSTDS::Dictionary class.
|
10
11
|
class Dictionary
|
12
|
+
# Current train defaults.
|
11
13
|
TRAIN_DEFAULTS = {
|
12
14
|
:gvl => false,
|
13
15
|
:capacity => 0
|
14
16
|
}
|
15
17
|
.freeze
|
16
18
|
|
19
|
+
# Current finalize defaults.
|
17
20
|
FINALIZE_DEFAULTS = {
|
18
21
|
:gvl => false,
|
19
22
|
:max_size => 0,
|
@@ -21,6 +24,7 @@ module ZSTDS
|
|
21
24
|
}
|
22
25
|
.freeze
|
23
26
|
|
27
|
+
# Current finalize dictionary defaults.
|
24
28
|
FINALIZE_DICTIONARY_DEFAULTS = {
|
25
29
|
:compression_level => 0,
|
26
30
|
:notification_level => 0,
|
@@ -28,8 +32,11 @@ module ZSTDS
|
|
28
32
|
}
|
29
33
|
.freeze
|
30
34
|
|
35
|
+
# Reads current +buffer+ binary data.
|
31
36
|
attr_reader :buffer
|
32
37
|
|
38
|
+
# Initializes compressor.
|
39
|
+
# Uses +buffer+ binary data.
|
33
40
|
def initialize(buffer)
|
34
41
|
Validation.validate_string buffer
|
35
42
|
raise ValidateError, "dictionary buffer should not be empty" if buffer.empty?
|
@@ -37,6 +44,12 @@ module ZSTDS
|
|
37
44
|
@buffer = buffer
|
38
45
|
end
|
39
46
|
|
47
|
+
# Trains dictionary.
|
48
|
+
# Uses +samples+ list of binary datas.
|
49
|
+
# Uses +options+ options hash.
|
50
|
+
# Option +gvl+ is global interpreter lock enabled.
|
51
|
+
# Option +capacity+ capacity of dictionary buffer.
|
52
|
+
# Returns dictionary based on new buffer.
|
40
53
|
def self.train(samples, options = {})
|
41
54
|
validate_samples samples
|
42
55
|
|
@@ -51,6 +64,14 @@ module ZSTDS
|
|
51
64
|
new buffer
|
52
65
|
end
|
53
66
|
|
67
|
+
# Finalizes dictionary.
|
68
|
+
# Uses +content+ binary data.
|
69
|
+
# Uses +samples+ list of binary datas.
|
70
|
+
# Uses +options+ options hash.
|
71
|
+
# Option +gvl+ is global interpreter lock enabled.
|
72
|
+
# Option +max_size+ max size of dictionary buffer.
|
73
|
+
# Option +dictionary_options+ standard dictionary options hash.
|
74
|
+
# Returns dictionary based on new buffer.
|
54
75
|
def self.finalize(content, samples, options = {})
|
55
76
|
Validation.validate_string content
|
56
77
|
raise ValidateError, "content should not be empty" if content.empty?
|
@@ -79,6 +100,7 @@ module ZSTDS
|
|
79
100
|
new buffer
|
80
101
|
end
|
81
102
|
|
103
|
+
# Raises error when +samples+ are not list of not empty strings.
|
82
104
|
def self.validate_samples(samples)
|
83
105
|
Validation.validate_array samples
|
84
106
|
|
@@ -88,10 +110,12 @@ module ZSTDS
|
|
88
110
|
end
|
89
111
|
end
|
90
112
|
|
113
|
+
# Returns current dictionary id.
|
91
114
|
def id
|
92
115
|
self.class.get_buffer_id @buffer
|
93
116
|
end
|
94
117
|
|
118
|
+
# Returns current dictionary header size.
|
95
119
|
def header_size
|
96
120
|
self.class.get_header_size @buffer
|
97
121
|
end
|
data/lib/zstds/error.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# Ruby bindings for zstd library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require "adsp"
|
5
|
+
|
4
6
|
module ZSTDS
|
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
|
class CorruptedDictionaryError < BaseError; end
|
16
15
|
|
@@ -18,6 +17,11 @@ module ZSTDS
|
|
18
17
|
class ReadIOError < BaseError; end
|
19
18
|
class WriteIOError < BaseError; end
|
20
19
|
|
21
|
-
|
22
|
-
|
20
|
+
ValidateError = ADSP::ValidateError
|
21
|
+
|
22
|
+
NotEnoughDestinationError = ADSP::NotEnoughDestinationError
|
23
|
+
UsedAfterCloseError = ADSP::UsedAfterCloseError
|
24
|
+
|
25
|
+
NotImplementedError = ADSP::NotImplementedError
|
26
|
+
UnexpectedError = ADSP::UnexpectedError
|
23
27
|
end
|
data/lib/zstds/file.rb
CHANGED
@@ -1,50 +1,40 @@
|
|
1
1
|
# Ruby bindings for zstd library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require "adsp/file"
|
4
5
|
require "zstds_ext"
|
5
6
|
|
6
|
-
require_relative "error"
|
7
7
|
require_relative "option"
|
8
8
|
require_relative "validation"
|
9
9
|
|
10
10
|
module ZSTDS
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
# ZSTDS::File class.
|
12
|
+
class File < ADSP::File
|
13
|
+
# Current option class.
|
14
|
+
Option = ZSTDS::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: +:pledged_size+ 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[:pledged_size] = ::File.size source
|
21
26
|
|
22
|
-
|
23
|
-
ZSTDS._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
|
-
ZSTDS._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
|
+
ZSTDS._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
|
+
ZSTDS._native_decompress_io(*args)
|
48
38
|
end
|
49
39
|
end
|
50
40
|
end
|
data/lib/zstds/option.rb
CHANGED
@@ -8,41 +8,95 @@ require_relative "error"
|
|
8
8
|
require_relative "validation"
|
9
9
|
|
10
10
|
module ZSTDS
|
11
|
+
# ZSTDS::Option module.
|
11
12
|
module Option
|
13
|
+
# Current default buffer length.
|
12
14
|
DEFAULT_BUFFER_LENGTH = 0
|
13
15
|
|
16
|
+
# Current compressor defaults.
|
14
17
|
COMPRESSOR_DEFAULTS = {
|
18
|
+
# Enables global VM lock where possible.
|
15
19
|
:gvl => false,
|
20
|
+
# Compression level.
|
16
21
|
:compression_level => nil,
|
22
|
+
# Maximum back-reference distance (power of 2).
|
17
23
|
:window_log => nil,
|
24
|
+
# Size of the initial probe table (power of 2).
|
18
25
|
:hash_log => nil,
|
26
|
+
# Size of the multi-probe search table (power of 2).
|
19
27
|
:chain_log => nil,
|
28
|
+
# Number of search attempts (power of 2).
|
20
29
|
:search_log => nil,
|
30
|
+
# Minimum size of searched matches.
|
21
31
|
:min_match => nil,
|
32
|
+
# Distance between match sampling (for :fast strategy),
|
33
|
+
# length of match considered "good enough" for (for other strategies).
|
22
34
|
:target_length => nil,
|
35
|
+
# Choses strategy.
|
23
36
|
:strategy => nil,
|
37
|
+
# Enables long distance matching.
|
24
38
|
:enable_long_distance_matching => nil,
|
39
|
+
# Size of the table for long distance matching (power of 2).
|
25
40
|
:ldm_hash_log => nil,
|
41
|
+
# Minimum match size for long distance matcher.
|
26
42
|
:ldm_min_match => nil,
|
43
|
+
# Log size of each bucket in the LDM hash table for collision resolution.
|
27
44
|
:ldm_bucket_size_log => nil,
|
45
|
+
# Frequency of inserting/looking up entries into the LDM hash table.
|
28
46
|
:ldm_hash_rate_log => nil,
|
47
|
+
# Enables writing of content size into frame header (if known).
|
29
48
|
:content_size_flag => nil,
|
49
|
+
# Enables writing of 32-bits checksum of content at end of frame.
|
30
50
|
:checksum_flag => nil,
|
51
|
+
# Enables writing of dictionary id into frame header.
|
31
52
|
:dict_id_flag => nil,
|
53
|
+
# Number of threads spawned in parallel.
|
32
54
|
:nb_workers => nil,
|
55
|
+
# Size of job (nb_workers >= 1).
|
33
56
|
:job_size => nil,
|
57
|
+
# Overlap size, as a fraction of window size.
|
34
58
|
:overlap_log => nil,
|
59
|
+
# Chose dictionary.
|
35
60
|
:dictionary => nil
|
36
61
|
}
|
37
62
|
.freeze
|
38
63
|
|
64
|
+
# Current decompressor defaults.
|
39
65
|
DECOMPRESSOR_DEFAULTS = {
|
66
|
+
# Enables global VM lock where possible.
|
40
67
|
:gvl => false,
|
68
|
+
# Size limit (power of 2).
|
41
69
|
:window_log_max => nil,
|
70
|
+
# Chose dictionary.
|
42
71
|
:dictionary => nil
|
43
72
|
}
|
44
73
|
.freeze
|
45
74
|
|
75
|
+
# Processes compressor +options+ and +buffer_length_names+.
|
76
|
+
# Option: +:source_buffer_length+ source buffer length.
|
77
|
+
# Option: +:destination_buffer_length+ destination buffer length.
|
78
|
+
# Option: +:gvl+ enables global VM lock where possible.
|
79
|
+
# Option: +:compression_level+ compression level.
|
80
|
+
# Option: +:window_log+ maximum back-reference distance (power of 2).
|
81
|
+
# Option: +:hash_log+ size of the initial probe table (power of 2).
|
82
|
+
# Option: +:chain_log+ size of the multi-probe search table (power of 2).
|
83
|
+
# Option: +:search_log+ number of search attempts (power of 2).
|
84
|
+
# Option: +:min_match+ minimum size of searched matches.
|
85
|
+
# Option: +:target_length+ distance between match sampling (for :fast strategy),
|
86
|
+
# length of match considered "good enough" for (for other strategies).
|
87
|
+
# Option: +:strategy+ choses strategy.
|
88
|
+
# Option: +:ldm_hash_log+ size of the table for long distance matching (power of 2).
|
89
|
+
# Option: +:ldm_min_match+ minimum match size for long distance matcher.
|
90
|
+
# Option: +:ldm_bucket_size_log+ log size of each bucket in the LDM hash table for collision resolution.
|
91
|
+
# Option: +:ldm_hash_rate_log+ frequency of inserting/looking up entries into the LDM hash table.
|
92
|
+
# Option: +:content_size_flag+ enables writing of content size into frame header (if known).
|
93
|
+
# Option: +:checksum_flag+ enables writing of 32-bits checksum of content at end of frame.
|
94
|
+
# Option: +:dict_id_flag+ enables writing of dictionary id into frame header.
|
95
|
+
# Option: +:nb_workers+ number of threads spawned in parallel.
|
96
|
+
# Option: +:job_size+ size of job (nb_workers >= 1).
|
97
|
+
# Option: +:overlap_log+ overlap size, as a fraction of window size.
|
98
|
+
# Option: +:dictionary+ chose dictionary.
|
99
|
+
# Returns processed compressor options.
|
46
100
|
def self.get_compressor_options(options, buffer_length_names)
|
47
101
|
Validation.validate_hash options
|
48
102
|
|
@@ -179,6 +233,12 @@ module ZSTDS
|
|
179
233
|
options
|
180
234
|
end
|
181
235
|
|
236
|
+
# Processes decompressor +options+ and +buffer_length_names+.
|
237
|
+
# Option: +:source_buffer_length+ source buffer length.
|
238
|
+
# Option: +:destination_buffer_length+ destination buffer length.
|
239
|
+
# Option: +:gvl+ enables global VM lock where possible.
|
240
|
+
# Option: +:window_log_max+ size limit (power of 2).
|
241
|
+
# Returns processed decompressor options.
|
182
242
|
def self.get_decompressor_options(options, buffer_length_names)
|
183
243
|
Validation.validate_hash options
|
184
244
|
|
@@ -1,97 +1,33 @@
|
|
1
1
|
# Ruby bindings for zstd library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require "adsp/stream/raw/compressor"
|
4
5
|
require "zstds_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 ZSTDS
|
12
11
|
module Stream
|
13
12
|
module Raw
|
14
|
-
|
15
|
-
|
13
|
+
# ZSTDS::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 = ZSTDS::Option
|
20
|
+
|
21
|
+
# Initializes compressor.
|
22
|
+
# Option: +:destination_buffer_length+ destination buffer length.
|
23
|
+
# Option: +:pledged_size+ source bytesize.
|
17
24
|
def initialize(options = {})
|
18
25
|
options = Option.get_compressor_options options, BUFFER_LENGTH_NAMES
|
19
26
|
|
20
27
|
pledged_size = options[:pledged_size]
|
21
28
|
Validation.validate_not_negative_integer pledged_size unless pledged_size.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 zstd library.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require "adsp/stream/raw/decompressor"
|
4
5
|
require "zstds_ext"
|
5
6
|
|
6
|
-
require_relative "abstract"
|
7
7
|
require_relative "../../option"
|
8
|
-
require_relative "../../validation"
|
9
8
|
|
10
9
|
module ZSTDS
|
11
10
|
module Stream
|
12
11
|
module Raw
|
13
|
-
|
14
|
-
|
12
|
+
# ZSTDS::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 = ZSTDS::Option
|
63
19
|
end
|
64
20
|
end
|
65
21
|
end
|