lib/protocol/http1/body/remainder.rb in protocol-http1-0.8.3 vs lib/protocol/http1/body/remainder.rb in protocol-http1-0.9.0

- old
+ new

@@ -22,27 +22,33 @@ module Protocol module HTTP1 module Body class Remainder < HTTP::Body::Readable + BLOCK_SIZE = 1024 * 64 + + # block_size may be removed in the future. It is better managed by stream. def initialize(stream) @stream = stream end def empty? - @stream.closed? + @stream.eof? or @stream.closed? end def close(error = nil) # We can't really do anything in this case except close the connection. @stream.close - + super end + # TODO this is a bit less efficient in order to maintain compatibility with `IO`. def read - @stream.read_partial + @stream.readpartial(BLOCK_SIZE) + rescue EOFError + return nil end def call(stream) self.each do |chunk| stream.write(chunk) @@ -50,10 +56,10 @@ stream.flush end def join - read + @stream.read end def inspect "\#<#{self.class} #{@stream.closed? ? 'closed' : 'open'}>" end