Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

IO Buffering #71

Closed
wants to merge 4 commits into
from
View
@@ -101,6 +101,7 @@ class IO does IO::FileTestable {
$!path = $path;
$!chomp = $chomp;
$!PIO.encoding($bin ?? 'binary' !! PARROT_ENCODING($encoding));
+ self.buffer_type(:line);
self;
}
@@ -110,6 +111,13 @@ class IO does IO::FileTestable {
Bool::True;
}
+ # XXX - DESTROY is NYI in Rakudo at the time this was written, so
+ # the following has no effect.
+ method DESTROY() {
@moritz

moritz Oct 16, 2014

Owner

now implemented in rakudo-moar; but it should be submethod, not a method.

+ # It might be correct to self.close(), here, but perhaps not...
+ self.flush();
+ }
+
method eof() {
nqp::p6bool($!PIO.eof);
}
@@ -196,6 +204,26 @@ class IO does IO::FileTestable {
Bool::True
}
+ # Underlying Parrot buffer types:
+ # * unbuffered
+ # * line-buffered
+ # * full-buffered
+ # Returns one of those strings
+ method buffer_type(IO:D: Bool :$unbuffered=False,
+ Bool :$line=False,
+ Bool :$full=False) {
+ my $type = $unbuffered ?? 'unbuffered' !! (
+ $line ?? 'line-buffered' !! (
+ $full ?? 'full-buffered' !!
+ die "buffer_type called without a type"));
+ nqp::p6box_s($!PIO.buffer_type(nqp::unbox_s($type)));
+ }
+
+ method flush(IO:D:) {
+ $!PIO.flush();
+ Bool::True;
+ }
+
multi method say(IO:D: |$) {
my Mu $args := pir::perl6_current_args_rpa__P();
nqp::shift($args);