function copy_to_string in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/guzzlehttp/psr7/src/functions.php \GuzzleHttp\Psr7\copy_to_string()
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.
Return value
string
Throws
\RuntimeException on error.
3 calls to copy_to_string()
- 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/ functions.php, line 304 
Namespace
GuzzleHttp\Psr7Code
function copy_to_string(StreamInterface $stream, $maxLen = -1) {
  $buffer = '';
  if ($maxLen === -1) {
    while (!$stream
      ->eof()) {
      $buf = $stream
        ->read(1048576);
      // Using a loose equality here to match on '' and false.
      if ($buf == null) {
        break;
      }
      $buffer .= $buf;
    }
    return $buffer;
  }
  $len = 0;
  while (!$stream
    ->eof() && $len < $maxLen) {
    $buf = $stream
      ->read($maxLen - $len);
    // Using a loose equality here to match on '' and false.
    if ($buf == null) {
      break;
    }
    $buffer .= $buf;
    $len = strlen($buffer);
  }
  return $buffer;
}