12 use StreamDecoratorTrait;
31 $this->stream =
$target ?:
new Stream(fopen(
'php://temp',
'r+'));
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();
An exception for terminatinating execution or to throw for unit testing.
Stream decorator that can cache previously read bytes from a sequentially read stream.
getSize()
Get the size of the stream if known.
seek($offset, $whence=SEEK_SET)
Seek to a position in the stream.
write($string)
Write data to the stream.
rewind()
Seek to the beginning of the stream.
close()
Close both the remote stream and buffer stream.
eof()
Returns true if the stream is at the end of the stream.
read($length)
Read data from the stream.
__construct(StreamInterface $stream, StreamInterface $target=null)
We will treat the buffer object as the body of the stream.
Compose stream implementations based on a hash of functions.
tell()
Returns the current position of the file read/write pointer.
$stream
PHP stream implementation.
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.
if($state['core:TerminatedAssocId'] !==null) $remaining