Class: Linedump::StreamWrapper
- Inherits:
-
Object
- Object
- Linedump::StreamWrapper
- Defined in:
- lib/linedump/stream_wrapper.rb
Constant Summary collapse
- MAX_LENGTH =
2048
Instance Attribute Summary collapse
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #eof? ⇒ Boolean
-
#initialize(_stream, _block) ⇒ StreamWrapper
constructor
A new instance of StreamWrapper.
- #process_lines ⇒ Object
Constructor Details
#initialize(_stream, _block) ⇒ StreamWrapper
Returns a new instance of StreamWrapper.
9 10 11 12 13 14 |
# File 'lib/linedump/stream_wrapper.rb', line 9 def initialize(_stream, _block) @stream = _stream @block = _block @buffer = [] @eof = false end |
Instance Attribute Details
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
7 8 9 |
# File 'lib/linedump/stream_wrapper.rb', line 7 def stream @stream end |
Instance Method Details
#eof? ⇒ Boolean
16 17 18 |
# File 'lib/linedump/stream_wrapper.rb', line 16 def eof? @eof end |
#process_lines ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/linedump/stream_wrapper.rb', line 20 def process_lines begin loop do chunk = @stream.read_nonblock(MAX_LENGTH) process_chunk chunk end rescue IO::WaitReadable # nothing, just stop looping rescue EOFError, IOError @eof = true rescue Exception => exc puts "Error in stream consumer: #{exc.class}" # TODO: not sure where to send this error @eof = true end end |