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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 410a7bdcec2ee16f130bbb7010bfd2258975253c1bd380c1832f034ae18b2979
4
- data.tar.gz: 6f8e7bd896166b10a77477a95a0eae88b742a117525d48c10fd23952fa37faa7
3
+ metadata.gz: 06e71b70e09ed1f57a4d776795d48fc973d32888a078c9e42319fc3eaee56db0
4
+ data.tar.gz: 7d956af5453840aee0a8c8cca5e7e4e44c465e1dcb13030daa37f2abc8f5cc78
5
5
  SHA512:
6
- metadata.gz: 85a53eae7c90affdfcd577836d83533d75eff5eb8e880352c6890d4805c219b91e99fc1d936cc72829dbe93d6b8ea55585cc0a2b3a1c8886ab2b261e7c078cb7
7
- data.tar.gz: 5bd17a2bae394ca10a84f659fe1e0aac8315ab393cfe11e4606b3b0e4ca901d121c2b0aeae91cf6dac0f1939fec039fac21036a5c8382abe382f5d705bf519ad
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 [Integer] the number of characters read into the internal buffer
150
- # Returns 0 on EOF
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 = nil
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
@@ -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
@@ -68,6 +68,8 @@ module IOStreams
68
68
  end
69
69
 
70
70
  def each
71
+ return to_enum(__method__) unless block_given?
72
+
71
73
  @line_reader.each do |line|
72
74
  if @tabular.header?
73
75
  @tabular.parse_header(line)
@@ -40,6 +40,8 @@ module IOStreams
40
40
  end
41
41
 
42
42
  def each
43
+ return to_enum(__method__) unless block_given?
44
+
43
45
  @line_reader.each do |line|
44
46
  if @tabular.header?
45
47
  columns = @tabular.parse_header(line)
@@ -1,3 +1,3 @@
1
1
  module IOStreams
2
- VERSION = "1.9.0".freeze
2
+ VERSION = "1.10.0".freeze
3
3
  end
@@ -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|
@@ -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
@@ -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
@@ -10,7 +10,7 @@ class RowReaderTest < Minitest::Test
10
10
  CSV.read(file_name)
11
11
  end
12
12
 
13
- describe ".open" do
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.9.0
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-17 00:00:00.000000000 Z
11
+ date: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: