diff --git a/src/Lib/ValueObjects/FileStream.php b/src/Lib/ValueObjects/FileStream.php index 0c5de79..1755039 100644 --- a/src/Lib/ValueObjects/FileStream.php +++ b/src/Lib/ValueObjects/FileStream.php @@ -20,8 +20,11 @@ final readonly class FileStream throw new UnexpectedStorageException('Resource is not a valid stream.'); } - if (! stream_get_meta_data($this->resource)) { - throw new UnexpectedStorageException('Unable to read stream metadata.'); + $meta = stream_get_meta_data($this->resource); + $mode = $meta['mode']; + + if (! str_contains($mode, 'r') && ! str_contains($mode, '+')) { + throw new UnexpectedStorageException('Stream is not readable.'); } } @@ -66,7 +69,7 @@ final readonly class FileStream } $meta = stream_get_meta_data($this->resource); - if ($meta['seekable'] ?? false) { + if ($meta['seekable']) { rewind($this->resource); }