iostreams 0.20.3 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/lib/io_streams/bzip2/reader.rb +9 -21
  3. data/lib/io_streams/bzip2/writer.rb +9 -21
  4. data/lib/io_streams/deprecated.rb +217 -0
  5. data/lib/io_streams/encode/reader.rb +12 -16
  6. data/lib/io_streams/encode/writer.rb +9 -13
  7. data/lib/io_streams/errors.rb +6 -6
  8. data/lib/io_streams/gzip/reader.rb +7 -14
  9. data/lib/io_streams/gzip/writer.rb +7 -15
  10. data/lib/io_streams/io_streams.rb +182 -524
  11. data/lib/io_streams/line/reader.rb +9 -9
  12. data/lib/io_streams/line/writer.rb +10 -11
  13. data/lib/io_streams/path.rb +190 -0
  14. data/lib/io_streams/paths/file.rb +176 -0
  15. data/lib/io_streams/paths/http.rb +92 -0
  16. data/lib/io_streams/paths/matcher.rb +61 -0
  17. data/lib/io_streams/paths/s3.rb +269 -0
  18. data/lib/io_streams/paths/sftp.rb +99 -0
  19. data/lib/io_streams/pgp.rb +47 -19
  20. data/lib/io_streams/pgp/reader.rb +20 -28
  21. data/lib/io_streams/pgp/writer.rb +24 -46
  22. data/lib/io_streams/reader.rb +28 -0
  23. data/lib/io_streams/record/reader.rb +20 -16
  24. data/lib/io_streams/record/writer.rb +28 -28
  25. data/lib/io_streams/row/reader.rb +22 -26
  26. data/lib/io_streams/row/writer.rb +29 -28
  27. data/lib/io_streams/stream.rb +400 -0
  28. data/lib/io_streams/streams.rb +125 -0
  29. data/lib/io_streams/symmetric_encryption/reader.rb +5 -13
  30. data/lib/io_streams/symmetric_encryption/writer.rb +16 -15
  31. data/lib/io_streams/tabular/header.rb +9 -3
  32. data/lib/io_streams/tabular/parser/array.rb +8 -3
  33. data/lib/io_streams/tabular/parser/csv.rb +6 -2
  34. data/lib/io_streams/tabular/parser/hash.rb +4 -1
  35. data/lib/io_streams/tabular/parser/json.rb +3 -1
  36. data/lib/io_streams/tabular/parser/psv.rb +3 -1
  37. data/lib/io_streams/tabular/utility/csv_row.rb +9 -8
  38. data/lib/io_streams/utils.rb +22 -0
  39. data/lib/io_streams/version.rb +1 -1
  40. data/lib/io_streams/writer.rb +28 -0
  41. data/lib/io_streams/xlsx/reader.rb +7 -19
  42. data/lib/io_streams/zip/reader.rb +7 -26
  43. data/lib/io_streams/zip/writer.rb +21 -38
  44. data/lib/iostreams.rb +15 -15
  45. data/test/bzip2_reader_test.rb +3 -3
  46. data/test/bzip2_writer_test.rb +3 -3
  47. data/test/deprecated_test.rb +123 -0
  48. data/test/encode_reader_test.rb +3 -3
  49. data/test/encode_writer_test.rb +6 -6
  50. data/test/gzip_reader_test.rb +2 -2
  51. data/test/gzip_writer_test.rb +3 -3
  52. data/test/io_streams_test.rb +43 -136
  53. data/test/line_reader_test.rb +20 -20
  54. data/test/line_writer_test.rb +3 -3
  55. data/test/path_test.rb +30 -28
  56. data/test/paths/file_test.rb +206 -0
  57. data/test/paths/http_test.rb +34 -0
  58. data/test/paths/matcher_test.rb +111 -0
  59. data/test/paths/s3_test.rb +207 -0
  60. data/test/pgp_reader_test.rb +8 -8
  61. data/test/pgp_writer_test.rb +13 -13
  62. data/test/record_reader_test.rb +5 -5
  63. data/test/record_writer_test.rb +4 -4
  64. data/test/row_reader_test.rb +5 -5
  65. data/test/row_writer_test.rb +6 -6
  66. data/test/stream_test.rb +116 -0
  67. data/test/streams_test.rb +255 -0
  68. data/test/utils_test.rb +20 -0
  69. data/test/xlsx_reader_test.rb +3 -3
  70. data/test/zip_reader_test.rb +12 -12
  71. data/test/zip_writer_test.rb +5 -5
  72. metadata +33 -45
  73. data/lib/io_streams/base_path.rb +0 -72
  74. data/lib/io_streams/file/path.rb +0 -58
  75. data/lib/io_streams/file/reader.rb +0 -12
  76. data/lib/io_streams/file/writer.rb +0 -22
  77. data/lib/io_streams/http/reader.rb +0 -71
  78. data/lib/io_streams/s3.rb +0 -26
  79. data/lib/io_streams/s3/path.rb +0 -40
  80. data/lib/io_streams/s3/reader.rb +0 -28
  81. data/lib/io_streams/s3/writer.rb +0 -85
  82. data/lib/io_streams/sftp/reader.rb +0 -67
  83. data/lib/io_streams/sftp/writer.rb +0 -68
  84. data/test/base_path_test.rb +0 -35
  85. data/test/file_path_test.rb +0 -97
  86. data/test/file_reader_test.rb +0 -33
  87. data/test/file_writer_test.rb +0 -50
  88. data/test/http_reader_test.rb +0 -38
  89. data/test/s3_reader_test.rb +0 -41
  90. data/test/s3_writer_test.rb +0 -41
@@ -1,12 +1,23 @@
1
1
  require 'io_streams/version'
2
- #@formatter:off
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 :S3, 'io_streams/s3'
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'
@@ -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 '.open' do
13
+ describe '.file' do
14
14
  it 'file' do
15
- result = IOStreams::Bzip2::Reader.open(file_name) do |io|
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.open(file) do |io|
23
+ IOStreams::Bzip2::Reader.stream(file) do |io|
24
24
  io.read
25
25
  end
26
26
  end
@@ -18,9 +18,9 @@ class Bzip2WriterTest < Minitest::Test
18
18
  temp_file.delete
19
19
  end
20
20
 
21
- describe '.open' do
21
+ describe '.file' do
22
22
  it 'file' do
23
- IOStreams::Bzip2::Writer.open(file_name) do |io|
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.open(io_string) do |io|
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
@@ -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.open(input, encoding: 'UTF-8') do |io|
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.open(input, encoding: 'UTF-8', encode_replace: '') do |io|
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.open(input, encoding: 'UTF-8', encode_cleaner: :printable, encode_replace: '') do |io|
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
@@ -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.open(file_name, encoding: 'ASCII-8BIT') do |io|
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.open(io, encoding: 'ASCII-8BIT') do |encoded|
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.open(io, encoding: 'UTF-8') do |encoded|
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.open(io, encoding: 'UTF-8', encode_replace: '?') do |encoded|
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.open(io, encoding: 'UTF-8', encode_replace: '?', encode_cleaner: :printable) do |encoded|
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.open(io_string, encoding: 'ASCII-8BIT') do |io|
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
@@ -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.open(file_name) do |io|
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.open(file) do |io|
23
+ IOStreams::Gzip::Reader.stream(file) do |io|
24
24
  io.read
25
25
  end
26
26
  end
@@ -18,9 +18,9 @@ class GzipWriterTest < Minitest::Test
18
18
  temp_file.delete
19
19
  end
20
20
 
21
- describe '.open' do
21
+ describe '.file' do
22
22
  it 'file' do
23
- IOStreams::Gzip::Writer.open(file_name) do |io|
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.open(io_string) do |io|
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)
@@ -1,158 +1,65 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- class IOStreamsTest < Minitest::Test
4
- describe IOStreams do
5
- let :source_file_name do
6
- File.join(__dir__, 'files', 'text.txt')
7
- end
8
-
9
- let :data do
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
- assert_equal actual, data
63
- assert_equal actual.size, size
64
- end
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
- it 'files' do
79
- size = IOStreams.copy(source_file_name, target_file_name)
80
- actual = File.read(target_file_name)
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
- it 'is case-insensitive' do
104
- streams = IOStreams.streams_for_file_name('a.GzIp')
105
- assert_equal [:gzip], streams
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
- it 'multiple streams are case-insensitive' do
109
- streams = IOStreams.streams_for_file_name('a.XlsX.Gz')
110
- assert_equal [:xlsx, :gz], streams
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
- describe '.scheme_for_file_name' do
115
- it 'default' do
116
- assert_nil IOStreams.scheme_for_file_name('a.xyz')
117
- end
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
- it 's3' do
120
- assert_equal :s3, IOStreams.scheme_for_file_name('s3://a.xyz')
121
- end
122
- end
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
- describe '.each_line' do
125
- it 'returns a line at a time' do
126
- lines = []
127
- count = IOStreams.each_line(source_file_name) { |line| lines << line }
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
- it 'strips non-printable characters' do
133
- input = StringIO.new(bad_data)
134
- lines = []
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
- describe '.reader' do
144
- it 'reads a zip file' do
145
- result = IOStreams.reader(multiple_zip_file_name, streams: {zip: {entry_file_name: 'test.json'}}) do |io|
146
- io.read
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
- it 'reads a zip file from within a gz file' do
152
- result = IOStreams.reader(zip_gz_file_name) do |io|
153
- io.read
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