You are here

function copy_to_string in Auth0 Single Sign On 8.2

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 332

Namespace

GuzzleHttp\Psr7

Code

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;
}