Class: Protocol::HTTP1::Body::Remainder
- Inherits:
-
HTTP::Body::Readable
- Object
- HTTP::Body::Readable
- Protocol::HTTP1::Body::Remainder
- Defined in:
- lib/protocol/http1/body/remainder.rb
Constant Summary collapse
- BLOCK_SIZE =
1024 * 64
Instance Method Summary collapse
- #call(stream) ⇒ Object
- #close(error = nil) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(stream) ⇒ Remainder
constructor
block_size may be removed in the future.
- #inspect ⇒ Object
- #join ⇒ Object
-
#read ⇒ Object
TODO this is a bit less efficient in order to maintain compatibility with ‘IO`.
Constructor Details
#initialize(stream) ⇒ Remainder
block_size may be removed in the future. It is better managed by stream.
32 33 34 |
# File 'lib/protocol/http1/body/remainder.rb', line 32 def initialize(stream) @stream = stream end |
Instance Method Details
#call(stream) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/protocol/http1/body/remainder.rb', line 54 def call(stream) self.each do |chunk| stream.write(chunk) end stream.flush end |
#close(error = nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/protocol/http1/body/remainder.rb', line 40 def close(error = nil) # We can't really do anything in this case except close the connection. @stream.close super end |
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/protocol/http1/body/remainder.rb', line 36 def empty? @stream.eof? or @stream.closed? end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/protocol/http1/body/remainder.rb', line 66 def inspect "\#<#{self.class} #{@stream.closed? ? 'closed' : 'open'}>" end |
#join ⇒ Object
62 63 64 |
# File 'lib/protocol/http1/body/remainder.rb', line 62 def join @stream.read end |
#read ⇒ Object
TODO this is a bit less efficient in order to maintain compatibility with ‘IO`.
48 49 50 51 52 |
# File 'lib/protocol/http1/body/remainder.rb', line 48 def read @stream.readpartial(BLOCK_SIZE) rescue EOFError return nil end |