diff --git a/php/src/file.php b/php/src/file.php index 6bd1928..a8175d4 100644 --- a/php/src/file.php +++ b/php/src/file.php @@ -117,4 +117,18 @@ class file { } return $file; } + + static function string_reader(string $content, ?callable $func=null): MemoryStream { + $file = new MemoryStream(); + $file->fwrite($content); + $file->rewind(); + if ($func !== null) { + try { + $func($file); + } finally { + $file ->close(); + } + } + return $file; + } }