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

Breadcrumb

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

function CachingStream::seek

Overrides StreamDecoratorTrait::seek

1 call to CachingStream::seek()
CachingStream::rewind in vendor/guzzlehttp/psr7/src/CachingStream.php
Seek to the beginning of the stream.

File

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

Class

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

Namespace

GuzzleHttp\Psr7

Code

public function seek($offset, $whence = SEEK_SET) : void {
    if ($whence === SEEK_SET) {
        $byte = $offset;
    }
    elseif ($whence === SEEK_CUR) {
        $byte = $offset + $this->tell();
    }
    elseif ($whence === SEEK_END) {
        $size = $this->remoteStream
            ->getSize();
        if ($size === null) {
            $size = $this->cacheEntireStream();
        }
        $byte = $size + $offset;
    }
    else {
        throw new \InvalidArgumentException('Invalid whence');
    }
    $diff = $byte - $this->stream
        ->getSize();
    if ($diff > 0) {
        // Read the remoteStream until we have read in at least the amount
        // of bytes requested, or we reach the end of the file.
        while ($diff > 0 && !$this->remoteStream
            ->eof()) {
            $this->read($diff);
            $diff = $byte - $this->stream
                ->getSize();
        }
    }
    else {
        // We can just do a normal seek since we've already seen this byte.
        $this->stream
            ->seek($byte);
    }
}

API Navigation

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