Class: Kitchen::Driver::VMMUtils::StreamReader
- Inherits:
-
Object
- Object
- Kitchen::Driver::VMMUtils::StreamReader
- Defined in:
- lib/kitchen/driver/vmm_utils.rb
Overview
for powershell stdout read
Instance Method Summary collapse
- #<<(chunk) ⇒ Object
-
#initialize(&block) ⇒ StreamReader
constructor
A new instance of StreamReader.
Constructor Details
#initialize(&block) ⇒ StreamReader
Returns a new instance of StreamReader.
57 58 59 60 61 |
# File 'lib/kitchen/driver/vmm_utils.rb', line 57 def initialize(&block) @block = block @buffer = StringIO.new @buffer.sync = true if @buffer.respond_to?(:sync) end |
Instance Method Details
#<<(chunk) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kitchen/driver/vmm_utils.rb', line 63 def <<(chunk) overflow = '' @buffer.write(chunk) @buffer.rewind @buffer.each_line do |line| if line.match(/\r?\n/) @block.call(line.strip) else overflow = line end end @buffer.truncate(@buffer.rewind) @buffer.write(overflow) end |