Permalink
Browse files

[IO] added :$bin parameter to &open and .open

When called, the file is opened without expecting utf-8. The argument
'binary' to the .encoding method on the filehandle could actually have
been any non-'utf-8' string, since Parrot only has two modes right now.
  • Loading branch information...
1 parent e58b166 commit 2d0a57359c94fdd97476ae69cf831b77ea2af62d @masak masak committed Jul 4, 2010
Showing with 3 additions and 3 deletions.
  1. +3 −3 src/core/IO.pm
View
@@ -35,7 +35,7 @@ class IO is Cool {
}
}
- method open($filename, :$r, :$w, :$a) {
+ multi method open($filename, :$r, :$w, :$a, :$bin) {
if $!PIO { $!PIO.close; $!PIO = Nil; }
my $mode = $w ?? 'w' !! ($a ?? 'wa' !! 'r');
$!PIO = $filename eq '-'
@@ -44,7 +44,7 @@ class IO is Cool {
unless pir::istrue__IP($!PIO) {
fail("Unable to open file '$filename'");
}
- $!PIO.encoding('utf8');
+ $!PIO.encoding($bin ?? 'binary' !! 'utf8');
self;
}
@@ -108,7 +108,7 @@ multi sub say(Mu *@items) { $*OUT.say(@items); }
sub getc($handle) { $handle.getc(); }
-sub open($filename, :$r, :$w, :$a) {
+sub open($filename, :$r, :$w, :$a, :$bin) {
my $mode = $w ?? 'w' !! ($a ?? 'wa' !! 'r');
my $PIO = pir::open__PSS($filename, $mode);
unless pir::istrue__IP($PIO) {

0 comments on commit 2d0a573

Please sign in to comment.