readchars
ErrorsCollection

readchars

Synthesised documentation from type/IO/Handle type/IO/CatHandle

From type/IO/Handle

See Original text in context

method readchars(IO::Handle:D: Int(Cool:D$chars = 65536 --> Str:D)

Reading chars; reads and returns up to $chars chars (graphemes) from the filehandle. $chars defaults to an implementation-specific value (in Rakudo, the value of $*DEFAULT-READ-ELEMS, which by default is set to 65536). Attempting to call this method when the handle is :$enc will result in X::IO::BinaryMode exception being thrown.

(my $file = 'foo'.IO).spurt: 'I ♥ Raku';
given $file.open {
    say .readchars: 5# OUTPUT: «I ♥ R␤» 
    .close;
}

From type/IO/CatHandle

See Original text in context

method readchars(IO::CatHandle:D: Int(Cool:D$chars = 65536 --> Str:D)

Returns a Str of up to $chars characters read from the handle. $chars defaults to an implementation-specific value (in Rakudo, the value of $*DEFAULT-READ-ELEMS, which by default is set to 65536). It is NOT permitted to call this method on handles opened in binary mode and doing so will result in X::IO::BinaryMode exception being thrown.

(my $f1 = 'foo'.IO).spurt: 'Raku loves to';
(my $f2 = 'bar'.IO).spurt: ' meow';
 
with IO::CatHandle.new: $f1$f2 {
    say .readchars: 11;   # OUTPUT: «Raku loves ␤» 
    say .readchars: 1000# OUTPUT: «to meow␤» 
}