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

Breadcrumb

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

function CachingStream::read

Overrides StreamDecoratorTrait::read

1 call to CachingStream::read()
CachingStream::seek in vendor/guzzlehttp/psr7/src/CachingStream.php
Seek to a position in the stream.

File

vendor/guzzlehttp/psr7/src/CachingStream.php, line 89

Class

CachingStream
Stream decorator that can cache previously read bytes from a sequentially read stream.

Namespace

GuzzleHttp\Psr7

Code

public function read($length) : string {
    // Perform a regular read on any previously read data from the buffer
    $data = $this->stream
        ->read($length);
    $remaining = $length - strlen($data);
    // More data was requested so read from the remote stream
    if ($remaining) {
        // If data was written to the buffer in a position that would have
        // been filled from the remote stream, then we must skip bytes on
        // the remote stream to emulate overwriting bytes from that
        // position. This mimics the behavior of other PHP stream wrappers.
        $remoteData = $this->remoteStream
            ->read($remaining + $this->skipReadBytes);
        if ($this->skipReadBytes) {
            $len = strlen($remoteData);
            $remoteData = substr($remoteData, $this->skipReadBytes);
            $this->skipReadBytes = max(0, $this->skipReadBytes - $len);
        }
        $data .= $remoteData;
        $this->stream
            ->write($remoteData);
    }
    return $data;
}

API Navigation

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