function Utils::copyToStream
Copy the contents of a stream into another stream until the given number of bytes have been read.
Parameters
StreamInterface $source Stream to read from:
StreamInterface $dest Stream to write to:
int $maxLen Maximum number of bytes to read. Pass -1: to read the entire stream.
Throws
\RuntimeException on error.
2 calls to Utils::copyToStream()
- CachingStream::cacheEntireStream in vendor/
guzzlehttp/ psr7/ src/ CachingStream.php - UploadedFile::moveTo in vendor/
guzzlehttp/ psr7/ src/ UploadedFile.php - Move the uploaded file to a new location.
File
-
vendor/
guzzlehttp/ psr7/ src/ Utils.php, line 47
Class
Namespace
GuzzleHttp\Psr7Code
public static function copyToStream(StreamInterface $source, StreamInterface $dest, int $maxLen = -1) : void {
$bufferSize = 8192;
if ($maxLen === -1) {
while (!$source->eof()) {
if (!$dest->write($source->read($bufferSize))) {
break;
}
}
}
else {
$remaining = $maxLen;
while ($remaining > 0 && !$source->eof()) {
$buf = $source->read(min($bufferSize, $remaining));
$len = strlen($buf);
if (!$len) {
break;
}
$remaining -= $len;
$dest->write($buf);
}
}
}