perl6/doc/lib/Buf

doc src
(title) class Buf
    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

(head2) new
    method new(*@codes)

 
Creates a Buf from a list of integers.
(head2) Bool
    multi method Bool(Buf:D:)

 
Returns False if and only if the buffer is empty.
(head2) elems
    multi method elems(Buf:D:) returns Int:D

 
Returns the number of elements of the buffer.
(head2) decode
    multi method decode(Buf:D: Str:D $encoding = 'UTF-8') returns Str:D

 
Applies an encoding to turn the buffer into a Str .
(head2) 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>

 

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: