class Seahorse::Client::Plugins::ReadCallbackIO
@api private
Attributes
io[R]
Public Class Methods
new(io, on_read = nil)
click to toggle source
# File lib/seahorse/client/plugins/request_callback.rb, line 15 def initialize(io, on_read = nil) @io = io @on_read = on_read if on_read.is_a? Proc @bytes_read = 0 # Some IO objects support readpartial - IO.copy_stream used by the # request will call readpartial if available, so define a wrapper # for it if the underlying IO supports it. if @io.respond_to?(:readpartial) def self.readpartial(*args) @io.readpartial(*args).tap do |chunk| handle_chunk(chunk) end end end end
readpartial(*args)
click to toggle source
# File lib/seahorse/client/plugins/request_callback.rb, line 24 def self.readpartial(*args) @io.readpartial(*args).tap do |chunk| handle_chunk(chunk) end end
Public Instance Methods
read(*args)
click to toggle source
# File lib/seahorse/client/plugins/request_callback.rb, line 34 def read(*args) @io.read(*args).tap do |chunk| handle_chunk(chunk) end end
Private Instance Methods
handle_chunk(chunk)
click to toggle source
# File lib/seahorse/client/plugins/request_callback.rb, line 42 def handle_chunk(chunk) @bytes_read += chunk.bytesize if chunk && chunk.respond_to?(:bytesize) total_size = @io.respond_to?(:size) ? @io.size : nil @on_read.call(chunk, @bytes_read, total_size) if @on_read end