Class: Seahorse::Client::BlockIO

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

Instance Method Summary collapse

Constructor Details

#initialize(headers = nil, &block) ⇒ BlockIO



7
8
9
10
11
# File 'lib/seahorse/client/block_io.rb', line 7

def initialize(headers = nil, &block)
  @headers = headers
  @block = block
  @size = 0
end

Instance Method Details

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



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

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

#sizeInteger



30
31
32
# File 'lib/seahorse/client/block_io.rb', line 30

def size
  @size
end

#write(chunk) ⇒ Integer



15
16
17
18
19
# File 'lib/seahorse/client/block_io.rb', line 15

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