lib/protocol/http/body/readable.rb in protocol-http-0.20.1 vs lib/protocol/http/body/readable.rb in protocol-http-0.21.0
- old
+ new
@@ -58,9 +58,24 @@
# Read the next available chunk.
def read
nil
end
+ # Should the internal mechanism prefer to use {call}?
+ # @returns [Boolean]
+ def stream?
+ false
+ end
+
+ # Write the body to the given stream.
+ def call(stream)
+ while chunk = self.read
+ stream.write(chunk)
+ end
+ ensure
+ stream.close($!)
+ end
+
# Read all remaining chunks into a buffered body and close the underlying input.
def finish
# Internally, this invokes `self.each` which then invokes `self.close`.
Buffered.for(self)
end