iostreams 0.20.3 → 1.0.0.beta
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/lib/io_streams/bzip2/reader.rb +9 -21
- data/lib/io_streams/bzip2/writer.rb +9 -21
- data/lib/io_streams/deprecated.rb +217 -0
- data/lib/io_streams/encode/reader.rb +12 -16
- data/lib/io_streams/encode/writer.rb +9 -13
- data/lib/io_streams/errors.rb +6 -6
- data/lib/io_streams/gzip/reader.rb +7 -14
- data/lib/io_streams/gzip/writer.rb +7 -15
- data/lib/io_streams/io_streams.rb +182 -524
- data/lib/io_streams/line/reader.rb +9 -9
- data/lib/io_streams/line/writer.rb +10 -11
- data/lib/io_streams/path.rb +190 -0
- data/lib/io_streams/paths/file.rb +176 -0
- data/lib/io_streams/paths/http.rb +92 -0
- data/lib/io_streams/paths/matcher.rb +61 -0
- data/lib/io_streams/paths/s3.rb +269 -0
- data/lib/io_streams/paths/sftp.rb +99 -0
- data/lib/io_streams/pgp.rb +47 -19
- data/lib/io_streams/pgp/reader.rb +20 -28
- data/lib/io_streams/pgp/writer.rb +24 -46
- data/lib/io_streams/reader.rb +28 -0
- data/lib/io_streams/record/reader.rb +20 -16
- data/lib/io_streams/record/writer.rb +28 -28
- data/lib/io_streams/row/reader.rb +22 -26
- data/lib/io_streams/row/writer.rb +29 -28
- data/lib/io_streams/stream.rb +400 -0
- data/lib/io_streams/streams.rb +125 -0
- data/lib/io_streams/symmetric_encryption/reader.rb +5 -13
- data/lib/io_streams/symmetric_encryption/writer.rb +16 -15
- data/lib/io_streams/tabular/header.rb +9 -3
- data/lib/io_streams/tabular/parser/array.rb +8 -3
- data/lib/io_streams/tabular/parser/csv.rb +6 -2
- data/lib/io_streams/tabular/parser/hash.rb +4 -1
- data/lib/io_streams/tabular/parser/json.rb +3 -1
- data/lib/io_streams/tabular/parser/psv.rb +3 -1
- data/lib/io_streams/tabular/utility/csv_row.rb +9 -8
- data/lib/io_streams/utils.rb +22 -0
- data/lib/io_streams/version.rb +1 -1
- data/lib/io_streams/writer.rb +28 -0
- data/lib/io_streams/xlsx/reader.rb +7 -19
- data/lib/io_streams/zip/reader.rb +7 -26
- data/lib/io_streams/zip/writer.rb +21 -38
- data/lib/iostreams.rb +15 -15
- data/test/bzip2_reader_test.rb +3 -3
- data/test/bzip2_writer_test.rb +3 -3
- data/test/deprecated_test.rb +123 -0
- data/test/encode_reader_test.rb +3 -3
- data/test/encode_writer_test.rb +6 -6
- data/test/gzip_reader_test.rb +2 -2
- data/test/gzip_writer_test.rb +3 -3
- data/test/io_streams_test.rb +43 -136
- data/test/line_reader_test.rb +20 -20
- data/test/line_writer_test.rb +3 -3
- data/test/path_test.rb +30 -28
- data/test/paths/file_test.rb +206 -0
- data/test/paths/http_test.rb +34 -0
- data/test/paths/matcher_test.rb +111 -0
- data/test/paths/s3_test.rb +207 -0
- data/test/pgp_reader_test.rb +8 -8
- data/test/pgp_writer_test.rb +13 -13
- data/test/record_reader_test.rb +5 -5
- data/test/record_writer_test.rb +4 -4
- data/test/row_reader_test.rb +5 -5
- data/test/row_writer_test.rb +6 -6
- data/test/stream_test.rb +116 -0
- data/test/streams_test.rb +255 -0
- data/test/utils_test.rb +20 -0
- data/test/xlsx_reader_test.rb +3 -3
- data/test/zip_reader_test.rb +12 -12
- data/test/zip_writer_test.rb +5 -5
- metadata +33 -45
- data/lib/io_streams/base_path.rb +0 -72
- data/lib/io_streams/file/path.rb +0 -58
- data/lib/io_streams/file/reader.rb +0 -12
- data/lib/io_streams/file/writer.rb +0 -22
- data/lib/io_streams/http/reader.rb +0 -71
- data/lib/io_streams/s3.rb +0 -26
- data/lib/io_streams/s3/path.rb +0 -40
- data/lib/io_streams/s3/reader.rb +0 -28
- data/lib/io_streams/s3/writer.rb +0 -85
- data/lib/io_streams/sftp/reader.rb +0 -67
- data/lib/io_streams/sftp/writer.rb +0 -68
- data/test/base_path_test.rb +0 -35
- data/test/file_path_test.rb +0 -97
- data/test/file_reader_test.rb +0 -33
- data/test/file_writer_test.rb +0 -50
- data/test/http_reader_test.rb +0 -38
- data/test/s3_reader_test.rb +0 -41
- data/test/s3_writer_test.rb +0 -41
data/lib/iostreams.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
require 'io_streams/version'
|
2
|
-
|
2
|
+
# @formatter:off
|
3
3
|
module IOStreams
|
4
|
-
autoload :BasePath, 'io_streams/base_path'
|
5
4
|
autoload :Errors, 'io_streams/errors'
|
5
|
+
autoload :Path, 'io_streams/path'
|
6
6
|
autoload :Pgp, 'io_streams/pgp'
|
7
|
-
autoload :
|
7
|
+
autoload :Reader, 'io_streams/reader'
|
8
|
+
autoload :Stream, 'io_streams/stream'
|
9
|
+
autoload :Streams, 'io_streams/streams'
|
8
10
|
autoload :Tabular, 'io_streams/tabular'
|
9
11
|
autoload :Utils, 'io_streams/utils'
|
12
|
+
autoload :Writer, 'io_streams/writer'
|
13
|
+
|
14
|
+
module Paths
|
15
|
+
autoload :File, 'io_streams/paths/file'
|
16
|
+
autoload :HTTP, 'io_streams/paths/http'
|
17
|
+
autoload :Matcher, 'io_streams/paths/matcher'
|
18
|
+
autoload :S3, 'io_streams/paths/s3'
|
19
|
+
autoload :SFTP, 'io_streams/paths/sftp'
|
20
|
+
end
|
10
21
|
|
11
22
|
module Bzip2
|
12
23
|
autoload :Reader, 'io_streams/bzip2/reader'
|
@@ -16,18 +27,10 @@ module IOStreams
|
|
16
27
|
autoload :Reader, 'io_streams/encode/reader'
|
17
28
|
autoload :Writer, 'io_streams/encode/writer'
|
18
29
|
end
|
19
|
-
module File
|
20
|
-
autoload :Path, 'io_streams/file/path'
|
21
|
-
autoload :Reader, 'io_streams/file/reader'
|
22
|
-
autoload :Writer, 'io_streams/file/writer'
|
23
|
-
end
|
24
30
|
module Gzip
|
25
31
|
autoload :Reader, 'io_streams/gzip/reader'
|
26
32
|
autoload :Writer, 'io_streams/gzip/writer'
|
27
33
|
end
|
28
|
-
module HTTP
|
29
|
-
autoload :Reader, 'io_streams/http/reader'
|
30
|
-
end
|
31
34
|
module Line
|
32
35
|
autoload :Reader, 'io_streams/line/reader'
|
33
36
|
autoload :Writer, 'io_streams/line/writer'
|
@@ -40,10 +43,6 @@ module IOStreams
|
|
40
43
|
autoload :Reader, 'io_streams/row/reader'
|
41
44
|
autoload :Writer, 'io_streams/row/writer'
|
42
45
|
end
|
43
|
-
module SFTP
|
44
|
-
autoload :Reader, 'io_streams/sftp/reader'
|
45
|
-
autoload :Writer, 'io_streams/sftp/writer'
|
46
|
-
end
|
47
46
|
module SymmetricEncryption
|
48
47
|
autoload :Reader, 'io_streams/symmetric_encryption/reader'
|
49
48
|
autoload :Writer, 'io_streams/symmetric_encryption/writer'
|
@@ -56,4 +55,5 @@ module IOStreams
|
|
56
55
|
autoload :Writer, 'io_streams/zip/writer'
|
57
56
|
end
|
58
57
|
end
|
58
|
+
require 'io_streams/deprecated'
|
59
59
|
require 'io_streams/io_streams'
|
data/test/bzip2_reader_test.rb
CHANGED
@@ -10,9 +10,9 @@ class Bzip2ReaderTest < Minitest::Test
|
|
10
10
|
File.read(File.join(File.dirname(__FILE__), 'files', 'text.txt'))
|
11
11
|
end
|
12
12
|
|
13
|
-
describe '.
|
13
|
+
describe '.file' do
|
14
14
|
it 'file' do
|
15
|
-
result = IOStreams::Bzip2::Reader.
|
15
|
+
result = IOStreams::Bzip2::Reader.file(file_name) do |io|
|
16
16
|
io.read
|
17
17
|
end
|
18
18
|
assert_equal decompressed, result
|
@@ -20,7 +20,7 @@ class Bzip2ReaderTest < Minitest::Test
|
|
20
20
|
|
21
21
|
it 'stream' do
|
22
22
|
result = File.open(file_name) do |file|
|
23
|
-
IOStreams::Bzip2::Reader.
|
23
|
+
IOStreams::Bzip2::Reader.stream(file) do |io|
|
24
24
|
io.read
|
25
25
|
end
|
26
26
|
end
|
data/test/bzip2_writer_test.rb
CHANGED
@@ -18,9 +18,9 @@ class Bzip2WriterTest < Minitest::Test
|
|
18
18
|
temp_file.delete
|
19
19
|
end
|
20
20
|
|
21
|
-
describe '.
|
21
|
+
describe '.file' do
|
22
22
|
it 'file' do
|
23
|
-
IOStreams::Bzip2::Writer.
|
23
|
+
IOStreams::Bzip2::Writer.file(file_name) do |io|
|
24
24
|
io.write(decompressed)
|
25
25
|
end
|
26
26
|
|
@@ -34,7 +34,7 @@ class Bzip2WriterTest < Minitest::Test
|
|
34
34
|
|
35
35
|
it 'stream' do
|
36
36
|
io_string = StringIO.new(''.b)
|
37
|
-
IOStreams::Bzip2::Writer.
|
37
|
+
IOStreams::Bzip2::Writer.stream(io_string) do |io|
|
38
38
|
io.write(decompressed)
|
39
39
|
end
|
40
40
|
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
# Test deprecated api
|
4
|
+
class DeprecatedTest < Minitest::Test
|
5
|
+
describe IOStreams do
|
6
|
+
let :source_file_name do
|
7
|
+
File.join(__dir__, 'files', 'text.txt')
|
8
|
+
end
|
9
|
+
|
10
|
+
let :data do
|
11
|
+
File.read(source_file_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
let :temp_file do
|
15
|
+
Tempfile.new('iostreams')
|
16
|
+
end
|
17
|
+
|
18
|
+
let :target_file_name do
|
19
|
+
temp_file.path
|
20
|
+
end
|
21
|
+
|
22
|
+
let :bad_data do
|
23
|
+
[
|
24
|
+
"New M\xE9xico,NE".b,
|
25
|
+
'good line',
|
26
|
+
"New M\xE9xico,\x07SF".b
|
27
|
+
].join("\n").encode('BINARY')
|
28
|
+
end
|
29
|
+
|
30
|
+
let :stripped_data do
|
31
|
+
bad_data.gsub("\xE9".b, '').gsub("\x07", '')
|
32
|
+
end
|
33
|
+
|
34
|
+
let :multiple_zip_file_name do
|
35
|
+
File.join(File.dirname(__FILE__), 'files', 'multiple_files.zip')
|
36
|
+
end
|
37
|
+
|
38
|
+
let :zip_gz_file_name do
|
39
|
+
File.join(File.dirname(__FILE__), 'files', 'text.zip.gz')
|
40
|
+
end
|
41
|
+
|
42
|
+
let :contents_test_txt do
|
43
|
+
File.read(File.join(File.dirname(__FILE__), 'files', 'text.txt'))
|
44
|
+
end
|
45
|
+
|
46
|
+
let :contents_test_json do
|
47
|
+
File.read(File.join(File.dirname(__FILE__), 'files', 'test.json'))
|
48
|
+
end
|
49
|
+
|
50
|
+
after do
|
51
|
+
temp_file.delete
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '.copy' do
|
55
|
+
it 'streams' do
|
56
|
+
size = IOStreams.reader(source_file_name) do |source_stream|
|
57
|
+
IOStreams.writer(target_file_name) do |target_stream|
|
58
|
+
IOStreams.copy(source_stream, target_stream)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
actual = File.read(target_file_name)
|
62
|
+
|
63
|
+
assert_equal actual, data
|
64
|
+
assert_equal actual.size, size
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'IO stream' do
|
68
|
+
size = File.open(source_file_name) do |source_stream|
|
69
|
+
IOStreams.writer(target_file_name) do |target_stream|
|
70
|
+
IOStreams.copy(source_stream, target_stream)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
actual = File.read(target_file_name)
|
74
|
+
|
75
|
+
assert_equal actual, data
|
76
|
+
assert_equal actual.size, size
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'files' do
|
80
|
+
size = IOStreams.copy(source_file_name, target_file_name)
|
81
|
+
actual = File.read(target_file_name)
|
82
|
+
|
83
|
+
assert_equal actual, data
|
84
|
+
assert_equal actual.size, size
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '.each_line' do
|
89
|
+
it 'returns a line at a time' do
|
90
|
+
lines = []
|
91
|
+
count = IOStreams.each_line(source_file_name) { |line| lines << line }
|
92
|
+
assert_equal data.lines.map(&:strip), lines
|
93
|
+
assert_equal data.lines.count, count
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'strips non-printable characters' do
|
97
|
+
input = StringIO.new(bad_data)
|
98
|
+
lines = []
|
99
|
+
count = IOStreams.each_line(input, encoding: 'UTF-8', encode_cleaner: :printable, encode_replace: '') do |line|
|
100
|
+
lines << line
|
101
|
+
end
|
102
|
+
assert_equal stripped_data.lines.map(&:strip), lines
|
103
|
+
assert_equal stripped_data.lines.count, count
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
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'}}) do |io|
|
110
|
+
io.read
|
111
|
+
end
|
112
|
+
assert_equal contents_test_json, result
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'reads a zip file from within a gz file' do
|
116
|
+
result = IOStreams.reader(zip_gz_file_name) do |io|
|
117
|
+
io.read
|
118
|
+
end
|
119
|
+
assert_equal contents_test_txt, result
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/test/encode_reader_test.rb
CHANGED
@@ -22,7 +22,7 @@ class EncodeReaderTest < Minitest::Test
|
|
22
22
|
describe 'replacement' do
|
23
23
|
it 'does not strip invalid characters' do
|
24
24
|
input = StringIO.new(bad_data)
|
25
|
-
IOStreams::Encode::Reader.
|
25
|
+
IOStreams::Encode::Reader.stream(input, encoding: 'UTF-8') do |io|
|
26
26
|
assert_raises ::Encoding::UndefinedConversionError do
|
27
27
|
io.read.encoding
|
28
28
|
end
|
@@ -32,7 +32,7 @@ class EncodeReaderTest < Minitest::Test
|
|
32
32
|
it 'strips invalid characters' do
|
33
33
|
input = StringIO.new(bad_data)
|
34
34
|
data =
|
35
|
-
IOStreams::Encode::Reader.
|
35
|
+
IOStreams::Encode::Reader.stream(input, encoding: 'UTF-8', replace: '') do |io|
|
36
36
|
io.read
|
37
37
|
end
|
38
38
|
assert_equal cleansed_data, data
|
@@ -43,7 +43,7 @@ class EncodeReaderTest < Minitest::Test
|
|
43
43
|
it 'strips non-printable characters' do
|
44
44
|
input = StringIO.new(bad_data)
|
45
45
|
data =
|
46
|
-
IOStreams::Encode::Reader.
|
46
|
+
IOStreams::Encode::Reader.stream(input, encoding: 'UTF-8', cleaner: :printable, replace: '') do |io|
|
47
47
|
io.read
|
48
48
|
end
|
49
49
|
assert_equal stripped_data, data
|
data/test/encode_writer_test.rb
CHANGED
@@ -22,7 +22,7 @@ class EncodeWriterTest < Minitest::Test
|
|
22
22
|
it 'file' do
|
23
23
|
temp_file = Tempfile.new('rocket_job')
|
24
24
|
file_name = temp_file.to_path
|
25
|
-
IOStreams::Encode::Writer.
|
25
|
+
IOStreams::Encode::Writer.file(file_name, encoding: 'ASCII-8BIT') do |io|
|
26
26
|
io << bad_data
|
27
27
|
end
|
28
28
|
result = File.read(file_name, mode: 'rb')
|
@@ -31,7 +31,7 @@ class EncodeWriterTest < Minitest::Test
|
|
31
31
|
|
32
32
|
it 'stream' do
|
33
33
|
io = StringIO.new(''.b)
|
34
|
-
IOStreams::Encode::Writer.
|
34
|
+
IOStreams::Encode::Writer.stream(io, encoding: 'ASCII-8BIT') do |encoded|
|
35
35
|
encoded << bad_data
|
36
36
|
end
|
37
37
|
assert_equal 'ASCII-8BIT', io.string.encoding.to_s
|
@@ -41,7 +41,7 @@ class EncodeWriterTest < Minitest::Test
|
|
41
41
|
it 'stream as utf-8' do
|
42
42
|
io = StringIO.new('')
|
43
43
|
assert_raises Encoding::UndefinedConversionError do
|
44
|
-
IOStreams::Encode::Writer.
|
44
|
+
IOStreams::Encode::Writer.stream(io, encoding: 'UTF-8') do |encoded|
|
45
45
|
encoded << bad_data
|
46
46
|
end
|
47
47
|
end
|
@@ -49,7 +49,7 @@ class EncodeWriterTest < Minitest::Test
|
|
49
49
|
|
50
50
|
it 'stream as utf-8 with replacement' do
|
51
51
|
io = StringIO.new('')
|
52
|
-
IOStreams::Encode::Writer.
|
52
|
+
IOStreams::Encode::Writer.stream(io, encoding: 'UTF-8', replace: '?') do |encoded|
|
53
53
|
encoded << bad_data
|
54
54
|
end
|
55
55
|
assert_equal 'UTF-8', io.string.encoding.to_s
|
@@ -58,7 +58,7 @@ class EncodeWriterTest < Minitest::Test
|
|
58
58
|
|
59
59
|
it 'stream as utf-8 with replacement and printable cleansing' do
|
60
60
|
io = StringIO.new('')
|
61
|
-
IOStreams::Encode::Writer.
|
61
|
+
IOStreams::Encode::Writer.stream(io, encoding: 'UTF-8', replace: '?', cleaner: :printable) do |encoded|
|
62
62
|
encoded << bad_data
|
63
63
|
end
|
64
64
|
assert_equal 'UTF-8', io.string.encoding.to_s
|
@@ -70,7 +70,7 @@ class EncodeWriterTest < Minitest::Test
|
|
70
70
|
it 'returns byte count' do
|
71
71
|
io_string = StringIO.new(''.b)
|
72
72
|
count = 0
|
73
|
-
IOStreams::Encode::Writer.
|
73
|
+
IOStreams::Encode::Writer.stream(io_string, encoding: 'ASCII-8BIT') do |io|
|
74
74
|
count += io.write(bad_data)
|
75
75
|
end
|
76
76
|
assert_equal bad_data, io_string.string
|
data/test/gzip_reader_test.rb
CHANGED
@@ -12,7 +12,7 @@ class GzipReaderTest < Minitest::Test
|
|
12
12
|
|
13
13
|
describe '.open' do
|
14
14
|
it 'file' do
|
15
|
-
result = IOStreams::Gzip::Reader.
|
15
|
+
result = IOStreams::Gzip::Reader.file(file_name) do |io|
|
16
16
|
io.read
|
17
17
|
end
|
18
18
|
assert_equal decompressed, result
|
@@ -20,7 +20,7 @@ class GzipReaderTest < Minitest::Test
|
|
20
20
|
|
21
21
|
it 'stream' do
|
22
22
|
result = File.open(file_name) do |file|
|
23
|
-
IOStreams::Gzip::Reader.
|
23
|
+
IOStreams::Gzip::Reader.stream(file) do |io|
|
24
24
|
io.read
|
25
25
|
end
|
26
26
|
end
|
data/test/gzip_writer_test.rb
CHANGED
@@ -18,9 +18,9 @@ class GzipWriterTest < Minitest::Test
|
|
18
18
|
temp_file.delete
|
19
19
|
end
|
20
20
|
|
21
|
-
describe '.
|
21
|
+
describe '.file' do
|
22
22
|
it 'file' do
|
23
|
-
IOStreams::Gzip::Writer.
|
23
|
+
IOStreams::Gzip::Writer.file(file_name) do |io|
|
24
24
|
io.write(decompressed)
|
25
25
|
end
|
26
26
|
result = Zlib::GzipReader.open(file_name) { |gz| gz.read }
|
@@ -30,7 +30,7 @@ class GzipWriterTest < Minitest::Test
|
|
30
30
|
|
31
31
|
it 'stream' do
|
32
32
|
io_string = StringIO.new(''.b)
|
33
|
-
IOStreams::Gzip::Writer.
|
33
|
+
IOStreams::Gzip::Writer.stream(io_string) do |io|
|
34
34
|
io.write(decompressed)
|
35
35
|
end
|
36
36
|
io = StringIO.new(io_string.string)
|
data/test/io_streams_test.rb
CHANGED
@@ -1,158 +1,65 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
File.read(source_file_name)
|
11
|
-
end
|
12
|
-
|
13
|
-
let :temp_file do
|
14
|
-
Tempfile.new('iostreams')
|
15
|
-
end
|
16
|
-
|
17
|
-
let :target_file_name do
|
18
|
-
temp_file.path
|
19
|
-
end
|
20
|
-
|
21
|
-
let :bad_data do
|
22
|
-
[
|
23
|
-
"New M\xE9xico,NE".b,
|
24
|
-
'good line',
|
25
|
-
"New M\xE9xico,\x07SF".b
|
26
|
-
].join("\n").encode('BINARY')
|
27
|
-
end
|
28
|
-
|
29
|
-
let :stripped_data do
|
30
|
-
bad_data.gsub("\xE9".b, '').gsub("\x07", '')
|
31
|
-
end
|
32
|
-
|
33
|
-
let :multiple_zip_file_name do
|
34
|
-
File.join(File.dirname(__FILE__), 'files', 'multiple_files.zip')
|
35
|
-
end
|
36
|
-
|
37
|
-
let :zip_gz_file_name do
|
38
|
-
File.join(File.dirname(__FILE__), 'files', 'text.zip.gz')
|
39
|
-
end
|
40
|
-
|
41
|
-
let :contents_test_txt do
|
42
|
-
File.read(File.join(File.dirname(__FILE__), 'files', 'text.txt'))
|
43
|
-
end
|
44
|
-
|
45
|
-
let :contents_test_json do
|
46
|
-
File.read(File.join(File.dirname(__FILE__), 'files', 'test.json'))
|
47
|
-
end
|
48
|
-
|
49
|
-
after do
|
50
|
-
temp_file.delete
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '.copy' do
|
54
|
-
it 'streams' do
|
55
|
-
size = IOStreams.reader(source_file_name) do |source_stream|
|
56
|
-
IOStreams.writer(target_file_name) do |target_stream|
|
57
|
-
IOStreams.copy(source_stream, target_stream)
|
58
|
-
end
|
3
|
+
module IOStreams
|
4
|
+
class PathTest < Minitest::Test
|
5
|
+
describe IOStreams do
|
6
|
+
describe '.root' do
|
7
|
+
it 'return default path' do
|
8
|
+
path = ::File.expand_path(::File.join(__dir__, '../tmp/default'))
|
9
|
+
assert_equal path, IOStreams.root.to_s
|
59
10
|
end
|
60
|
-
actual = File.read(target_file_name)
|
61
11
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
it 'IO stream' do
|
67
|
-
size = File.open(source_file_name) do |source_stream|
|
68
|
-
IOStreams.writer(target_file_name) do |target_stream|
|
69
|
-
IOStreams.copy(source_stream, target_stream)
|
70
|
-
end
|
12
|
+
it 'return downloads path' do
|
13
|
+
path = ::File.expand_path(::File.join(__dir__, '../tmp/downloads'))
|
14
|
+
assert_equal path, IOStreams.root(:downloads).to_s
|
71
15
|
end
|
72
|
-
actual = File.read(target_file_name)
|
73
|
-
|
74
|
-
assert_equal actual, data
|
75
|
-
assert_equal actual.size, size
|
76
16
|
end
|
77
17
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
assert_equal actual, data
|
83
|
-
assert_equal actual.size, size
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe '.streams_for_file_name' do
|
88
|
-
it 'file only' do
|
89
|
-
streams = IOStreams.streams_for_file_name('a.xyz')
|
90
|
-
assert_equal [], streams
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'single stream' do
|
94
|
-
streams = IOStreams.streams_for_file_name('a.gz')
|
95
|
-
assert_equal [:gz], streams
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'multiple streams' do
|
99
|
-
streams = IOStreams.streams_for_file_name('a.xlsx.gz')
|
100
|
-
assert_equal [:xlsx, :gz], streams
|
101
|
-
end
|
18
|
+
describe '.join' do
|
19
|
+
it 'returns path' do
|
20
|
+
assert_equal IOStreams.root.to_s, IOStreams.join.to_s
|
21
|
+
end
|
102
22
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
23
|
+
it 'adds path to root' do
|
24
|
+
assert_equal ::File.join(IOStreams.root.to_s, 'test'), IOStreams.join('test').to_s
|
25
|
+
end
|
107
26
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
27
|
+
it 'adds paths to root' do
|
28
|
+
assert_equal ::File.join(IOStreams.root.to_s, 'test', 'second', 'third'), IOStreams.join('test', 'second', 'third').to_s
|
29
|
+
end
|
113
30
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
31
|
+
it 'returns path and filename' do
|
32
|
+
path = ::File.join(IOStreams.root.to_s, 'file.xls')
|
33
|
+
assert_equal path, IOStreams.join('file.xls').to_s
|
34
|
+
end
|
118
35
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
36
|
+
it 'adds path to root and filename' do
|
37
|
+
path = ::File.join(IOStreams.root.to_s, 'test', 'file.xls')
|
38
|
+
assert_equal path, IOStreams.join('test', 'file.xls').to_s
|
39
|
+
end
|
123
40
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
assert_equal data.lines.map(&:strip), lines
|
129
|
-
assert_equal data.lines.count, count
|
130
|
-
end
|
41
|
+
it 'adds paths to root' do
|
42
|
+
path = ::File.join(IOStreams.root.to_s, 'test', 'second', 'third', 'file.xls')
|
43
|
+
assert_equal path, IOStreams.join('test', 'second', 'third', 'file.xls').to_s
|
44
|
+
end
|
131
45
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
count = IOStreams.each_line(input, encoding: 'UTF-8', encode_cleaner: :printable, encode_replace: '') do |line|
|
136
|
-
lines << line
|
46
|
+
it 'return path as sent in when full path' do
|
47
|
+
path = ::File.join(IOStreams.root.to_s, 'file.xls')
|
48
|
+
assert_equal path, IOStreams.join(path).to_s
|
137
49
|
end
|
138
|
-
assert_equal stripped_data.lines.map(&:strip), lines
|
139
|
-
assert_equal stripped_data.lines.count, count
|
140
50
|
end
|
141
|
-
end
|
142
51
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
52
|
+
describe '.path' do
|
53
|
+
it 'default' do
|
54
|
+
path = IOStreams.path('a.xyz')
|
55
|
+
assert path.is_a?(IOStreams::Paths::File), path
|
147
56
|
end
|
148
|
-
assert_equal contents_test_json, result
|
149
|
-
end
|
150
57
|
|
151
|
-
|
152
|
-
|
153
|
-
|
58
|
+
it 's3' do
|
59
|
+
skip 'TODO'
|
60
|
+
IOStreams.path('s3://a.xyz')
|
61
|
+
assert_equal :s3, path
|
154
62
|
end
|
155
|
-
assert_equal contents_test_txt, result
|
156
63
|
end
|
157
64
|
end
|
158
65
|
end
|