Public Class methods
new(body)
[show source]
# File lib/httpx/transcoder/utils/body_reader.rb 8 def initialize(body) 9 @body = if body.respond_to?(:read) 10 body.rewind if body.respond_to?(:rewind) 11 body 12 elsif body.respond_to?(:each) 13 body.enum_for(:each) 14 else 15 StringIO.new(body.to_s) 16 end 17 end
Public Instance methods
bytesize()
[show source]
# File lib/httpx/transcoder/utils/body_reader.rb 19 def bytesize 20 return @body.bytesize if @body.respond_to?(:bytesize) 21 22 Float::INFINITY 23 end
close()
[show source]
# File lib/httpx/transcoder/utils/body_reader.rb 40 def close 41 @body.close if @body.respond_to?(:close) 42 end
read(length = nil, outbuf = nil)
[show source]
# File lib/httpx/transcoder/utils/body_reader.rb 25 def read(length = nil, outbuf = nil) 26 return @body.read(length, outbuf) if @body.respond_to?(:read) 27 28 begin 29 chunk = @body.next 30 if outbuf 31 outbuf.replace(chunk) 32 else 33 outbuf = chunk 34 end 35 outbuf unless length && outbuf.empty? 36 rescue StopIteration 37 end 38 end