Sha256: 13ba45eadde003cba8e8021677c515ca14c404b3aca730f7d5077c063aee8d1b

Contents?: true

Size: 932 Bytes

Versions: 10

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true

require "forwardable"

module HTTPX
  # 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
  #
  class Buffer
    extend Forwardable

    def_delegator :@buffer, :<<

    def_delegator :@buffer, :to_s

    def_delegator :@buffer, :to_str

    def_delegator :@buffer, :empty?

    def_delegator :@buffer, :bytesize

    def_delegator :@buffer, :clear

    def_delegator :@buffer, :replace

    attr_reader :limit

    def initialize(limit)
      @buffer = "".b
      @limit = limit
    end

    def full?
      @buffer.bytesize >= @limit
    end

    def capacity
      @limit - @buffer.bytesize
    end

    def shift!(fin)
      @buffer = @buffer.byteslice(fin..-1) || "".b
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
httpx-1.3.4 lib/httpx/buffer.rb
httpx-1.3.3 lib/httpx/buffer.rb
httpx-1.3.2 lib/httpx/buffer.rb
httpx-1.3.1 lib/httpx/buffer.rb
httpx-1.3.0 lib/httpx/buffer.rb
httpx-1.2.6 lib/httpx/buffer.rb
httpx-1.2.4 lib/httpx/buffer.rb
httpx-1.2.3 lib/httpx/buffer.rb
httpx-1.2.2 lib/httpx/buffer.rb
httpx-1.2.1 lib/httpx/buffer.rb