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/test/utils_test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class UtilsTest < Minitest::Test
|
4
|
+
describe IOStreams::Utils do
|
5
|
+
describe '.temp_file_name' do
|
6
|
+
it 'returns value from block' do
|
7
|
+
result = IOStreams::Utils.temp_file_name('base', '.ext') { |_name| 257 }
|
8
|
+
assert_equal 257, result
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'supplies new temp file_name' do
|
12
|
+
file_name = nil
|
13
|
+
file_name2 = nil
|
14
|
+
IOStreams::Utils.temp_file_name('base', '.ext') { |name| file_name = name }
|
15
|
+
IOStreams::Utils.temp_file_name('base', '.ext') { |name| file_name2 = name }
|
16
|
+
refute_equal file_name, file_name2
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/xlsx_reader_test.rb
CHANGED
@@ -14,10 +14,10 @@ class XlsxReaderTest
|
|
14
14
|
]
|
15
15
|
end
|
16
16
|
|
17
|
-
describe '.
|
17
|
+
describe '.file' do
|
18
18
|
describe 'with a file path' do
|
19
19
|
it 'returns the contents of the file' do
|
20
|
-
csv
|
20
|
+
csv = IOStreams::Xlsx::Reader.file(file_name, &:read)
|
21
21
|
assert_equal xlsx_contents, CSV.parse(csv)
|
22
22
|
end
|
23
23
|
end
|
@@ -26,7 +26,7 @@ class XlsxReaderTest
|
|
26
26
|
it 'returns the contents of the file' do
|
27
27
|
csv = ''
|
28
28
|
File.open(file_name, 'rb') do |file|
|
29
|
-
csv = IOStreams::Xlsx::Reader.
|
29
|
+
csv = IOStreams::Xlsx::Reader.stream(file, &:read)
|
30
30
|
end
|
31
31
|
|
32
32
|
assert_equal xlsx_contents, CSV.parse(csv)
|
data/test/zip_reader_test.rb
CHANGED
@@ -24,36 +24,36 @@ class ZipReaderTest < Minitest::Test
|
|
24
24
|
Zip::File.open(file_name) { |zip_file| zip_file.first.get_input_stream.read }
|
25
25
|
end
|
26
26
|
|
27
|
-
describe '.
|
27
|
+
describe '.file' do
|
28
28
|
it 'reads the first file' do
|
29
|
-
result = IOStreams::Zip::Reader.
|
29
|
+
result = IOStreams::Zip::Reader.file(file_name) do |io|
|
30
30
|
io.read
|
31
31
|
end
|
32
32
|
assert_equal decompressed, result
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'reads entry within zip file' do
|
36
|
-
result = IOStreams::Zip::Reader.
|
36
|
+
result = IOStreams::Zip::Reader.file(multiple_zip_file_name, entry_file_name: 'text.txt') do |io|
|
37
37
|
io.read
|
38
38
|
end
|
39
39
|
assert_equal contents_test_txt, result
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'reads another entry within zip file' do
|
43
|
-
result = IOStreams::Zip::Reader.
|
43
|
+
result = IOStreams::Zip::Reader.file(multiple_zip_file_name, entry_file_name: 'test.json') do |io|
|
44
44
|
io.read
|
45
45
|
end
|
46
46
|
assert_equal contents_test_json, result
|
47
47
|
end
|
48
48
|
|
49
|
-
it 'reads from a stream' do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
49
|
+
# it 'reads from a stream' do
|
50
|
+
# result = MinimalFileReader.open(file_name) do |file|
|
51
|
+
# IOStreams::Zip::Reader.stream(file) do |io|
|
52
|
+
# io.read
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
# assert_equal decompressed, result
|
56
|
+
# end
|
57
57
|
end
|
58
58
|
|
59
59
|
end
|
data/test/zip_writer_test.rb
CHANGED
@@ -12,19 +12,19 @@ class ZipWriterTest < Minitest::Test
|
|
12
12
|
end
|
13
13
|
|
14
14
|
let :decompressed do
|
15
|
-
File.read(File.join(File.dirname(__FILE__), 'files', 'text.txt'))
|
15
|
+
::File.read(File.join(File.dirname(__FILE__), 'files', 'text.txt'))
|
16
16
|
end
|
17
17
|
|
18
18
|
after do
|
19
19
|
temp_file.delete
|
20
20
|
end
|
21
21
|
|
22
|
-
describe '.
|
22
|
+
describe '.file' do
|
23
23
|
it 'file' do
|
24
|
-
IOStreams::Zip::Writer.
|
24
|
+
IOStreams::Zip::Writer.file(file_name, entry_file_name: 'text.txt') do |io|
|
25
25
|
io.write(decompressed)
|
26
26
|
end
|
27
|
-
result = Zip::File.open(file_name) do |zip_file|
|
27
|
+
result = ::Zip::File.open(file_name) do |zip_file|
|
28
28
|
zip_file.first.get_input_stream.read
|
29
29
|
end
|
30
30
|
assert_equal decompressed, result
|
@@ -32,7 +32,7 @@ class ZipWriterTest < Minitest::Test
|
|
32
32
|
|
33
33
|
it 'stream' do
|
34
34
|
io_string = StringIO.new(''.b)
|
35
|
-
IOStreams::Zip::Writer.
|
35
|
+
IOStreams::Zip::Writer.stream(io_string) do |io|
|
36
36
|
io.write(decompressed)
|
37
37
|
end
|
38
38
|
io = StringIO.new(io_string.string)
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iostreams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: concurrent-ruby
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2019-10-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description:
|
28
14
|
email:
|
29
15
|
- reidmo@gmail.com
|
@@ -34,34 +20,33 @@ files:
|
|
34
20
|
- LICENSE
|
35
21
|
- README.md
|
36
22
|
- Rakefile
|
37
|
-
- lib/io_streams/base_path.rb
|
38
23
|
- lib/io_streams/bzip2/reader.rb
|
39
24
|
- lib/io_streams/bzip2/writer.rb
|
25
|
+
- lib/io_streams/deprecated.rb
|
40
26
|
- lib/io_streams/encode/reader.rb
|
41
27
|
- lib/io_streams/encode/writer.rb
|
42
28
|
- lib/io_streams/errors.rb
|
43
|
-
- lib/io_streams/file/path.rb
|
44
|
-
- lib/io_streams/file/reader.rb
|
45
|
-
- lib/io_streams/file/writer.rb
|
46
29
|
- lib/io_streams/gzip/reader.rb
|
47
30
|
- lib/io_streams/gzip/writer.rb
|
48
|
-
- lib/io_streams/http/reader.rb
|
49
31
|
- lib/io_streams/io_streams.rb
|
50
32
|
- lib/io_streams/line/reader.rb
|
51
33
|
- lib/io_streams/line/writer.rb
|
34
|
+
- lib/io_streams/path.rb
|
35
|
+
- lib/io_streams/paths/file.rb
|
36
|
+
- lib/io_streams/paths/http.rb
|
37
|
+
- lib/io_streams/paths/matcher.rb
|
38
|
+
- lib/io_streams/paths/s3.rb
|
39
|
+
- lib/io_streams/paths/sftp.rb
|
52
40
|
- lib/io_streams/pgp.rb
|
53
41
|
- lib/io_streams/pgp/reader.rb
|
54
42
|
- lib/io_streams/pgp/writer.rb
|
43
|
+
- lib/io_streams/reader.rb
|
55
44
|
- lib/io_streams/record/reader.rb
|
56
45
|
- lib/io_streams/record/writer.rb
|
57
46
|
- lib/io_streams/row/reader.rb
|
58
47
|
- lib/io_streams/row/writer.rb
|
59
|
-
- lib/io_streams/
|
60
|
-
- lib/io_streams/
|
61
|
-
- lib/io_streams/s3/reader.rb
|
62
|
-
- lib/io_streams/s3/writer.rb
|
63
|
-
- lib/io_streams/sftp/reader.rb
|
64
|
-
- lib/io_streams/sftp/writer.rb
|
48
|
+
- lib/io_streams/stream.rb
|
49
|
+
- lib/io_streams/streams.rb
|
65
50
|
- lib/io_streams/symmetric_encryption/reader.rb
|
66
51
|
- lib/io_streams/symmetric_encryption/writer.rb
|
67
52
|
- lib/io_streams/tabular.rb
|
@@ -76,18 +61,16 @@ files:
|
|
76
61
|
- lib/io_streams/tabular/utility/csv_row.rb
|
77
62
|
- lib/io_streams/utils.rb
|
78
63
|
- lib/io_streams/version.rb
|
64
|
+
- lib/io_streams/writer.rb
|
79
65
|
- lib/io_streams/xlsx/reader.rb
|
80
66
|
- lib/io_streams/zip/reader.rb
|
81
67
|
- lib/io_streams/zip/writer.rb
|
82
68
|
- lib/iostreams.rb
|
83
|
-
- test/base_path_test.rb
|
84
69
|
- test/bzip2_reader_test.rb
|
85
70
|
- test/bzip2_writer_test.rb
|
71
|
+
- test/deprecated_test.rb
|
86
72
|
- test/encode_reader_test.rb
|
87
73
|
- test/encode_writer_test.rb
|
88
|
-
- test/file_path_test.rb
|
89
|
-
- test/file_reader_test.rb
|
90
|
-
- test/file_writer_test.rb
|
91
74
|
- test/files/embedded_lines_test.csv
|
92
75
|
- test/files/multiple_files.zip
|
93
76
|
- test/files/spreadsheet.xlsx
|
@@ -102,12 +85,15 @@ files:
|
|
102
85
|
- test/files/unclosed_quote_test.csv
|
103
86
|
- test/gzip_reader_test.rb
|
104
87
|
- test/gzip_writer_test.rb
|
105
|
-
- test/http_reader_test.rb
|
106
88
|
- test/io_streams_test.rb
|
107
89
|
- test/line_reader_test.rb
|
108
90
|
- test/line_writer_test.rb
|
109
91
|
- test/minimal_file_reader.rb
|
110
92
|
- test/path_test.rb
|
93
|
+
- test/paths/file_test.rb
|
94
|
+
- test/paths/http_test.rb
|
95
|
+
- test/paths/matcher_test.rb
|
96
|
+
- test/paths/s3_test.rb
|
111
97
|
- test/pgp_reader_test.rb
|
112
98
|
- test/pgp_test.rb
|
113
99
|
- test/pgp_writer_test.rb
|
@@ -115,10 +101,11 @@ files:
|
|
115
101
|
- test/record_writer_test.rb
|
116
102
|
- test/row_reader_test.rb
|
117
103
|
- test/row_writer_test.rb
|
118
|
-
- test/
|
119
|
-
- test/
|
104
|
+
- test/stream_test.rb
|
105
|
+
- test/streams_test.rb
|
120
106
|
- test/tabular_test.rb
|
121
107
|
- test/test_helper.rb
|
108
|
+
- test/utils_test.rb
|
122
109
|
- test/xlsx_reader_test.rb
|
123
110
|
- test/zip_reader_test.rb
|
124
111
|
- test/zip_writer_test.rb
|
@@ -134,12 +121,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
121
|
requirements:
|
135
122
|
- - ">="
|
136
123
|
- !ruby/object:Gem::Version
|
137
|
-
version: '2.
|
124
|
+
version: '2.3'
|
138
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
126
|
requirements:
|
140
|
-
- - "
|
127
|
+
- - ">"
|
141
128
|
- !ruby/object:Gem::Version
|
142
|
-
version:
|
129
|
+
version: 1.3.1
|
143
130
|
requirements: []
|
144
131
|
rubygems_version: 3.0.6
|
145
132
|
signing_key:
|
@@ -147,7 +134,7 @@ specification_version: 4
|
|
147
134
|
summary: Input and Output streaming for Ruby.
|
148
135
|
test_files:
|
149
136
|
- test/pgp_reader_test.rb
|
150
|
-
- test/
|
137
|
+
- test/deprecated_test.rb
|
151
138
|
- test/line_reader_test.rb
|
152
139
|
- test/xlsx_reader_test.rb
|
153
140
|
- test/minimal_file_reader.rb
|
@@ -156,10 +143,13 @@ test_files:
|
|
156
143
|
- test/bzip2_writer_test.rb
|
157
144
|
- test/encode_writer_test.rb
|
158
145
|
- test/gzip_writer_test.rb
|
159
|
-
- test/
|
146
|
+
- test/streams_test.rb
|
147
|
+
- test/stream_test.rb
|
148
|
+
- test/paths/matcher_test.rb
|
149
|
+
- test/paths/s3_test.rb
|
150
|
+
- test/paths/file_test.rb
|
151
|
+
- test/paths/http_test.rb
|
160
152
|
- test/record_reader_test.rb
|
161
|
-
- test/s3_writer_test.rb
|
162
|
-
- test/http_reader_test.rb
|
163
153
|
- test/pgp_writer_test.rb
|
164
154
|
- test/line_writer_test.rb
|
165
155
|
- test/row_reader_test.rb
|
@@ -180,11 +170,9 @@ test_files:
|
|
180
170
|
- test/gzip_reader_test.rb
|
181
171
|
- test/encode_reader_test.rb
|
182
172
|
- test/test_helper.rb
|
183
|
-
- test/
|
173
|
+
- test/utils_test.rb
|
184
174
|
- test/tabular_test.rb
|
185
175
|
- test/path_test.rb
|
186
176
|
- test/pgp_test.rb
|
187
177
|
- test/io_streams_test.rb
|
188
178
|
- test/record_writer_test.rb
|
189
|
-
- test/s3_reader_test.rb
|
190
|
-
- test/file_path_test.rb
|
data/lib/io_streams/base_path.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module IOStreams
|
3
|
-
class BasePath
|
4
|
-
attr_reader :path
|
5
|
-
|
6
|
-
def initialize(path)
|
7
|
-
@path = path.frozen? ? path : path.dup.freeze
|
8
|
-
end
|
9
|
-
|
10
|
-
# If elements already contains the current path then it is used as is without
|
11
|
-
# adding the current path for a second time
|
12
|
-
def join(*elements)
|
13
|
-
return self if elements.empty?
|
14
|
-
|
15
|
-
relative = ::File.join(*elements)
|
16
|
-
if relative.start_with?(path)
|
17
|
-
self.class.new(relative)
|
18
|
-
else
|
19
|
-
self.class.new(::File.join(path, relative))
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_s
|
24
|
-
path
|
25
|
-
end
|
26
|
-
|
27
|
-
# Removes the last element of the path, the file name, before creating the entire path.
|
28
|
-
# Returns self
|
29
|
-
def mkpath
|
30
|
-
raise NotImplementedError
|
31
|
-
end
|
32
|
-
|
33
|
-
# Assumes the current path does not include a file name, and creates all elements in the path.
|
34
|
-
# Returns self
|
35
|
-
#
|
36
|
-
# Note: Do not call this method if the path contains a file name, see `#mkpath`
|
37
|
-
def mkdir
|
38
|
-
raise NotImplementedError
|
39
|
-
end
|
40
|
-
|
41
|
-
# Returns [true|false] whether the file exists
|
42
|
-
def exist?
|
43
|
-
raise NotImplementedError
|
44
|
-
end
|
45
|
-
|
46
|
-
# Returns [Integer] size of the file
|
47
|
-
def size
|
48
|
-
raise NotImplementedError
|
49
|
-
end
|
50
|
-
|
51
|
-
# Delete the file.
|
52
|
-
# Returns self
|
53
|
-
#
|
54
|
-
# Notes:
|
55
|
-
# * No error is raised if the file is not present.
|
56
|
-
# * Only the file is removed, not any of the parent paths.
|
57
|
-
def delete
|
58
|
-
raise NotImplementedError
|
59
|
-
end
|
60
|
-
|
61
|
-
# Return a reader for this path
|
62
|
-
def reader(**args, &block)
|
63
|
-
IOStreams.reader(path, **args, &block)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Return a writer for this path
|
67
|
-
def writer(**args, &block)
|
68
|
-
IOStreams.writer(path, **args, &block)
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
data/lib/io_streams/file/path.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module IOStreams
|
5
|
-
module File
|
6
|
-
class Path < IOStreams::BasePath
|
7
|
-
# Yields the path to a temporary file_name.
|
8
|
-
#
|
9
|
-
# File is deleted upon completion if present.
|
10
|
-
def self.temp_file_name(basename, extension = '')
|
11
|
-
result = nil
|
12
|
-
::Dir::Tmpname.create([basename, extension]) do |tmpname|
|
13
|
-
begin
|
14
|
-
result = yield(tmpname)
|
15
|
-
ensure
|
16
|
-
::File.unlink(tmpname) if ::File.exist?(tmpname)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
result
|
20
|
-
end
|
21
|
-
|
22
|
-
# Used by writers that can write directly to file to create the target path
|
23
|
-
def self.mkpath(path)
|
24
|
-
dir = ::File.dirname(path)
|
25
|
-
FileUtils.mkdir_p(dir) unless ::File.exist?(dir)
|
26
|
-
end
|
27
|
-
|
28
|
-
def mkpath
|
29
|
-
self.class.mkpath(path)
|
30
|
-
self
|
31
|
-
end
|
32
|
-
|
33
|
-
def mkdir
|
34
|
-
FileUtils.mkdir_p(path) unless ::File.exist?(path)
|
35
|
-
self
|
36
|
-
end
|
37
|
-
|
38
|
-
def exist?
|
39
|
-
::File.exist?(path)
|
40
|
-
end
|
41
|
-
|
42
|
-
def size
|
43
|
-
::File.size(path)
|
44
|
-
end
|
45
|
-
|
46
|
-
def delete(recursively: false)
|
47
|
-
return self unless ::File.exist?(path)
|
48
|
-
|
49
|
-
if ::File.directory?(path)
|
50
|
-
recursively ? FileUtils.remove_dir(path) : Dir.delete(path)
|
51
|
-
else
|
52
|
-
::File.unlink(path)
|
53
|
-
end
|
54
|
-
self
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module IOStreams
|
2
|
-
module File
|
3
|
-
class Reader
|
4
|
-
# Read from a named file
|
5
|
-
def self.open(file_name, **args, &block)
|
6
|
-
raise(ArgumentError, 'File name must be a string') unless file_name.is_a?(String)
|
7
|
-
|
8
|
-
::File.open(file_name, 'rb', &block)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|