Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Stream.php

function Stream::read

Overrides StreamInterface::read

File

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

Class

Stream
PHP stream implementation.

Namespace

GuzzleHttp\Psr7

Code

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal