diff --git a/src/os/file.php b/src/os/file.php index e42749b..40d09f1 100644 --- a/src/os/file.php +++ b/src/os/file.php @@ -3,7 +3,9 @@ namespace nur\sery\os; use nur\sery\os\file\FileReader; use nur\sery\os\file\FileWriter; +use nur\sery\os\file\MemoryStream; use nur\sery\os\file\SharedFile; +use nur\sery\os\file\TempStream; use nur\sery\os\file\TmpfileWriter; /** @@ -11,47 +13,74 @@ use nur\sery\os\file\TmpfileWriter; */ class file { static function reader($input, ?callable $func=null): FileReader { - $reader = new FileReader($input); + $file = new FileReader($input); if ($func !== null) { try { - $func($reader); + $func($file); } finally { - $reader->close(); + $file->close(); } } + return $file; } static function writer($output, ?callable $func=null): FileWriter { - $writer = new FileWriter($output); + $file = new FileWriter($output); if ($func !== null) { try { - $func($writer); + $func($file); } finally { - $writer->close(); - } - } - } - - static function tmpwriter($destdir=null, ?callable $func=null): TmpfileWriter { - $tmpwriter = new TmpfileWriter($destdir); - if ($func !== null) { - try { - $func($tmpwriter); - } finally { - $tmpwriter->close(); + $file->close(); } } + return $file; } static function shared($file, ?callable $func=null): SharedFile { - $shared = new SharedFile($file); + $file = new SharedFile($file); if ($func !== null) { try { - $func($shared); + $func($file); } finally { - $shared ->close(); + $file ->close(); } } + return $file; } + static function tmpwriter($destdir=null, ?callable $func=null): TmpfileWriter { + $file = new TmpfileWriter($destdir); + if ($func !== null) { + try { + $func($file); + } finally { + $file->close(); + } + } + return $file; + } + + static function memory(?callable $func=null): MemoryStream { + $file = new MemoryStream(); + if ($func !== null) { + try { + $func($file); + } finally { + $file->close(); + } + } + return $file; + } + + static function temp(?callable $func=null): TempStream { + $file = new TempStream(); + if ($func !== null) { + try { + $func($file); + } finally { + $file->close(); + } + } + return $file; + } }