Class: Seahorse::Client::BlockIO

Inherits:
Object
  • Object
show all
Defined in:
lib/seahorse/client/block_io.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ BlockIO



5
6
7
8
# File 'lib/seahorse/client/block_io.rb', line 5

def initialize(&block)
  @block = block
  @size = 0
end

Instance Method Details

#read(bytes = nil, output_buffer = nil) ⇒ String?



20
21
22
23
# File 'lib/seahorse/client/block_io.rb', line 20

def read(bytes = nil, output_buffer = nil)
  data = bytes ? nil : ''
  output_buffer ? output_buffer.replace(data || '') : data
end

#sizeInteger



26
27
28
# File 'lib/seahorse/client/block_io.rb', line 26

def size
  @size
end

#write(chunk) ⇒ Integer



12
13
14
15
# File 'lib/seahorse/client/block_io.rb', line 12

def write(chunk)
  @block.call(chunk)
  chunk.bytesize.tap { |chunk_size| @size += chunk_size }
end