1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
# frozen_string_literal: true
module Seahorse
module Client
class BlockIO
def initialize(headers = nil, &block)
@headers = headers
@block = block
@size = 0
end
# @param [String] chunk
# @return [Integer]
def write(chunk)
@block.call(chunk, @headers)
ensure
chunk.bytesize.tap { |chunk_size| @size += chunk_size }
end
# @param [Integer] bytes (nil)
# @param [String] output_buffer (nil)
# @return [String, nil]
def read(bytes = nil, output_buffer = nil)
data = bytes ? nil : ''
output_buffer ? output_buffer.replace(data || '') : data
end
# @return [Integer]
def size
@size
end
end
end
end
|