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 41 def close 42 @body.close if @body.respond_to?(:close) 43 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.clear.force_encoding(Encoding::BINARY) 32 outbuf << chunk 33 else 34 outbuf = chunk 35 end 36 outbuf unless length && outbuf.empty? 37 rescue StopIteration 38 end 39 end