fix(FileStream): improve stream validation in constructor
Ensure the stream is readable and metadata is correctly checked.
This commit is contained in:
parent
f956a47c35
commit
bb1129c209
1 changed files with 6 additions and 3 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue