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

Breadcrumb

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

function LimitStream::read

Overrides StreamDecoratorTrait::read

File

vendor/guzzlehttp/psr7/src/LimitStream.php, line 140

Class

LimitStream
Decorator used to return only a subset of a stream.

Namespace

GuzzleHttp\Psr7

Code

public function read($length) : string {
    if ($this->limit === -1) {
        return $this->stream
            ->read($length);
    }
    // Check if the current position is less than the total allowed
    // bytes + original offset
    $remaining = $this->offset + $this->limit - $this->stream
        ->tell();
    if ($remaining > 0) {
        // Only return the amount of requested data, ensuring that the byte
        // limit is not exceeded
        return $this->stream
            ->read(min($remaining, $length));
    }
    return '';
}

API Navigation

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