Skip to content

Commit

Permalink
Add examples to handle .read/.readchars
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed May 28, 2017
1 parent 93dcea5 commit 760d034
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions doc/Type/IO/Handle.pod6
Expand Up @@ -376,23 +376,39 @@ $fh.close;
Defined as:
method read(IO::Handle:D: Int(Cool:D) $bytes --> Blob)
method read(IO::Handle:D: Int(Cool:D) $bytes --> Buf:D)
Binary reading; reads and returns up to C<$bytes> bytes from the filehandle.
This method can be called even when the handle is not
L<in binary mode|/type/IO::Handle#method_encoding>.
=begin code :skip-test
(my $file = 'foo'.IO).spurt: 'I ♥ Perl';
with $file.open {
say .read: 6; # OUTPUT: «Buf[uint8]:0x<49 20 e2 99 a5 20>␤»
.close;
}
=end code
=head2 method readchars
Defined as:
method readchars(IO::Handle:D: Int(Cool:D) $chars --> Str)
method readchars(IO::Handle:D: Int(Cool:D) $chars --> Str:D)
Reading chars; reads and returns up to C<$chars> chars (graphemes) from the
filehandle. Attempting to call this method when the handle is
L<in binary mode|/type/IO::Handle#method_encoding> will result in
C<X::IO::BinaryMode> exception being thrown.
=begin code :skip-test
(my $file = 'foo'.IO).spurt: 'I ♥ Perl';
with $file.open {
say .readchars: 5; # OUTPUT: «I ♥ P␤»
.close;
}
=end code
=head2 method write
Defined as:
Expand Down

0 comments on commit 760d034

Please sign in to comment.