class Buf

String of bytes

class Buf does Positional { ... }

A Buf (short for buffer) is a binary string, and generally returned from low-level IO operations ($$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.


method new

method new(*@codes)

Creates a Buf from a list of integers.

method Bool

multi method Bool(Buf:D:)

Returns False if and only if the buffer is empty.

method elems

multi method elems(Buf:D:) returns Int:D

Returns the number of elements of the buffer.

method decode

multi method decode(Buf:D: Str:D $encoding = 'UTF-8') returns Str:D

Applies an encoding to turn the buffer into a Str.

method subbuf

method subbuf(Int $from, Int $len = self.elems) returns Buf:D

Extracts a part of the invocant buffer, starting 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, 4);    # Buf:0x<03 04 05 06>

Type graph

Below you should see an image showing the type relations for Buf. If not, try the PNG version.

perl6-type-graph Buf Buf Blob Blob Buf->Blob Positional Positional Stringy Stringy Blob->Positional Blob->Stringy