class Buf
src
class Buf does Positional { ... }
A Buf (short for buffer) is a binary string, and generally returned from
low-level IO operations ( $io.read($number-of-by) ) or from Str.encode .
It can be used to for writing to IO handles as $io.write($buf) .
In the abstract it is just a list of integers, so
for example indexing into a Buf with .[$idx] returns an Int .
Methods
new
method new(*@codes)
Creates a Buf from a list of integers.
Bool
multi method Bool(Buf:D:)
Returns False if and only if the buffer is empty.
elems
multi method elems(Buf:D:) returns Int:D
Returns the number of elements of the buffer.
decode
multi method decode(Buf:D: Str:D $encoding = 'UTF-8') returns Str:D
Applies an encoding to turn the buffer into a Str .
subbuf
method subbuf(Int $from, Int $len = self.elems) returns Buf:D
Extracts a part of the invocant buffer, statrting from the index with
elements $from , and taking $len elements (or less if the buffer is
shorter), and creates a new buffer as the result.
say Buf.new(1..10).subbuf(2, 4); # Buf:0x<03 04 05 06>