iostreams 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/io_streams/line/reader.rb +9 -3
- data/lib/io_streams/paths/file.rb +5 -0
- data/lib/io_streams/paths/s3.rb +5 -0
- data/lib/io_streams/paths/sftp.rb +5 -0
- data/lib/io_streams/record/reader.rb +2 -0
- data/lib/io_streams/row/reader.rb +2 -0
- data/lib/io_streams/version.rb +1 -1
- data/test/line_reader_test.rb +7 -0
- data/test/paths/file_test.rb +21 -1
- data/test/record_reader_test.rb +7 -0
- data/test/row_reader_test.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06e71b70e09ed1f57a4d776795d48fc973d32888a078c9e42319fc3eaee56db0
|
4
|
+
data.tar.gz: 7d956af5453840aee0a8c8cca5e7e4e44c465e1dcb13030daa37f2abc8f5cc78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ed848fcc886ed53d36504097036605d13735887a880ed65620460f55d78fc26771a18b1ab32e1685f765cf25097fa42f7e59ba233099aeb15a93b0005936bb5
|
7
|
+
data.tar.gz: 6301601fa85f7f9198e0c61fabdd0a9206c4dfb2b239c0e8155a01a47973f6cb545272a870a593d67437ef25476901aed9c1101c24cacef5ab22e4f794936398
|
@@ -75,6 +75,8 @@ module IOStreams
|
|
75
75
|
# Note:
|
76
76
|
# * The line delimiter is _not_ returned.
|
77
77
|
def each
|
78
|
+
return to_enum(__method__) unless block_given?
|
79
|
+
|
78
80
|
line_count = 0
|
79
81
|
until eof?
|
80
82
|
line = readline
|
@@ -146,8 +148,8 @@ module IOStreams
|
|
146
148
|
data
|
147
149
|
end
|
148
150
|
|
149
|
-
# Returns
|
150
|
-
# Returns
|
151
|
+
# Returns whether more data is available to read
|
152
|
+
# Returns false on EOF
|
151
153
|
def read_block
|
152
154
|
return false if @eof
|
153
155
|
|
@@ -157,7 +159,8 @@ module IOStreams
|
|
157
159
|
@input_stream.read(@buffer_size, @read_cache_buffer)
|
158
160
|
rescue ArgumentError
|
159
161
|
# Handle arity of -1 when just 0..1
|
160
|
-
@read_cache_buffer
|
162
|
+
@read_cache_buffer = nil
|
163
|
+
@use_read_cache_buffer = false
|
161
164
|
@input_stream.read(@buffer_size)
|
162
165
|
end
|
163
166
|
else
|
@@ -170,6 +173,9 @@ module IOStreams
|
|
170
173
|
return false
|
171
174
|
end
|
172
175
|
|
176
|
+
# When less data is returned than was requested, it means the end of the file with partial data.
|
177
|
+
@eof = true if block.size < @buffer_size
|
178
|
+
|
173
179
|
if @buffer
|
174
180
|
@buffer << block
|
175
181
|
else
|
@@ -89,6 +89,11 @@ module IOStreams
|
|
89
89
|
# "**.rb" "lib/song.rb" true
|
90
90
|
# "*" "dave/.profile" true
|
91
91
|
def each_child(pattern = "*", case_sensitive: false, directories: false, hidden: false)
|
92
|
+
unless block_given?
|
93
|
+
return to_enum(__method__, pattern,
|
94
|
+
case_sensitive: case_sensitive, directories: directories, hidden: hidden)
|
95
|
+
end
|
96
|
+
|
92
97
|
flags = 0
|
93
98
|
flags |= ::File::FNM_CASEFOLD unless case_sensitive
|
94
99
|
flags |= ::File::FNM_DOTMATCH if hidden
|
data/lib/io_streams/paths/s3.rb
CHANGED
@@ -284,6 +284,11 @@ module IOStreams
|
|
284
284
|
# Notes:
|
285
285
|
# - Currently all S3 lookups are recursive as of the pattern regardless of whether the pattern includes `**`.
|
286
286
|
def each_child(pattern = "*", case_sensitive: false, directories: false, hidden: false)
|
287
|
+
unless block_given?
|
288
|
+
return to_enum(__method__, pattern,
|
289
|
+
case_sensitive: case_sensitive, directories: directories, hidden: hidden)
|
290
|
+
end
|
291
|
+
|
287
292
|
matcher = Matcher.new(self, pattern, case_sensitive: case_sensitive, hidden: hidden)
|
288
293
|
|
289
294
|
# When the pattern includes an exact file name without any pattern characters
|
@@ -142,6 +142,11 @@ module IOStreams
|
|
142
142
|
# sftp://sftp.example.org/a/b/c/test.txt {:type=>1, :size=>37, :owner=>"test_owner", :group=>"test_group",
|
143
143
|
# :permissions=>420, :atime=>1572378136, :mtime=>1572378136, :link_count=>1, :extended=>{}}
|
144
144
|
def each_child(pattern = "*", case_sensitive: true, directories: false, hidden: false)
|
145
|
+
unless block_given?
|
146
|
+
return to_enum(__method__, pattern,
|
147
|
+
case_sensitive: case_sensitive, directories: directories, hidden: hidden)
|
148
|
+
end
|
149
|
+
|
145
150
|
Utils.load_soft_dependency("net-sftp", "SFTP glob capability", "net/sftp") unless defined?(Net::SFTP)
|
146
151
|
|
147
152
|
flags = ::File::FNM_EXTGLOB
|
data/lib/io_streams/version.rb
CHANGED
data/test/line_reader_test.rb
CHANGED
@@ -98,6 +98,13 @@ class LineReaderTest < Minitest::Test
|
|
98
98
|
assert_equal data.size, count
|
99
99
|
end
|
100
100
|
|
101
|
+
it "with no block returns enumerator" do
|
102
|
+
lines = IOStreams::Line::Reader.file(file_name) do |io|
|
103
|
+
io.each.first(100)
|
104
|
+
end
|
105
|
+
assert_equal data, lines
|
106
|
+
end
|
107
|
+
|
101
108
|
it "each_line stream" do
|
102
109
|
lines = []
|
103
110
|
count = File.open(file_name) do |file|
|
data/test/paths/file_test.rb
CHANGED
@@ -5,7 +5,7 @@ module Paths
|
|
5
5
|
describe IOStreams::Paths::File do
|
6
6
|
let(:root) { IOStreams::Paths::File.new("/tmp/iostreams").delete_all }
|
7
7
|
let(:directory) { root.join("/some_test_dir") }
|
8
|
-
let(:data) { "Hello World" }
|
8
|
+
let(:data) { "Hello World\nHow are you doing?\nOn this fine day" }
|
9
9
|
let(:file_path) do
|
10
10
|
path = root.join("some_test_dir/test_file.txt")
|
11
11
|
path.writer { |io| io << data }
|
@@ -17,6 +17,20 @@ module Paths
|
|
17
17
|
path
|
18
18
|
end
|
19
19
|
|
20
|
+
describe "#each" do
|
21
|
+
it "reads lines" do
|
22
|
+
records = []
|
23
|
+
count = file_path.each { |line| records << line }
|
24
|
+
assert_equal count, data.lines.size
|
25
|
+
assert_equal data.lines.collect(&:strip), records
|
26
|
+
end
|
27
|
+
|
28
|
+
it "reads lines without block" do
|
29
|
+
records = file_path.each.first(100)
|
30
|
+
assert_equal data.lines.collect(&:strip), records
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
20
34
|
describe "#each_child" do
|
21
35
|
it "iterates an empty path" do
|
22
36
|
none = nil
|
@@ -48,6 +62,12 @@ module Paths
|
|
48
62
|
actual = root.children("**/Test*.TXT", case_sensitive: true).collect(&:to_s)
|
49
63
|
refute_equal expected, actual.sort
|
50
64
|
end
|
65
|
+
|
66
|
+
it "with no block returns enumerator" do
|
67
|
+
expected = [file_path.to_s, file_path2.to_s]
|
68
|
+
actual = root.each_child("**/*").first(100).collect(&:to_s)
|
69
|
+
assert_equal expected.sort, actual.sort
|
70
|
+
end
|
51
71
|
end
|
52
72
|
|
53
73
|
describe "#mkpath" do
|
data/test/record_reader_test.rb
CHANGED
@@ -46,6 +46,13 @@ class RecordReaderTest < Minitest::Test
|
|
46
46
|
end
|
47
47
|
assert_equal expected, rows
|
48
48
|
end
|
49
|
+
|
50
|
+
it "with no block returns enumerator" do
|
51
|
+
records = IOStreams::Record::Reader.file(file_name, cleanse_header: false) do |io|
|
52
|
+
io.each.first(100)
|
53
|
+
end
|
54
|
+
assert_equal expected, records
|
55
|
+
end
|
49
56
|
end
|
50
57
|
|
51
58
|
describe "#collect" do
|
data/test/row_reader_test.rb
CHANGED
@@ -10,7 +10,7 @@ class RowReaderTest < Minitest::Test
|
|
10
10
|
CSV.read(file_name)
|
11
11
|
end
|
12
12
|
|
13
|
-
describe "
|
13
|
+
describe "#each" do
|
14
14
|
it "file" do
|
15
15
|
rows = []
|
16
16
|
count = IOStreams::Row::Reader.file(file_name) do |io|
|
@@ -20,6 +20,13 @@ class RowReaderTest < Minitest::Test
|
|
20
20
|
assert_equal expected.size, count
|
21
21
|
end
|
22
22
|
|
23
|
+
it "with no block returns enumerator" do
|
24
|
+
rows = IOStreams::Row::Reader.file(file_name) do |io|
|
25
|
+
io.each.first(100)
|
26
|
+
end
|
27
|
+
assert_equal expected, rows
|
28
|
+
end
|
29
|
+
|
23
30
|
it "stream" do
|
24
31
|
rows = []
|
25
32
|
count = IOStreams::Line::Reader.file(file_name) do |file|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iostreams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|