diff --git a/lib/BlockingDriver.php b/lib/BlockingDriver.php index 661c8c1..09903c0 100644 --- a/lib/BlockingDriver.php +++ b/lib/BlockingDriver.php @@ -11,7 +11,26 @@ class BlockingDriver implements Driver { * {@inheritdoc} */ public function open(string $path, string $mode): Promise { - if (!$fh = \fopen($path, $mode)) { + $mode = \str_replace(['b', 't', 'e'], '', $mode); + + switch ($mode) { + case "r": + case "r+": + case "w": + case "w+": + case "a": + case "a+": + case "x": + case "x+": + case "c": + case "c+": + break; + + default: + throw new \Error("Invalid file mode"); + } + + if (!$fh = \fopen($path, $mode . 'be')) { return new Failure(new FilesystemException( "Failed opening file handle" )); diff --git a/lib/EioDriver.php b/lib/EioDriver.php index e5389ac..19ff1c4 100644 --- a/lib/EioDriver.php +++ b/lib/EioDriver.php @@ -31,7 +31,7 @@ class EioDriver implements Driver { } private function parseMode(string $mode): int { - $mode = \str_replace(['b', 't'], '', $mode); + $mode = \str_replace(['b', 't', 'e'], '', $mode); switch ($mode) { case 'r': return \EIO_O_RDONLY; diff --git a/lib/UvDriver.php b/lib/UvDriver.php index 3cc0840..aeb6610 100644 --- a/lib/UvDriver.php +++ b/lib/UvDriver.php @@ -54,7 +54,7 @@ class UvDriver implements Driver { } private function parseMode(string $mode): int { - $mode = \str_replace(['b', 't'], '', $mode); + $mode = \str_replace(['b', 't', 'e'], '', $mode); switch ($mode) { case "r": return \UV::O_RDONLY;