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. initialize_dup
  5. limit
  6. 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
58 def capacity
59   @limit - @buffer.bytesize
60 end
full?()
[show source]
   # File lib/httpx/buffer.rb
54 def full?
55   @buffer.bytesize >= @limit
56 end
initialize_dup(other)
[show source]
   # File lib/httpx/buffer.rb
49 def initialize_dup(other)
50   super
51   @buffer = other.instance_variable_get(:@buffer).dup
52 end
shift!(fin)
[show source]
   # File lib/httpx/buffer.rb
62 def shift!(fin)
63   @buffer = @buffer.byteslice(fin..-1) || "".b
64 end