36 return max($this->stream->getSize(), $this->remoteStream->getSize());
44 public function seek($offset, $whence = SEEK_SET)
46 if ($whence == SEEK_SET) {
48 } elseif ($whence == SEEK_CUR) {
49 $byte = $offset + $this->
tell();
50 } elseif ($whence == SEEK_END) {
51 $size = $this->remoteStream->getSize();
55 $byte =
$size + $offset;
57 throw new \InvalidArgumentException(
'Invalid whence');
60 $diff = $byte - $this->stream->getSize();
65 while ($diff > 0 && !$this->remoteStream->eof()) {
67 $diff = $byte - $this->stream->getSize();
71 $this->stream->seek($byte);
75 public function read($length)
78 $data = $this->stream->read($length);
87 $remoteData = $this->remoteStream->read(
91 if ($this->skipReadBytes) {
92 $len = strlen($remoteData);
93 $remoteData = substr($remoteData, $this->skipReadBytes);
94 $this->skipReadBytes = max(0, $this->skipReadBytes - $len);
98 $this->stream->write($remoteData);
110 $overflow = (strlen($string) + $this->
tell()) - $this->remoteStream->tell();
112 $this->skipReadBytes += $overflow;
115 return $this->stream->write($string);
120 return $this->stream->eof() && $this->remoteStream->eof();
128 $this->remoteStream->close() && $this->stream->close();
136 return $this->
tell();
Stream decorator that can cache previously read bytes from a sequentially read stream.
rewind()
Seek to the beginning of the stream.
read($length)
Read data from the stream.
if($state['core:TerminatedAssocId'] !==null) $remaining
$stream
PHP stream implementation.
close()
Close both the remote stream and buffer stream.
getSize()
Get the size of the stream if known.
eof()
Returns true if the stream is at the end of the stream.
Compose stream implementations based on a hash of functions.
copy_to_stream(StreamInterface $source, StreamInterface $dest, $maxLen=-1)
Copy the contents of a stream into another stream until the given number of bytes have been read...
__construct(StreamInterface $stream, StreamInterface $target=null)
We will treat the buffer object as the body of the stream.
write($string)
Write data to the stream.
seek($offset, $whence=SEEK_SET)
Seek to a position in the stream.
tell()
Returns the current position of the file read/write pointer.