You are here

public function CachingStream::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 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 75

Class

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

Namespace

GuzzleHttp\Psr7

Code

public function read($length) {

  // 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;
}