class

Crowbar::Buffer

Inherits Reference < Object

Binary-safe byte buffer container for non-destructive and in-place transformations. Handles raw bytes, arbitrary non-UTF-8 binaries, and provides slicing/splicing helpers.

Constructors

from_io(io : IO, limit : Int32 | Nil = nil) : self
Source
new(initial_bytes : Bytes | Array(UInt8) | String = Bytes.empty)
Source

Instance methods

==(other : Buffer) : Bool
Source
==(other) : Bool

Returns false (other can only be a Value here).

Source
[](start : Int32, count : Int32) : Bytes
Source
[](range : Range(B, E)) : Bytes forall B, E
Source
[](index : Int32) : UInt8
Source
[]=(index : Int32, value : UInt8)
Source
[]?(index : Int32) : UInt8 | Nil
Source
bytes
Source
clear

Clears all bytes in buffer

Source
clone
Source
concat(slice : Bytes | Array(UInt8)) : Nil

Appends bytes to the buffer

Source
delete_at(pos : Int32) : UInt8 | Nil

Delete single byte at position

Source
delete_range(start : Int32, length : Int32)

Delete a contiguous range of bytes

Source
empty?
Source
find_delimiter_pairs(open_byte : UInt8, close_byte : UInt8) : Array(Tuple(Int32, Int32))

Find balanced delimiter pairs like (), [], {}, <>, "", ''

Source
hash(hasher)

See Object#hash(hasher)

Source
index(needle : Bytes | Array(UInt8) | Buffer, offset : Int32 = 0) : Int32 | Nil

Searches for a needle sequence starting at offset

Source
insert(pos : Int32, byte : UInt8)

Insert a single byte at position

Source
insert(pos : Int32, slice : Bytes | Array(UInt8))

Insert a byte slice at position

Source
lines

Find line ranges (0-indexed [start, end_exclusive])

Source
replace_range(start : Int32, length : Int32, replacement : Bytes | Array(UInt8))

Replace a slice with another slice

Source
size
Source
swap_ranges(pos1 : Int32, len : Int32, pos2 : Int32, len2 : Int32 = len) : Nil

Swaps two equal-length ranges of bytes in-place

Source
text?

Check if buffer appears to be mostly text

Source
to_raw_s
Source
to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Source
to_s

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.

Source
to_slice
Source