Class: HTTPX::Buffer
- Inherits:
-
Object
- Object
- HTTPX::Buffer
- Extended by:
- Forwardable
- Defined in:
- lib/httpx/buffer.rb
Overview
Internal class to abstract a string buffer, by wrapping a string and providing the minimum possible API and functionality required.
buffer = Buffer.new(640)
buffer.full? #=> false
buffer << "aa"
buffer.capacity #=> 638
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
- #capacity ⇒ Object
- #full? ⇒ Boolean
-
#initialize(limit) ⇒ Buffer
constructor
A new instance of Buffer.
- #shift!(fin) ⇒ Object
Constructor Details
#initialize(limit) ⇒ Buffer
Returns a new instance of Buffer.
33 34 35 36 |
# File 'lib/httpx/buffer.rb', line 33 def initialize(limit) @buffer = "".b @limit = limit end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
31 32 33 |
# File 'lib/httpx/buffer.rb', line 31 def limit @limit end |
Instance Method Details
#capacity ⇒ Object
42 43 44 |
# File 'lib/httpx/buffer.rb', line 42 def capacity @limit - @buffer.bytesize end |
#full? ⇒ Boolean
38 39 40 |
# File 'lib/httpx/buffer.rb', line 38 def full? @buffer.bytesize >= @limit end |
#shift!(fin) ⇒ Object
46 47 48 |
# File 'lib/httpx/buffer.rb', line 46 def shift!(fin) @buffer = @buffer.byteslice(fin..-1) || "".b end |