filter_io 0.2.5 → 0.2.6
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/filter_io.rb +3 -2
- data/lib/filter_io/version.rb +1 -1
- data/spec/filter_io_spec.rb +33 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a31b33c49d022a4d843c22358d84cc2617c2c9b
|
4
|
+
data.tar.gz: 6a5fc3060b2192db6dfe7a01cdfa0fc470df52a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 027ae9db72c8aabb4922f035975091ee8ea1859d1db24f66774e078dcd4d6d987c0b942a0d4049e0c23c8cf99402399ddf1d502947cde6c63546ba36d74478f7
|
7
|
+
data.tar.gz: 2c50d946d7b86b86ffbc6483e0561d93d868cfc9c63433e284d37ffa746fa2aeb75670528198a239da8dbf124d00af1c8bc290974e6cd83763ea8d74cd584033
|
data/lib/filter_io.rb
CHANGED
@@ -103,7 +103,8 @@ class FilterIO
|
|
103
103
|
return '' if length == 0
|
104
104
|
|
105
105
|
# fill the buffer up to the fill level (or whole input if length is nil)
|
106
|
-
while !source_eof? && (length.nil? || length > @buffer.bytesize)
|
106
|
+
while (!source_eof? || !@did_first_read) && (length.nil? || length > @buffer.bytesize)
|
107
|
+
@did_first_read = true
|
107
108
|
buffer_data @options[:block_size] || length
|
108
109
|
end
|
109
110
|
|
@@ -310,7 +311,7 @@ class FilterIO
|
|
310
311
|
@source_pos += data.bytesize
|
311
312
|
data.force_encoding(external_encoding)
|
312
313
|
else
|
313
|
-
|
314
|
+
data = ""
|
314
315
|
end
|
315
316
|
|
316
317
|
initial_data_size = data.bytesize
|
data/lib/filter_io/version.rb
CHANGED
data/spec/filter_io_spec.rb
CHANGED
@@ -45,9 +45,9 @@ describe FilterIO do
|
|
45
45
|
|
46
46
|
it 'works with an empty source' do
|
47
47
|
io = FilterIO.new(StringIO.new(''))
|
48
|
-
expect(io.bof?).to
|
48
|
+
expect(io.bof?).to eq true
|
49
49
|
io = FilterIO.new(StringIO.new(''))
|
50
|
-
expect(io.eof?).to
|
50
|
+
expect(io.eof?).to eq true
|
51
51
|
io = FilterIO.new(StringIO.new(''))
|
52
52
|
expect {
|
53
53
|
io.readchar
|
@@ -56,18 +56,18 @@ describe FilterIO do
|
|
56
56
|
|
57
57
|
it 'supports `eof?`' do
|
58
58
|
io = FilterIO.new(StringIO.new('x'))
|
59
|
-
expect(io.eof?).to
|
59
|
+
expect(io.eof?).to eq false
|
60
60
|
expect(io.readchar.chr).to eq 'x'
|
61
|
-
expect(io.eof?).to
|
61
|
+
expect(io.eof?).to eq true
|
62
62
|
expect(io.read).to eq ''
|
63
63
|
expect(io.read(8)).to eq nil
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'supports `bof?`' do
|
67
67
|
io = FilterIO.new(StringIO.new('x'))
|
68
|
-
expect(io.bof?).to
|
68
|
+
expect(io.bof?).to eq true
|
69
69
|
expect(io.readchar.chr).to eq 'x'
|
70
|
-
expect(io.bof?).to
|
70
|
+
expect(io.bof?).to eq false
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'can `readchar` with unicode characters' do
|
@@ -286,22 +286,22 @@ describe FilterIO do
|
|
286
286
|
end
|
287
287
|
expect(io.read).to eq io_reference.read
|
288
288
|
expect(io.read(4)).to eq io_reference.read(4)
|
289
|
-
expect(io_reference.eof?).to
|
290
|
-
expect(io.eof?).to
|
289
|
+
expect(io_reference.eof?).to eq true
|
290
|
+
expect(io.eof?).to eq true
|
291
291
|
end
|
292
292
|
|
293
293
|
it 'returns empty from read(0) before EOF' do
|
294
294
|
io = FilterIO.new(StringIO.new('foo'))
|
295
295
|
expect(io.read(0)).to eq ''
|
296
296
|
expect(io.pos).to eq 0
|
297
|
-
expect(io.eof?).to
|
297
|
+
expect(io.eof?).to eq false
|
298
298
|
end
|
299
299
|
|
300
300
|
it 'returns empty from read(0) at EOF' do
|
301
301
|
io = FilterIO.new(StringIO.new(''))
|
302
302
|
expect(io.read(0)).to eq ''
|
303
303
|
expect(io.pos).to eq 0
|
304
|
-
expect(io.eof?).to
|
304
|
+
expect(io.eof?).to eq true
|
305
305
|
end
|
306
306
|
|
307
307
|
it 'errors if attempting to read negative' do
|
@@ -917,4 +917,27 @@ describe FilterIO do
|
|
917
917
|
|
918
918
|
expect(rows).to eq [%w[FOO BAR], %w[BAZ]]
|
919
919
|
end
|
920
|
+
|
921
|
+
it 'calls block when stream empty' do
|
922
|
+
io = FilterIO.new StringIO.new('') do |data, state|
|
923
|
+
out = state.bof? ? 'start' : ''
|
924
|
+
out << data.upcase
|
925
|
+
out << 'end' if state.eof?
|
926
|
+
end
|
927
|
+
expect(io.read).to eq 'startend'
|
928
|
+
|
929
|
+
# multiple reads from empty stream should only trigger block once
|
930
|
+
expect(io.read).to eq ""
|
931
|
+
end
|
932
|
+
|
933
|
+
it 'no longer calls block once the stream is eof' do
|
934
|
+
io = FilterIO.new StringIO.new('foo') do |data, state|
|
935
|
+
out = state.bof? ? 'start' : ''
|
936
|
+
out << data.upcase
|
937
|
+
out << 'end' if state.eof?
|
938
|
+
end
|
939
|
+
expect(io.read).to eq 'startFOOend'
|
940
|
+
expect(io.read).to eq ""
|
941
|
+
end
|
942
|
+
|
920
943
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filter_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Weathered
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|