Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

IO Buffering #71

Open
wants to merge 4 commits into from

2 participants

Aaron Sherman ajscogo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 28 additions and 0 deletions. Show diff stats Hide diff stats

  1. 28  src/core/IO.pm
28  src/core/IO.pm
@@ -101,6 +101,7 @@ class IO does IO::FileTestable {
101 101
         $!path = $path;
102 102
         $!chomp = $chomp;
103 103
         $!PIO.encoding($bin ?? 'binary' !! PARROT_ENCODING($encoding));
  104
+        self.buffer_type(:line);
104 105
         self;
105 106
     }
106 107
 
@@ -110,6 +111,13 @@ class IO does IO::FileTestable {
110 111
         Bool::True;
111 112
     }
112 113
 
  114
+    # XXX - DESTROY is NYI in Rakudo at the time this was written, so
  115
+    #       the following has no effect.
  116
+    method DESTROY() {
  117
+        # It might be correct to self.close(), here, but perhaps not...
  118
+        self.flush();
  119
+    }
  120
+
113 121
     method eof() {
114 122
         nqp::p6bool($!PIO.eof);
115 123
     }
@@ -196,6 +204,26 @@ class IO does IO::FileTestable {
196 204
         Bool::True
197 205
     }
198 206
 
  207
+    # Underlying Parrot buffer types:
  208
+    # * unbuffered
  209
+    # * line-buffered
  210
+    # * full-buffered
  211
+    # Returns one of those strings
  212
+    method buffer_type(IO:D: Bool :$unbuffered=False,
  213
+                             Bool :$line=False,
  214
+                             Bool :$full=False) {
  215
+        my $type = $unbuffered ?? 'unbuffered' !! (
  216
+                $line ?? 'line-buffered' !! (
  217
+                    $full ?? 'full-buffered' !!
  218
+                        die "buffer_type called without a type"));
  219
+        nqp::p6box_s($!PIO.buffer_type(nqp::unbox_s($type)));
  220
+    }
  221
+
  222
+    method flush(IO:D:) {
  223
+        $!PIO.flush();
  224
+        Bool::True;
  225
+    }
  226
+
199 227
     multi method say(IO:D: |$) {
200 228
         my Mu $args := pir::perl6_current_args_rpa__P();
201 229
         nqp::shift($args);
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.