iostreams 1.1.0 → 1.1.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 +1 -1
- data/Rakefile +7 -7
- data/lib/io_streams/builder.rb +4 -3
- data/lib/io_streams/bzip2/reader.rb +1 -1
- data/lib/io_streams/bzip2/writer.rb +1 -1
- data/lib/io_streams/deprecated.rb +2 -3
- data/lib/io_streams/encode/reader.rb +5 -8
- data/lib/io_streams/encode/writer.rb +1 -1
- data/lib/io_streams/io_streams.rb +5 -2
- data/lib/io_streams/line/reader.rb +2 -1
- data/lib/io_streams/path.rb +4 -4
- data/lib/io_streams/paths/http.rb +8 -10
- data/lib/io_streams/paths/matcher.rb +10 -11
- data/lib/io_streams/paths/s3.rb +6 -6
- data/lib/io_streams/paths/sftp.rb +38 -23
- data/lib/io_streams/pgp.rb +45 -35
- data/lib/io_streams/pgp/reader.rb +4 -6
- data/lib/io_streams/pgp/writer.rb +1 -2
- data/lib/io_streams/reader.rb +2 -2
- data/lib/io_streams/record/writer.rb +2 -4
- data/lib/io_streams/row/writer.rb +3 -5
- data/lib/io_streams/stream.rb +6 -6
- data/lib/io_streams/symmetric_encryption/reader.rb +1 -3
- data/lib/io_streams/symmetric_encryption/writer.rb +2 -6
- data/lib/io_streams/tabular.rb +12 -10
- data/lib/io_streams/tabular/header.rb +4 -4
- data/lib/io_streams/tabular/parser/array.rb +2 -4
- data/lib/io_streams/tabular/parser/csv.rb +3 -5
- data/lib/io_streams/tabular/parser/fixed.rb +4 -3
- data/lib/io_streams/tabular/parser/hash.rb +2 -4
- data/lib/io_streams/tabular/parser/json.rb +2 -4
- data/lib/io_streams/tabular/parser/psv.rb +5 -7
- data/lib/io_streams/tabular/utility/csv_row.rb +9 -17
- data/lib/io_streams/utils.rb +3 -3
- data/lib/io_streams/utils/reliable_http.rb +98 -0
- data/lib/io_streams/version.rb +1 -1
- data/lib/io_streams/writer.rb +1 -1
- data/lib/io_streams/xlsx/reader.rb +5 -5
- data/lib/io_streams/zip/reader.rb +1 -1
- data/lib/io_streams/zip/writer.rb +2 -2
- data/lib/iostreams.rb +34 -34
- data/test/builder_test.rb +74 -74
- data/test/bzip2_reader_test.rb +8 -13
- data/test/bzip2_writer_test.rb +8 -9
- data/test/deprecated_test.rb +25 -29
- data/test/encode_reader_test.rb +14 -18
- data/test/encode_writer_test.rb +29 -30
- data/test/gzip_reader_test.rb +8 -13
- data/test/gzip_writer_test.rb +10 -11
- data/test/io_streams_test.rb +35 -35
- data/test/line_reader_test.rb +35 -39
- data/test/line_writer_test.rb +8 -9
- data/test/minimal_file_reader.rb +1 -1
- data/test/path_test.rb +24 -24
- data/test/paths/file_test.rb +42 -42
- data/test/paths/http_test.rb +5 -5
- data/test/paths/matcher_test.rb +11 -12
- data/test/paths/s3_test.rb +44 -46
- data/test/paths/sftp_test.rb +18 -18
- data/test/pgp_reader_test.rb +13 -15
- data/test/pgp_test.rb +43 -44
- data/test/pgp_writer_test.rb +27 -28
- data/test/record_reader_test.rb +9 -10
- data/test/record_writer_test.rb +10 -11
- data/test/row_reader_test.rb +5 -6
- data/test/row_writer_test.rb +7 -8
- data/test/stream_test.rb +60 -62
- data/test/tabular_test.rb +111 -111
- data/test/test_helper.rb +22 -22
- data/test/utils_test.rb +7 -7
- data/test/xlsx_reader_test.rb +12 -12
- data/test/zip_reader_test.rb +14 -21
- data/test/zip_writer_test.rb +10 -10
- metadata +4 -3
data/test/builder_test.rb
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
3
|
class BuilderTest < Minitest::Test
|
4
4
|
describe IOStreams::Builder do
|
5
|
-
let(:file_name) {
|
5
|
+
let(:file_name) { "my/path/abc.bcd.xlsx.zip.gz.pgp" }
|
6
6
|
let(:streams) { IOStreams::Builder.new(file_name) }
|
7
7
|
|
8
|
-
describe
|
9
|
-
it
|
10
|
-
streams.option(:pgp, passphrase:
|
11
|
-
assert_equal({pgp: {passphrase:
|
8
|
+
describe "#option" do
|
9
|
+
it "adds one option" do
|
10
|
+
streams.option(:pgp, passphrase: "unlock-me")
|
11
|
+
assert_equal({pgp: {passphrase: "unlock-me"}}, streams.options)
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
15
|
-
streams.option(:pgp, passphrase:
|
14
|
+
it "adds options in order" do
|
15
|
+
streams.option(:pgp, passphrase: "unlock-me")
|
16
16
|
streams.option(:enc, compress: false)
|
17
|
-
assert_equal({pgp: {passphrase:
|
17
|
+
assert_equal({pgp: {passphrase: "unlock-me"}, enc: {compress: false}}, streams.options)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
streams.stream(:pgp, passphrase:
|
20
|
+
it "will not add an option if a stream was already set" do
|
21
|
+
streams.stream(:pgp, passphrase: "unlock-me")
|
22
22
|
assert_raises ArgumentError do
|
23
|
-
streams.option(:pgp, passphrase:
|
23
|
+
streams.option(:pgp, passphrase: "unlock-me")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it "will not add an invalid option" do
|
28
28
|
assert_raises ArgumentError do
|
29
29
|
streams.option(:blah, value: 23)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe
|
33
|
+
describe "with no file_name" do
|
34
34
|
let(:file_name) { nil }
|
35
35
|
|
36
|
-
it
|
36
|
+
it "prevents options being set" do
|
37
37
|
assert_raises ArgumentError do
|
38
|
-
streams.option(:pgp, passphrase:
|
38
|
+
streams.option(:pgp, passphrase: "unlock-me")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe
|
45
|
-
it
|
46
|
-
streams.stream(:pgp, passphrase:
|
47
|
-
assert_equal({pgp: {passphrase:
|
44
|
+
describe "#stream" do
|
45
|
+
it "adds one stream" do
|
46
|
+
streams.stream(:pgp, passphrase: "unlock-me")
|
47
|
+
assert_equal({pgp: {passphrase: "unlock-me"}}, streams.streams)
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
streams.stream(:pgp, passphrase:
|
50
|
+
it "adds streams in order" do
|
51
|
+
streams.stream(:pgp, passphrase: "unlock-me")
|
52
52
|
streams.stream(:enc, compress: false)
|
53
|
-
assert_equal({pgp: {passphrase:
|
53
|
+
assert_equal({pgp: {passphrase: "unlock-me"}, enc: {compress: false}}, streams.streams)
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
57
|
-
streams.option(:pgp, passphrase:
|
56
|
+
it "will not add a stream if an option was already set" do
|
57
|
+
streams.option(:pgp, passphrase: "unlock-me")
|
58
58
|
assert_raises ArgumentError do
|
59
|
-
streams.stream(:pgp, passphrase:
|
59
|
+
streams.stream(:pgp, passphrase: "unlock-me")
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it "will not add an invalid stream" do
|
64
64
|
assert_raises ArgumentError do
|
65
65
|
streams.stream(:blah, value: 23)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
describe
|
70
|
+
describe "#reader" do
|
71
71
|
let :gzip_string do
|
72
|
-
io_string = StringIO.new(
|
72
|
+
io_string = StringIO.new("".b)
|
73
73
|
IOStreams::Gzip::Writer.stream(io_string) do |io|
|
74
74
|
io.write("Hello World")
|
75
75
|
end
|
76
76
|
io_string.string
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
79
|
+
it "directly calls block for an empty stream" do
|
80
80
|
string_io = StringIO.new
|
81
81
|
value = nil
|
82
82
|
streams.stream(:none)
|
@@ -87,7 +87,7 @@ class BuilderTest < Minitest::Test
|
|
87
87
|
assert_equal 32, value
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
90
|
+
it "returns the reader" do
|
91
91
|
string_io = StringIO.new(gzip_string)
|
92
92
|
streams.stream(:gz)
|
93
93
|
streams.reader(string_io) do |io|
|
@@ -95,7 +95,7 @@ class BuilderTest < Minitest::Test
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
it
|
98
|
+
it "returns the last reader" do
|
99
99
|
string_io = StringIO.new(gzip_string)
|
100
100
|
streams.stream(:encode)
|
101
101
|
streams.stream(:gz)
|
@@ -105,8 +105,8 @@ class BuilderTest < Minitest::Test
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
describe
|
109
|
-
it
|
108
|
+
describe "#writer" do
|
109
|
+
it "directly calls block for an empty stream" do
|
110
110
|
string_io = StringIO.new
|
111
111
|
value = nil
|
112
112
|
streams.stream(:none)
|
@@ -117,7 +117,7 @@ class BuilderTest < Minitest::Test
|
|
117
117
|
assert_equal 32, value
|
118
118
|
end
|
119
119
|
|
120
|
-
it
|
120
|
+
it "returns the reader" do
|
121
121
|
string_io = StringIO.new
|
122
122
|
streams.stream(:zip)
|
123
123
|
streams.writer(string_io) do |io|
|
@@ -125,7 +125,7 @@ class BuilderTest < Minitest::Test
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
it
|
128
|
+
it "returns the last reader" do
|
129
129
|
string_io = StringIO.new
|
130
130
|
streams.stream(:encode)
|
131
131
|
streams.stream(:zip)
|
@@ -137,79 +137,79 @@ class BuilderTest < Minitest::Test
|
|
137
137
|
|
138
138
|
# Internal methods
|
139
139
|
|
140
|
-
describe
|
141
|
-
it
|
140
|
+
describe "#class_for_stream" do
|
141
|
+
it "xlsx" do
|
142
142
|
assert_equal IOStreams::Xlsx::Reader, streams.send(:class_for_stream, :reader, :xlsx)
|
143
143
|
end
|
144
144
|
|
145
|
-
it
|
145
|
+
it "gzip" do
|
146
146
|
assert_equal IOStreams::Gzip::Writer, streams.send(:class_for_stream, :writer, :gzip)
|
147
147
|
end
|
148
148
|
|
149
|
-
it
|
149
|
+
it "unknown" do
|
150
150
|
assert_raises ArgumentError do
|
151
151
|
streams.send(:class_for_stream, :reader, :unknown)
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
describe
|
157
|
-
it
|
158
|
-
streams = IOStreams::Builder.new(
|
156
|
+
describe "#parse_extensions" do
|
157
|
+
it "single stream" do
|
158
|
+
streams = IOStreams::Builder.new("my/path/abc.xlsx")
|
159
159
|
assert_equal %i[xlsx], streams.send(:parse_extensions)
|
160
160
|
end
|
161
161
|
|
162
|
-
it
|
163
|
-
streams = IOStreams::Builder.new(
|
162
|
+
it "empty" do
|
163
|
+
streams = IOStreams::Builder.new("my/path/abc.csv")
|
164
164
|
assert_equal [], streams.send(:parse_extensions)
|
165
165
|
end
|
166
166
|
|
167
|
-
it
|
167
|
+
it "handles multiple extensions" do
|
168
168
|
assert_equal %i[xlsx zip gz pgp], streams.send(:parse_extensions)
|
169
169
|
end
|
170
170
|
|
171
|
-
describe
|
172
|
-
let(:file_name) {
|
171
|
+
describe "case-insensitive" do
|
172
|
+
let(:file_name) { "a.XlsX.GzIp" }
|
173
173
|
|
174
|
-
it
|
174
|
+
it "is case-insensitive" do
|
175
175
|
assert_equal %i[xlsx gzip], streams.send(:parse_extensions)
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
|
-
describe
|
181
|
-
it
|
180
|
+
describe "#pipeline" do
|
181
|
+
it "with stream and file name" do
|
182
182
|
expected = {enc: {compress: false}}
|
183
183
|
streams.stream(:enc, compress: false)
|
184
184
|
assert_equal expected, streams.pipeline
|
185
185
|
end
|
186
186
|
|
187
|
-
it
|
187
|
+
it "no file name, streams, or options" do
|
188
188
|
expected = {}
|
189
189
|
streams = IOStreams::Builder.new
|
190
190
|
assert_equal expected, streams.pipeline
|
191
191
|
end
|
192
192
|
|
193
|
-
it
|
194
|
-
expected = {:
|
193
|
+
it "file name without options" do
|
194
|
+
expected = {xlsx: {}, zip: {}, gz: {}, pgp: {}}
|
195
195
|
assert_equal expected, streams.pipeline
|
196
196
|
end
|
197
197
|
|
198
|
-
it
|
199
|
-
expected = {encode: {encoding:
|
200
|
-
streams.option(:encode, encoding:
|
198
|
+
it "file name with encode option" do
|
199
|
+
expected = {encode: {encoding: "BINARY"}, xlsx: {}, zip: {}, gz: {}, pgp: {}}
|
200
|
+
streams.option(:encode, encoding: "BINARY")
|
201
201
|
assert_equal expected, streams.pipeline
|
202
202
|
end
|
203
203
|
|
204
|
-
it
|
205
|
-
expected = {:
|
206
|
-
streams.option(:pgp, passphrase:
|
204
|
+
it "file name with option" do
|
205
|
+
expected = {xlsx: {}, zip: {}, gz: {}, pgp: {passphrase: "unlock-me"}}
|
206
|
+
streams.option(:pgp, passphrase: "unlock-me")
|
207
207
|
assert_equal expected, streams.pipeline
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
describe
|
212
|
-
it
|
211
|
+
describe "#execute" do
|
212
|
+
it "directly calls block for an empty stream" do
|
213
213
|
string_io = StringIO.new
|
214
214
|
value = nil
|
215
215
|
streams.send(:execute, :writer, {}, string_io) do |io|
|
@@ -219,25 +219,25 @@ class BuilderTest < Minitest::Test
|
|
219
219
|
assert_equal 32, value
|
220
220
|
end
|
221
221
|
|
222
|
-
it
|
223
|
-
pipeline = {simple: {arg:
|
222
|
+
it "calls last block in one element stream" do
|
223
|
+
pipeline = {simple: {arg: "first"}}
|
224
224
|
string_io = StringIO.new
|
225
|
-
streams.send(:execute, :writer, pipeline, string_io) { |io| io.write(
|
226
|
-
assert_equal
|
225
|
+
streams.send(:execute, :writer, pipeline, string_io) { |io| io.write("last") }
|
226
|
+
assert_equal "first>last", string_io.string
|
227
227
|
end
|
228
228
|
|
229
|
-
it
|
230
|
-
pipeline = {simple: {arg:
|
229
|
+
it "chains blocks in 2 element stream" do
|
230
|
+
pipeline = {simple: {arg: "first"}, simple2: {arg: "second"}}
|
231
231
|
string_io = StringIO.new
|
232
|
-
streams.send(:execute, :writer, pipeline, string_io) { |io| io.write(
|
233
|
-
assert_equal
|
232
|
+
streams.send(:execute, :writer, pipeline, string_io) { |io| io.write("last") }
|
233
|
+
assert_equal "second>first>last", string_io.string
|
234
234
|
end
|
235
235
|
|
236
|
-
it
|
237
|
-
pipeline = {simple: {arg:
|
236
|
+
it "chains blocks in 3 element stream" do
|
237
|
+
pipeline = {simple: {arg: "first"}, simple2: {arg: "second"}, simple3: {arg: "third"}}
|
238
238
|
string_io = StringIO.new
|
239
|
-
streams.send(:execute, :writer, pipeline, string_io) { |io| io.write(
|
240
|
-
assert_equal
|
239
|
+
streams.send(:execute, :writer, pipeline, string_io) { |io| io.write("last") }
|
240
|
+
assert_equal "third>second>first>last", string_io.string
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
data/test/bzip2_reader_test.rb
CHANGED
@@ -1,32 +1,27 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
3
|
class Bzip2ReaderTest < Minitest::Test
|
4
4
|
describe IOStreams::Bzip2::Reader do
|
5
5
|
let :file_name do
|
6
|
-
File.join(File.dirname(__FILE__),
|
6
|
+
File.join(File.dirname(__FILE__), "files", "text.txt.bz2")
|
7
7
|
end
|
8
8
|
|
9
9
|
let :decompressed do
|
10
|
-
File.read(File.join(File.dirname(__FILE__),
|
10
|
+
File.read(File.join(File.dirname(__FILE__), "files", "text.txt"))
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
15
|
-
result = IOStreams::Bzip2::Reader.file(file_name)
|
16
|
-
io.read
|
17
|
-
end
|
13
|
+
describe ".file" do
|
14
|
+
it "file" do
|
15
|
+
result = IOStreams::Bzip2::Reader.file(file_name, &:read)
|
18
16
|
assert_equal decompressed, result
|
19
17
|
end
|
20
18
|
|
21
|
-
it
|
19
|
+
it "stream" do
|
22
20
|
result = File.open(file_name) do |file|
|
23
|
-
IOStreams::Bzip2::Reader.stream(file)
|
24
|
-
io.read
|
25
|
-
end
|
21
|
+
IOStreams::Bzip2::Reader.stream(file, &:read)
|
26
22
|
end
|
27
23
|
assert_equal decompressed, result
|
28
24
|
end
|
29
25
|
end
|
30
|
-
|
31
26
|
end
|
32
27
|
end
|
data/test/bzip2_writer_test.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
3
|
class Bzip2WriterTest < Minitest::Test
|
4
4
|
describe IOStreams::Bzip2::Writer do
|
5
5
|
let :temp_file do
|
6
|
-
Tempfile.new(
|
6
|
+
Tempfile.new("iostreams")
|
7
7
|
end
|
8
8
|
|
9
9
|
let :file_name do
|
@@ -11,20 +11,20 @@ class Bzip2WriterTest < Minitest::Test
|
|
11
11
|
end
|
12
12
|
|
13
13
|
let :decompressed do
|
14
|
-
File.read(File.join(File.dirname(__FILE__),
|
14
|
+
File.read(File.join(File.dirname(__FILE__), "files", "text.txt"))
|
15
15
|
end
|
16
16
|
|
17
17
|
after do
|
18
18
|
temp_file.delete
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
it
|
21
|
+
describe ".file" do
|
22
|
+
it "file" do
|
23
23
|
IOStreams::Bzip2::Writer.file(file_name) do |io|
|
24
24
|
io.write(decompressed)
|
25
25
|
end
|
26
26
|
|
27
|
-
File.open(file_name,
|
27
|
+
File.open(file_name, "rb") do |file|
|
28
28
|
io = RBzip2.default_adapter::Decompressor.new(file)
|
29
29
|
result = io.read
|
30
30
|
temp_file.delete
|
@@ -32,8 +32,8 @@ class Bzip2WriterTest < Minitest::Test
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
36
|
-
io_string = StringIO.new(
|
35
|
+
it "stream" do
|
36
|
+
io_string = StringIO.new("".b)
|
37
37
|
IOStreams::Bzip2::Writer.stream(io_string) do |io|
|
38
38
|
io.write(decompressed)
|
39
39
|
end
|
@@ -44,6 +44,5 @@ class Bzip2WriterTest < Minitest::Test
|
|
44
44
|
assert_equal decompressed, data
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
48
47
|
end
|
49
48
|
end
|
data/test/deprecated_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
3
|
# Test deprecated api
|
4
4
|
class DeprecatedTest < Minitest::Test
|
5
5
|
describe IOStreams do
|
6
6
|
let :source_file_name do
|
7
|
-
File.join(__dir__,
|
7
|
+
File.join(__dir__, "files", "text.txt")
|
8
8
|
end
|
9
9
|
|
10
10
|
let :data do
|
@@ -12,7 +12,7 @@ class DeprecatedTest < Minitest::Test
|
|
12
12
|
end
|
13
13
|
|
14
14
|
let :temp_file do
|
15
|
-
Tempfile.new(
|
15
|
+
Tempfile.new("iostreams")
|
16
16
|
end
|
17
17
|
|
18
18
|
let :target_file_name do
|
@@ -22,38 +22,38 @@ class DeprecatedTest < Minitest::Test
|
|
22
22
|
let :bad_data do
|
23
23
|
[
|
24
24
|
"New M\xE9xico,NE".b,
|
25
|
-
|
25
|
+
"good line",
|
26
26
|
"New M\xE9xico,\x07SF".b
|
27
|
-
].join("\n").encode(
|
27
|
+
].join("\n").encode("BINARY")
|
28
28
|
end
|
29
29
|
|
30
30
|
let :stripped_data do
|
31
|
-
bad_data.gsub("\xE9".b,
|
31
|
+
bad_data.gsub("\xE9".b, "").gsub("\x07", "")
|
32
32
|
end
|
33
33
|
|
34
34
|
let :multiple_zip_file_name do
|
35
|
-
File.join(File.dirname(__FILE__),
|
35
|
+
File.join(File.dirname(__FILE__), "files", "multiple_files.zip")
|
36
36
|
end
|
37
37
|
|
38
38
|
let :zip_gz_file_name do
|
39
|
-
File.join(File.dirname(__FILE__),
|
39
|
+
File.join(File.dirname(__FILE__), "files", "text.zip.gz")
|
40
40
|
end
|
41
41
|
|
42
42
|
let :contents_test_txt do
|
43
|
-
File.read(File.join(File.dirname(__FILE__),
|
43
|
+
File.read(File.join(File.dirname(__FILE__), "files", "text.txt"))
|
44
44
|
end
|
45
45
|
|
46
46
|
let :contents_test_json do
|
47
|
-
File.read(File.join(File.dirname(__FILE__),
|
47
|
+
File.read(File.join(File.dirname(__FILE__), "files", "test.json"))
|
48
48
|
end
|
49
49
|
|
50
50
|
after do
|
51
51
|
temp_file.delete
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
55
|
-
it
|
56
|
-
size
|
54
|
+
describe ".copy" do
|
55
|
+
it "streams" do
|
56
|
+
size = IOStreams.reader(source_file_name) do |source_stream|
|
57
57
|
IOStreams.writer(target_file_name) do |target_stream|
|
58
58
|
IOStreams.copy(source_stream, target_stream)
|
59
59
|
end
|
@@ -64,8 +64,8 @@ class DeprecatedTest < Minitest::Test
|
|
64
64
|
assert_equal actual.size, size
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
68
|
-
size
|
67
|
+
it "IO stream" do
|
68
|
+
size = File.open(source_file_name) do |source_stream|
|
69
69
|
IOStreams.writer(target_file_name) do |target_stream|
|
70
70
|
IOStreams.copy(source_stream, target_stream)
|
71
71
|
end
|
@@ -76,7 +76,7 @@ class DeprecatedTest < Minitest::Test
|
|
76
76
|
assert_equal actual.size, size
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
79
|
+
it "files" do
|
80
80
|
size = IOStreams.copy(source_file_name, target_file_name)
|
81
81
|
actual = File.read(target_file_name)
|
82
82
|
|
@@ -85,18 +85,18 @@ class DeprecatedTest < Minitest::Test
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
describe
|
89
|
-
it
|
88
|
+
describe ".each_line" do
|
89
|
+
it "returns a line at a time" do
|
90
90
|
lines = []
|
91
91
|
count = IOStreams.each_line(source_file_name) { |line| lines << line }
|
92
92
|
assert_equal data.lines.map(&:strip), lines
|
93
93
|
assert_equal data.lines.count, count
|
94
94
|
end
|
95
95
|
|
96
|
-
it
|
96
|
+
it "strips non-printable characters" do
|
97
97
|
input = StringIO.new(bad_data)
|
98
98
|
lines = []
|
99
|
-
count = IOStreams.each_line(input, encoding:
|
99
|
+
count = IOStreams.each_line(input, encoding: "UTF-8", encode_cleaner: :printable, encode_replace: "") do |line|
|
100
100
|
lines << line
|
101
101
|
end
|
102
102
|
assert_equal stripped_data.lines.map(&:strip), lines
|
@@ -104,18 +104,14 @@ class DeprecatedTest < Minitest::Test
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
describe
|
108
|
-
it
|
109
|
-
result = IOStreams.reader(multiple_zip_file_name, streams: {zip: {entry_file_name:
|
110
|
-
io.read
|
111
|
-
end
|
107
|
+
describe ".reader" do
|
108
|
+
it "reads a zip file" do
|
109
|
+
result = IOStreams.reader(multiple_zip_file_name, streams: {zip: {entry_file_name: "test.json"}}, &:read)
|
112
110
|
assert_equal contents_test_json, result
|
113
111
|
end
|
114
112
|
|
115
|
-
it
|
116
|
-
result = IOStreams.reader(zip_gz_file_name)
|
117
|
-
io.read
|
118
|
-
end
|
113
|
+
it "reads a zip file from within a gz file" do
|
114
|
+
result = IOStreams.reader(zip_gz_file_name, &:read)
|
119
115
|
assert_equal contents_test_txt, result
|
120
116
|
end
|
121
117
|
end
|