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\Psr7Code
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;
}