Class: Async::HTTP::Body::Fixed
- Defined in:
- lib/async/http/body/fixed.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#remaining ⇒ Object
readonly
Returns the value of attribute remaining.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(stream, length) ⇒ Fixed
constructor
A new instance of Fixed.
- #inspect ⇒ Object
- #join ⇒ Object
- #read ⇒ Object
- #stop(error) ⇒ Object
Methods inherited from Readable
Constructor Details
#initialize(stream, length) ⇒ Fixed
Returns a new instance of Fixed.
27 28 29 30 31 |
# File 'lib/async/http/body/fixed.rb', line 27 def initialize(stream, length) @stream = stream @length = length @remaining = length end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
33 34 35 |
# File 'lib/async/http/body/fixed.rb', line 33 def length @length end |
#remaining ⇒ Object (readonly)
Returns the value of attribute remaining.
34 35 36 |
# File 'lib/async/http/body/fixed.rb', line 34 def remaining @remaining end |
Instance Method Details
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/async/http/body/fixed.rb', line 36 def empty? @remaining == 0 end |
#inspect ⇒ Object
64 65 66 |
# File 'lib/async/http/body/fixed.rb', line 64 def inspect "\#<#{self.class} length=#{@length} remaining=#{@remaining}>" end |
#join ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/async/http/body/fixed.rb', line 56 def join buffer = @stream.read(@remaining) @remaining = 0 return buffer end |
#read ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/async/http/body/fixed.rb', line 46 def read if @remaining > 0 if chunk = @stream.read_partial(@remaining) @remaining -= chunk.bytesize return chunk end end end |
#stop(error) ⇒ Object
40 41 42 43 44 |
# File 'lib/async/http/body/fixed.rb', line 40 def stop(error) if @remaining != 0 @stream.close end end |