function Utils::copyToString
Copy the contents of a stream into a string until the given number of bytes have been read.
Parameters
StreamInterface $stream Stream to read:
int $maxLen Maximum number of bytes to read. Pass -1: to read the entire stream.
Throws
\RuntimeException on error.
3 calls to Utils::copyToString()
- AppendStream::getContents in vendor/
guzzlehttp/ psr7/ src/ AppendStream.php - Returns the remaining contents in a string
- PumpStream::__toString in vendor/
guzzlehttp/ psr7/ src/ PumpStream.php - Reads all data from the stream into a string, from the beginning to end.
- StreamDecoratorTrait::getContents in vendor/
guzzlehttp/ psr7/ src/ StreamDecoratorTrait.php
File
-
vendor/
guzzlehttp/ psr7/ src/ Utils.php, line 81
Class
Namespace
GuzzleHttp\Psr7Code
public static function copyToString(StreamInterface $stream, int $maxLen = -1) : string {
$buffer = '';
if ($maxLen === -1) {
while (!$stream->eof()) {
$buf = $stream->read(1048576);
if ($buf === '') {
break;
}
$buffer .= $buf;
}
return $buffer;
}
$len = 0;
while (!$stream->eof() && $len < $maxLen) {
$buf = $stream->read($maxLen - $len);
if ($buf === '') {
break;
}
$buffer .= $buf;
$len = strlen($buffer);
}
return $buffer;
}