Skip to content

Commit

Permalink
Fix error handling in Stream::getContents()
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 10, 2023
1 parent 3cb4d16 commit f143df4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,14 @@ public function getContents(): string
throw new \RuntimeException('Stream is detached');
}

if (false === $contents = @\stream_get_contents($this->stream)) {
throw new \RuntimeException('Unable to read stream contents: ' . (\error_get_last()['message'] ?? ''));
$contents = '';

while (!\feof($this->stream)) {
if (false === $result = @\fread($this->stream, 16372)) {
throw new \RuntimeException('Unable to read from stream: ' . (\error_get_last()['message'] ?? ''));
}

$contents .= $result;
}

return $contents;
Expand Down

0 comments on commit f143df4

Please sign in to comment.