class HTTPX::Buffer

  1. lib/httpx/buffer.rb
Superclass: Object

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

Methods

Public Class

  1. new

Public Instance

  1. <<
  2. capacity
  3. full?
  4. limit
  5. shift!

Attributes

limit [R]

Public Class methods

new(limit)
[show source]
   # File lib/httpx/buffer.rb
32 def initialize(limit)
33   @buffer = String.new("", encoding: Encoding::BINARY, capacity: limit)
34   @limit = limit
35 end

Public Instance methods

<<(chunk)
[show source]
   # File lib/httpx/buffer.rb
37 def <<(chunk)
38   @buffer.append_as_bytes(chunk)
39 end
capacity()
[show source]
   # File lib/httpx/buffer.rb
53 def capacity
54   @limit - @buffer.bytesize
55 end
full?()
[show source]
   # File lib/httpx/buffer.rb
49 def full?
50   @buffer.bytesize >= @limit
51 end
shift!(fin)
[show source]
   # File lib/httpx/buffer.rb
57 def shift!(fin)
58   @buffer = @buffer.byteslice(fin..-1) || "".b
59 end