file::try("file.yaml", ".yml") * retourne "file.yml" * * @param string|array $exts * @param string|array $replace_ext */ static function try_ext(string $file, $exts=null, $replace_ext=null): ?string { if (file_exists($file)) return $file; if ($exts !== null) { foreach (cl::with($exts) as $ext) { $tmpfile = path::ensure_ext($file, $ext, $replace_ext); if (file_exists($tmpfile)) return $tmpfile; } } return null; } static function reader($input, ?callable $func=null): FileReader { $file = new FileReader(self::fix_dash($input)); if ($func !== null) { try { $func($file); } finally { $file->close(); } } return $file; } static function writer($output, ?string $mode="w+b", ?callable $func=null): FileWriter { $file = new FileWriter(self::fix_dash($output), $mode); if ($func !== null) { try { $func($file); } finally { $file->close(); } } return $file; } static function shared($file, ?callable $func=null): SharedFile { $file = new SharedFile($file); if ($func !== null) { try { $func($file); } finally { $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; } }