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

Returns a new instance of 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?

Parameters:

  • bytes (Integer) (defaults to: nil)

    (nil)

  • output_buffer (String) (defaults to: nil)

    (nil)

Returns:

  • (String, nil)


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

Returns:

  • (Integer)


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

def size
  @size
end

#write(chunk) ⇒ Integer

Parameters:

  • chunk (String)

Returns:

  • (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