filter_io 0.2.5 → 0.2.6

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
  SHA1:
3
- metadata.gz: cb0cdede3401dcdd670bf293213c4836b1abd8b5
4
- data.tar.gz: 6c9e0d608afff977d2acf2688e5a16c2357664f6
3
+ metadata.gz: 6a31b33c49d022a4d843c22358d84cc2617c2c9b
4
+ data.tar.gz: 6a5fc3060b2192db6dfe7a01cdfa0fc470df52a0
5
5
  SHA512:
6
- metadata.gz: 2d63ff2053219b2abca0dcaecb876550fbfcaf3b09c657c0acb758d5eaed34f601ef059d647c10caa11b3de2549fd20eeeb846e2f9b8c0f375332da6f12d2d84
7
- data.tar.gz: e80aeeb45c363e80a62a8c831a5fdfb8b94473ae9a3b98fe6ace97abaea623cff3380ec54c7333738450581020c788de8de8a6ffb90a46e848fda679da8e00a0
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
- return
314
+ data = ""
314
315
  end
315
316
 
316
317
  initial_data_size = data.bytesize
@@ -1,3 +1,3 @@
1
1
  class FilterIO
2
- VERSION = '0.2.5'
2
+ VERSION = '0.2.6'
3
3
  end
@@ -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 be_true
48
+ expect(io.bof?).to eq true
49
49
  io = FilterIO.new(StringIO.new(''))
50
- expect(io.eof?).to be_true
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 be_false
59
+ expect(io.eof?).to eq false
60
60
  expect(io.readchar.chr).to eq 'x'
61
- expect(io.eof?).to be_true
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 be_true
68
+ expect(io.bof?).to eq true
69
69
  expect(io.readchar.chr).to eq 'x'
70
- expect(io.bof?).to be_false
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 be_true
290
- expect(io.eof?).to be_true
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 be_false
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 be_true
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.5
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-08-12 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler