adsp 1.0.2 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{test → lib/adsp/test}/common.rb +4 -1
- data/{test → lib/adsp/test}/coverage_helper.rb +0 -0
- data/lib/adsp/test/file.rb +120 -0
- data/{test → lib/adsp/test}/minitest.rb +1 -0
- data/{test → lib/adsp/test}/mock/common.rb +1 -0
- data/{test → lib/adsp/test}/mock/file.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/raw/compressor.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/raw/decompressor.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/raw/native_compressor.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/raw/native_decompressor.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/reader.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/writer.rb +1 -0
- data/{test → lib/adsp/test}/mock/string.rb +1 -0
- data/{test → lib/adsp/test}/option.rb +1 -0
- data/{test → lib/adsp/test}/stream/abstract.rb +1 -0
- data/lib/adsp/test/stream/minitar.rb +50 -0
- data/{test → lib/adsp/test}/stream/raw/abstract.rb +1 -0
- data/lib/adsp/test/stream/raw/compressor.rb +165 -0
- data/lib/adsp/test/stream/raw/decompressor.rb +165 -0
- data/lib/adsp/test/stream/reader.rb +642 -0
- data/lib/adsp/test/stream/reader_helpers.rb +421 -0
- data/lib/adsp/test/stream/writer.rb +609 -0
- data/lib/adsp/test/stream/writer_helpers.rb +267 -0
- data/lib/adsp/test/string.rb +95 -0
- data/{test → lib/adsp/test}/validation.rb +7 -0
- data/lib/adsp/test/version.rb +18 -0
- data/lib/adsp/version.rb +1 -1
- data/test/file.test.rb +3 -116
- data/test/stream/minitar.test.rb +3 -46
- data/test/stream/raw/compressor.test.rb +3 -162
- data/test/stream/raw/decompressor.test.rb +3 -162
- data/test/stream/reader.test.rb +3 -639
- data/test/stream/reader_helpers.test.rb +3 -417
- data/test/stream/writer.test.rb +3 -606
- data/test/stream/writer_helpers.test.rb +3 -263
- data/test/string.test.rb +3 -91
- data/test/version.test.rb +3 -14
- metadata +28 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30860551943717e9021665e6b9a7579a2a2b51998515dd66bddfbe4a61803dda
|
4
|
+
data.tar.gz: eab7e3ece3ff8153ac5a6e47abdd9cccba8622beb6a04d387c3d214bac35611e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef45beb65c047e2c55cdcd68700aa0cfa456fa0b77653fda659c0c6d093d9e5b82e7ef7bcdff13d9d7c084da4e7490f29c5c2f8dcfcb83c1acc65013ec4d33ec
|
7
|
+
data.tar.gz: 685e128e4d17c3d875135bca4ab169004d2f15d03b3a50bef45998b213517a040dff8892b19143672f1eefcd6ddf0642792728d5db8904e748fcb05cc3780724
|
@@ -9,9 +9,12 @@ require_relative "coverage_helper"
|
|
9
9
|
|
10
10
|
module ADSP
|
11
11
|
module Test
|
12
|
+
# ADSP::Test::Common module.
|
12
13
|
module Common
|
13
|
-
BASE_PATH = ::File.expand_path(::File.join(::File.dirname(__FILE__), "..")).freeze
|
14
|
+
BASE_PATH = ::File.expand_path(::File.join(::File.dirname(__FILE__), "..", "..", "..")).freeze
|
15
|
+
|
14
16
|
TEMP_PATH = ::File.join(BASE_PATH, "tmp").freeze
|
17
|
+
FileUtils.mkdir_p TEMP_PATH
|
15
18
|
|
16
19
|
SOURCE_PATH = ::File.join(TEMP_PATH, "source").freeze
|
17
20
|
ARCHIVE_PATH = ::File.join(TEMP_PATH, "archive").freeze
|
File without changes
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# Abstract data stream processor.
|
2
|
+
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
|
+
|
4
|
+
require "adsp/file"
|
5
|
+
|
6
|
+
require_relative "common"
|
7
|
+
require_relative "minitest"
|
8
|
+
require_relative "mock/file"
|
9
|
+
require_relative "option"
|
10
|
+
require_relative "validation"
|
11
|
+
|
12
|
+
module ADSP
|
13
|
+
# ADSP::Test module.
|
14
|
+
module Test
|
15
|
+
# ADSP::Test::File class.
|
16
|
+
class File < Minitest::Test
|
17
|
+
Option = Test::Option
|
18
|
+
Target = Mock::File
|
19
|
+
|
20
|
+
SOURCE_PATH = Common::SOURCE_PATH
|
21
|
+
ARCHIVE_PATH = Common::ARCHIVE_PATH
|
22
|
+
TEXTS = Common::TEXTS
|
23
|
+
LARGE_TEXTS = Common::LARGE_TEXTS
|
24
|
+
|
25
|
+
BUFFER_LENGTH_NAMES = %i[source_buffer_length destination_buffer_length].freeze
|
26
|
+
BUFFER_LENGTH_MAPPING = {
|
27
|
+
:source_buffer_length => :destination_buffer_length,
|
28
|
+
:destination_buffer_length => :source_buffer_length
|
29
|
+
}
|
30
|
+
.freeze
|
31
|
+
|
32
|
+
def test_invalid_arguments
|
33
|
+
Validation::INVALID_STRINGS.each do |invalid_path|
|
34
|
+
assert_raises ValidateError do
|
35
|
+
Target.compress invalid_path, ARCHIVE_PATH
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_raises ValidateError do
|
39
|
+
Target.compress SOURCE_PATH, invalid_path
|
40
|
+
end
|
41
|
+
|
42
|
+
assert_raises ValidateError do
|
43
|
+
Target.decompress invalid_path, SOURCE_PATH
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_raises ValidateError do
|
47
|
+
Target.decompress ARCHIVE_PATH, invalid_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
get_invalid_compressor_options do |invalid_options|
|
52
|
+
assert_raises ValidateError do
|
53
|
+
Target.compress SOURCE_PATH, ARCHIVE_PATH, invalid_options
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
get_invalid_decompressor_options do |invalid_options|
|
58
|
+
assert_raises ValidateError do
|
59
|
+
Target.decompress ARCHIVE_PATH, SOURCE_PATH, invalid_options
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_texts
|
65
|
+
parallel_compressor_options do |compressor_options, worker_index|
|
66
|
+
source_path = Common.get_path SOURCE_PATH, worker_index
|
67
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
68
|
+
|
69
|
+
TEXTS.each do |text|
|
70
|
+
::File.write source_path, text, :mode => "wb"
|
71
|
+
Target.compress source_path, archive_path, compressor_options
|
72
|
+
|
73
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
74
|
+
Target.decompress archive_path, source_path, decompressor_options
|
75
|
+
|
76
|
+
decompressed_text = ::File.read source_path, :mode => "rb"
|
77
|
+
decompressed_text.force_encoding text.encoding
|
78
|
+
|
79
|
+
assert_equal text, decompressed_text
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_large_texts
|
86
|
+
Common.parallel LARGE_TEXTS do |text, worker_index|
|
87
|
+
source_path = Common.get_path SOURCE_PATH, worker_index
|
88
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
89
|
+
|
90
|
+
::File.write source_path, text, :mode => "wb"
|
91
|
+
Target.compress source_path, archive_path
|
92
|
+
Target.decompress archive_path, source_path
|
93
|
+
|
94
|
+
decompressed_text = ::File.read source_path, :mode => "rb"
|
95
|
+
decompressed_text.force_encoding text.encoding
|
96
|
+
|
97
|
+
assert_equal text, decompressed_text
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# -----
|
102
|
+
|
103
|
+
def get_invalid_compressor_options(&block)
|
104
|
+
self.class::Option.get_invalid_compressor_options BUFFER_LENGTH_NAMES, &block
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_invalid_decompressor_options(&block)
|
108
|
+
self.class::Option.get_invalid_decompressor_options BUFFER_LENGTH_NAMES, &block
|
109
|
+
end
|
110
|
+
|
111
|
+
def parallel_compressor_options(&block)
|
112
|
+
Common.parallel_options self.class::Option.get_compressor_options_generator(BUFFER_LENGTH_NAMES), &block
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_compatible_decompressor_options(compressor_options, &block)
|
116
|
+
self.class::Option.get_compatible_decompressor_options compressor_options, BUFFER_LENGTH_MAPPING, &block
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Abstract data stream processor.
|
2
|
+
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
|
+
|
4
|
+
require "minitar"
|
5
|
+
|
6
|
+
require_relative "../common"
|
7
|
+
require_relative "../minitest"
|
8
|
+
require_relative "../mock/stream/reader"
|
9
|
+
require_relative "../mock/stream/writer"
|
10
|
+
|
11
|
+
module ADSP
|
12
|
+
module Test
|
13
|
+
# ADSP::Test::Stream module.
|
14
|
+
module Stream
|
15
|
+
# ADSP::Test::Stream::MinitarTest class.
|
16
|
+
class MinitarTest < Minitest::Test
|
17
|
+
Reader = Mock::Stream::Reader
|
18
|
+
Writer = Mock::Stream::Writer
|
19
|
+
|
20
|
+
ARCHIVE_PATH = Common::ARCHIVE_PATH
|
21
|
+
LARGE_TEXTS = Common::LARGE_TEXTS
|
22
|
+
|
23
|
+
def test_tar
|
24
|
+
Common.parallel LARGE_TEXTS do |text, worker_index|
|
25
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
26
|
+
|
27
|
+
Writer.open archive_path do |writer|
|
28
|
+
Minitar::Writer.open writer do |tar|
|
29
|
+
tar.add_file_simple "file", :data => text
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Reader.open archive_path do |reader|
|
34
|
+
Minitar::Reader.open reader do |tar|
|
35
|
+
tar.each_entry do |entry|
|
36
|
+
assert_equal "file", entry.name
|
37
|
+
|
38
|
+
decompressed_text = entry.read
|
39
|
+
decompressed_text.force_encoding text.encoding
|
40
|
+
|
41
|
+
assert_equal text, decompressed_text
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# Abstract data stream processor.
|
2
|
+
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
|
+
|
4
|
+
require_relative "abstract"
|
5
|
+
require_relative "../../common"
|
6
|
+
require_relative "../../mock/stream/raw/compressor"
|
7
|
+
require_relative "../../mock/string"
|
8
|
+
require_relative "../../option"
|
9
|
+
require_relative "../../validation"
|
10
|
+
|
11
|
+
module ADSP
|
12
|
+
module Test
|
13
|
+
module Stream
|
14
|
+
# ADSP::Test::Stream::Raw module.
|
15
|
+
module Raw
|
16
|
+
# ADSP::Test::Stream::Raw::Compressor class.
|
17
|
+
class Compressor < Abstract
|
18
|
+
Target = Mock::Stream::Raw::Compressor
|
19
|
+
String = Mock::String
|
20
|
+
|
21
|
+
TEXTS = Common::TEXTS
|
22
|
+
LARGE_TEXTS = Common::LARGE_TEXTS
|
23
|
+
PORTION_LENGTHS = Common::PORTION_LENGTHS
|
24
|
+
LARGE_PORTION_LENGTHS = Common::LARGE_PORTION_LENGTHS
|
25
|
+
|
26
|
+
BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
|
27
|
+
BUFFER_LENGTH_MAPPING = { :destination_buffer_length => :destination_buffer_length }.freeze
|
28
|
+
|
29
|
+
def test_invalid_initialize
|
30
|
+
get_invalid_compressor_options do |invalid_options|
|
31
|
+
assert_raises ValidateError do
|
32
|
+
Target.new invalid_options
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_invalid_write
|
38
|
+
compressor = Target.new
|
39
|
+
|
40
|
+
Validation::INVALID_STRINGS.each do |invalid_string|
|
41
|
+
assert_raises ValidateError do
|
42
|
+
compressor.write invalid_string, &NOOP_PROC
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_raises ValidateError do
|
47
|
+
compressor.write ""
|
48
|
+
end
|
49
|
+
|
50
|
+
compressor.close(&NOOP_PROC)
|
51
|
+
|
52
|
+
assert_raises UsedAfterCloseError do
|
53
|
+
compressor.write "", &NOOP_PROC
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_texts
|
58
|
+
parallel_compressor_options do |compressor_options|
|
59
|
+
TEXTS.each do |text|
|
60
|
+
PORTION_LENGTHS.each do |portion_length|
|
61
|
+
compressed_buffer = ::StringIO.new
|
62
|
+
compressed_buffer.set_encoding ::Encoding::BINARY
|
63
|
+
|
64
|
+
writer = proc { |portion| compressed_buffer << portion }
|
65
|
+
compressor = Target.new compressor_options
|
66
|
+
|
67
|
+
begin
|
68
|
+
source = "".b
|
69
|
+
text_offset = 0
|
70
|
+
index = 0
|
71
|
+
|
72
|
+
loop do
|
73
|
+
portion = text.byteslice text_offset, portion_length
|
74
|
+
break if portion.nil?
|
75
|
+
|
76
|
+
text_offset += portion_length
|
77
|
+
source << portion
|
78
|
+
|
79
|
+
bytes_written = compressor.write source, &writer
|
80
|
+
source = source.byteslice bytes_written, source.bytesize - bytes_written
|
81
|
+
|
82
|
+
compressor.flush(&writer) if index.even?
|
83
|
+
index += 1
|
84
|
+
end
|
85
|
+
|
86
|
+
ensure
|
87
|
+
refute_predicate compressor, :closed?
|
88
|
+
compressor.close(&writer)
|
89
|
+
assert_predicate compressor, :closed?
|
90
|
+
end
|
91
|
+
|
92
|
+
compressed_text = compressed_buffer.string
|
93
|
+
|
94
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
95
|
+
decompressed_text = String.decompress compressed_text, decompressor_options
|
96
|
+
decompressed_text.force_encoding text.encoding
|
97
|
+
|
98
|
+
assert_equal text, decompressed_text
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_large_texts
|
106
|
+
options_generator = OCG.new(
|
107
|
+
:text => LARGE_TEXTS,
|
108
|
+
:portion_length => LARGE_PORTION_LENGTHS
|
109
|
+
)
|
110
|
+
|
111
|
+
Common.parallel_options options_generator do |options|
|
112
|
+
text = options[:text]
|
113
|
+
portion_length = options[:portion_length]
|
114
|
+
|
115
|
+
compressed_buffer = ::StringIO.new
|
116
|
+
compressed_buffer.set_encoding ::Encoding::BINARY
|
117
|
+
|
118
|
+
writer = proc { |portion| compressed_buffer << portion }
|
119
|
+
compressor = Target.new
|
120
|
+
|
121
|
+
begin
|
122
|
+
source = "".b
|
123
|
+
text_offset = 0
|
124
|
+
|
125
|
+
loop do
|
126
|
+
portion = text.byteslice text_offset, portion_length
|
127
|
+
break if portion.nil?
|
128
|
+
|
129
|
+
text_offset += portion_length
|
130
|
+
source << portion
|
131
|
+
|
132
|
+
bytes_written = compressor.write source, &writer
|
133
|
+
source = source.byteslice bytes_written, source.bytesize - bytes_written
|
134
|
+
end
|
135
|
+
ensure
|
136
|
+
compressor.close(&writer)
|
137
|
+
end
|
138
|
+
|
139
|
+
compressed_text = compressed_buffer.string
|
140
|
+
|
141
|
+
decompressed_text = String.decompress compressed_text
|
142
|
+
decompressed_text.force_encoding text.encoding
|
143
|
+
|
144
|
+
assert_equal text, decompressed_text
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# -----
|
149
|
+
|
150
|
+
def get_invalid_compressor_options(&block)
|
151
|
+
Option.get_invalid_compressor_options BUFFER_LENGTH_NAMES, &block
|
152
|
+
end
|
153
|
+
|
154
|
+
def parallel_compressor_options(&block)
|
155
|
+
Common.parallel_options Option.get_compressor_options_generator(BUFFER_LENGTH_NAMES), &block
|
156
|
+
end
|
157
|
+
|
158
|
+
def get_compatible_decompressor_options(compressor_options, &block)
|
159
|
+
Option.get_compatible_decompressor_options compressor_options, BUFFER_LENGTH_MAPPING, &block
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# Abstract data stream processor.
|
2
|
+
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
|
+
|
4
|
+
require_relative "abstract"
|
5
|
+
require_relative "../../common"
|
6
|
+
require_relative "../../mock/stream/raw/decompressor"
|
7
|
+
require_relative "../../mock/string"
|
8
|
+
require_relative "../../option"
|
9
|
+
require_relative "../../validation"
|
10
|
+
|
11
|
+
module ADSP
|
12
|
+
module Test
|
13
|
+
module Stream
|
14
|
+
# ADSP::Test::Stream::Raw module.
|
15
|
+
module Raw
|
16
|
+
# ADSP::Test::Stream::Raw::Decompressor class.
|
17
|
+
class Decompressor < Abstract
|
18
|
+
Target = Mock::Stream::Raw::Decompressor
|
19
|
+
String = Mock::String
|
20
|
+
|
21
|
+
TEXTS = Common::TEXTS
|
22
|
+
LARGE_TEXTS = Common::LARGE_TEXTS
|
23
|
+
PORTION_LENGTHS = Common::PORTION_LENGTHS
|
24
|
+
LARGE_PORTION_LENGTHS = Common::LARGE_PORTION_LENGTHS
|
25
|
+
|
26
|
+
BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
|
27
|
+
BUFFER_LENGTH_MAPPING = { :destination_buffer_length => :destination_buffer_length }.freeze
|
28
|
+
|
29
|
+
def test_invalid_initialize
|
30
|
+
get_invalid_decompressor_options do |invalid_options|
|
31
|
+
assert_raises ValidateError do
|
32
|
+
Target.new invalid_options
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_invalid_read
|
38
|
+
decompressor = Target.new
|
39
|
+
|
40
|
+
Validation::INVALID_STRINGS.each do |invalid_string|
|
41
|
+
assert_raises ValidateError do
|
42
|
+
decompressor.read invalid_string, &NOOP_PROC
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_raises ValidateError do
|
47
|
+
decompressor.read ""
|
48
|
+
end
|
49
|
+
|
50
|
+
decompressor.close(&NOOP_PROC)
|
51
|
+
|
52
|
+
assert_raises UsedAfterCloseError do
|
53
|
+
decompressor.read "", &NOOP_PROC
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_texts
|
58
|
+
parallel_compressor_options do |compressor_options|
|
59
|
+
TEXTS.each do |text|
|
60
|
+
compressed_text = String.compress text, compressor_options
|
61
|
+
|
62
|
+
PORTION_LENGTHS.each do |portion_length|
|
63
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
64
|
+
decompressed_buffer = ::StringIO.new
|
65
|
+
decompressed_buffer.set_encoding ::Encoding::BINARY
|
66
|
+
|
67
|
+
writer = proc { |portion| decompressed_buffer << portion }
|
68
|
+
decompressor = Target.new decompressor_options
|
69
|
+
|
70
|
+
begin
|
71
|
+
source = "".b
|
72
|
+
compressed_text_offset = 0
|
73
|
+
index = 0
|
74
|
+
|
75
|
+
loop do
|
76
|
+
portion = compressed_text.byteslice compressed_text_offset, portion_length
|
77
|
+
break if portion.nil?
|
78
|
+
|
79
|
+
compressed_text_offset += portion_length
|
80
|
+
source << portion
|
81
|
+
|
82
|
+
bytes_read = decompressor.read source, &writer
|
83
|
+
source = source.byteslice bytes_read, source.bytesize - bytes_read
|
84
|
+
|
85
|
+
decompressor.flush(&writer) if index.even?
|
86
|
+
index += 1
|
87
|
+
end
|
88
|
+
|
89
|
+
ensure
|
90
|
+
refute_predicate decompressor, :closed?
|
91
|
+
decompressor.close(&writer)
|
92
|
+
assert_predicate decompressor, :closed?
|
93
|
+
end
|
94
|
+
|
95
|
+
decompressed_text = decompressed_buffer.string
|
96
|
+
decompressed_text.force_encoding text.encoding
|
97
|
+
|
98
|
+
assert_equal text, decompressed_text
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_large_texts
|
106
|
+
options_generator = OCG.new(
|
107
|
+
:text => LARGE_TEXTS,
|
108
|
+
:portion_length => LARGE_PORTION_LENGTHS
|
109
|
+
)
|
110
|
+
|
111
|
+
Common.parallel_options options_generator do |options|
|
112
|
+
text = options[:text]
|
113
|
+
portion_length = options[:portion_length]
|
114
|
+
|
115
|
+
compressed_text = String.compress text
|
116
|
+
|
117
|
+
decompressed_buffer = ::StringIO.new
|
118
|
+
decompressed_buffer.set_encoding ::Encoding::BINARY
|
119
|
+
|
120
|
+
writer = proc { |portion| decompressed_buffer << portion }
|
121
|
+
decompressor = Target.new
|
122
|
+
|
123
|
+
begin
|
124
|
+
source = "".b
|
125
|
+
compressed_text_offset = 0
|
126
|
+
|
127
|
+
loop do
|
128
|
+
portion = compressed_text.byteslice compressed_text_offset, portion_length
|
129
|
+
break if portion.nil?
|
130
|
+
|
131
|
+
compressed_text_offset += portion_length
|
132
|
+
source << portion
|
133
|
+
|
134
|
+
bytes_read = decompressor.read source, &writer
|
135
|
+
source = source.byteslice bytes_read, source.bytesize - bytes_read
|
136
|
+
end
|
137
|
+
ensure
|
138
|
+
decompressor.close(&writer)
|
139
|
+
end
|
140
|
+
|
141
|
+
decompressed_text = decompressed_buffer.string
|
142
|
+
decompressed_text.force_encoding text.encoding
|
143
|
+
|
144
|
+
assert_equal text, decompressed_text
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# -----
|
149
|
+
|
150
|
+
def get_invalid_decompressor_options(&block)
|
151
|
+
Option.get_invalid_decompressor_options BUFFER_LENGTH_NAMES, &block
|
152
|
+
end
|
153
|
+
|
154
|
+
def parallel_compressor_options(&block)
|
155
|
+
Common.parallel_options Option.get_compressor_options_generator(BUFFER_LENGTH_NAMES), &block
|
156
|
+
end
|
157
|
+
|
158
|
+
def get_compatible_decompressor_options(compressor_options, &block)
|
159
|
+
Option.get_compatible_decompressor_options compressor_options, BUFFER_LENGTH_MAPPING, &block
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|