function Stream::read
Overrides StreamInterface::read
File
-
vendor/
guzzlehttp/ psr7/ src/ Stream.php, line 217
Class
- Stream
- PHP stream implementation.
Namespace
GuzzleHttp\Psr7Code
public function read($length) : string {
if (!isset($this->stream)) {
throw new \RuntimeException('Stream is detached');
}
if (!$this->readable) {
throw new \RuntimeException('Cannot read from non-readable stream');
}
if ($length < 0) {
throw new \RuntimeException('Length parameter cannot be negative');
}
if (0 === $length) {
return '';
}
try {
$string = fread($this->stream, $length);
} catch (\Exception $e) {
throw new \RuntimeException('Unable to read from stream', 0, $e);
}
if (false === $string) {
throw new \RuntimeException('Unable to read from stream');
}
return $string;
}