You are here

public function Stream::read in Auth0 Single Sign On 8.2

Read data from the stream.

Parameters

int $length Read up to $length bytes from the object and return: them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes.

Return value

string Returns the data read from the stream, or an empty string if no bytes are available.

Throws

\RuntimeException if an error occurs.

Overrides StreamInterface::read

File

vendor/guzzlehttp/psr7/src/Stream.php, line 209

Class

Stream
PHP stream implementation.

Namespace

GuzzleHttp\Psr7

Code

public function read($length) {
  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 '';
  }
  $string = fread($this->stream, $length);
  if (false === $string) {
    throw new \RuntimeException('Unable to read from stream');
  }
  return $string;
}