You are here

public function Stream::read in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/zendframework/zend-diactoros/src/Stream.php \Zend\Diactoros\Stream::read()
  2. 8.0 vendor/guzzlehttp/psr7/src/Stream.php \GuzzleHttp\Psr7\Stream::read()
  3. 8.0 vendor/symfony/psr-http-message-bridge/Tests/Fixtures/Stream.php \Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\Stream::read()
Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-diactoros/src/Stream.php \Zend\Diactoros\Stream::read()

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

1 call to Stream::read()
PhpInputStream::read in vendor/zendframework/zend-diactoros/src/PhpInputStream.php
Read data from the stream.
1 method overrides Stream::read()
PhpInputStream::read in vendor/zendframework/zend-diactoros/src/PhpInputStream.php
Read data from the stream.

File

vendor/zendframework/zend-diactoros/src/Stream.php, line 240

Class

Stream
Implementation of PSR HTTP streams

Namespace

Zend\Diactoros

Code

public function read($length) {
  if (!$this->resource) {
    throw new RuntimeException('No resource available; cannot read');
  }
  if (!$this
    ->isReadable()) {
    throw new RuntimeException('Stream is not readable');
  }
  $result = fread($this->resource, $length);
  if (false === $result) {
    throw new RuntimeException('Error reading stream');
  }
  return $result;
}