Skip to content

Commit b1ff1b0

Browse files
committed
Document IO::Handle.READ/.WRITE/.EOF
Spec[^1] blocked by R#2039 rakudo/rakudo#2039 [^1] Raku/roast@3cefe0dc59
1 parent 14d6595 commit b1ff1b0

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

doc/Type/IO/Handle.pod6

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,52 @@ Defined as:
908908
Returns C<True> if the handle is opened to a
909909
L<TTY|https://en.wikipedia.org/wiki/Terminal_emulator>, C<False> otherwise.
910910
911+
=head1 Creating Custom Handles
912+
913+
As of 6.d language (early implementation available in Rakudo compiler version 2018.07), a few
914+
helper methods are available to simplify creation of custom C<IO::Handle> objects. In your subclass
915+
you simply need to implement those methods to affect all of the related features.
916+
917+
=head2 method WRITE
918+
919+
Defined as:
920+
921+
method WRITE(IO::Handle:D: Blob:D \data --> Bool:D)
922+
923+
Called whenever a write operation is performed on the handle. Always receives the data as a
924+
L<Blob>, even if a textual writing method has been called.
925+
926+
=head2 method READ
927+
928+
Defined as:
929+
930+
method READ(IO::Handle:D: Int:D \bytes --> Buf:D)
931+
932+
Called whenever a read operation is performed on the handle. Receives the number of bytes
933+
requested to read. Returns a L<Buf> with those bytes which can be used to either fill the
934+
decoder buffer or returned from reading methods directly. The result is allowed to have fewer than
935+
the requested number of bytes, including no bytes at all.
936+
937+
If you provide your own C<.READ>, you very likely need to provide your own
938+
L<C«.EOF»|/routine/EOF> as well, for all the features to behave correctly.
939+
940+
The compiler may call L<C«.EOF»|/routine/EOF> method any number of times during a read operation to
941+
ascertain whether a call to C<.READ> should be made. More bytes than necessary to satisfy a read
942+
operation may be requested from C<.READ>, in which case the extra data may be buffered by
943+
the L<IO::Handle> or the decoder it's using, to fullfill any subsequent reading operations, without
944+
necessarilly having to make another C<.READ> call.
945+
946+
=head2 method EOF
947+
948+
Defined as:
949+
950+
method EOF(IO::Handle:D: --> Bool:D)
951+
952+
Indicates wether "end of file" has been reached for the B<data source> of the handle; i.e. no more
953+
data can be obtained by calling L<C«.READ»|/routine/READ> method. Note that this is B<not> the
954+
same as L<eof> method, which will return C<True> only if C<.EOF> returns C<True> B<and all
955+
the decoder buffers>, if any were used by the handle, are also empty.
956+
911957
=head1 Related roles and classes
912958
913959
See also the related role L<IO> and the related class L<IO::Path>.

0 commit comments

Comments
 (0)