52 throw new \InvalidArgumentException(
'Each stream must be readable');
57 $this->seekable =
false;
75 $this->pos = $this->current = 0;
77 foreach ($this->streams as
$stream) {
92 $this->detached =
true;
112 foreach ($this->streams as
$stream) {
113 $s = $stream->getSize();
125 return !$this->streams ||
126 ($this->current >= count($this->streams) - 1 &&
140 public function seek($offset, $whence = SEEK_SET)
142 if (!$this->seekable) {
143 throw new \RuntimeException(
'This AppendStream is not seekable');
144 } elseif ($whence !== SEEK_SET) {
145 throw new \RuntimeException(
'The AppendStream can only seek with SEEK_SET');
148 $this->pos = $this->current = 0;
151 foreach ($this->streams as
$i =>
$stream) {
155 throw new \RuntimeException(
'Unable to seek stream ' 156 .
$i .
' of the AppendStream', 0, $e);
161 while ($this->pos < $offset && !$this->
eof()) {
162 $result = $this->
read(min(8096, $offset - $this->pos));
177 $total = count($this->streams) - 1;
179 $progressToNext =
false;
184 if ($progressToNext || $this->streams[$this->current]->
eof()) {
185 $progressToNext =
false;
186 if ($this->current ===
$total) {
196 $progressToNext =
true;
204 $this->pos += strlen($buffer);
226 throw new \RuntimeException(
'Cannot write to an AppendStream');
231 return $key ? null : [];
getSize()
Tries to calculate the size by adding the size of each stream.
__toString()
Reads all data from the stream into a string, from the beginning to end.
rewind()
Seek to the beginning of the stream.
if($state['core:TerminatedAssocId'] !==null) $remaining
write($string)
Write data to the stream.
$stream
PHP stream implementation.
isReadable()
Returns whether or not the stream is readable.
getContents()
Returns the remaining contents in a string.
eof()
Returns true if the stream is at the end of the stream.
addStream(StreamInterface $stream)
Add a stream to the AppendStream.
isSeekable()
Returns whether or not the stream is seekable.
read($length)
Reads from all of the appended streams until the length is met or EOF.
__construct(array $streams=[])
close()
Closes each attached stream.
detach()
Detaches each attached stream.
isWritable()
Returns whether or not the stream is writable.
copy_to_string(StreamInterface $stream, $maxLen=-1)
Copy the contents of a stream into a string until the given number of bytes have been read...
isReadable()
Returns whether or not the stream is readable.
Reads from multiple streams, one after the other.
getMetadata($key=null)
Get stream metadata as an associative array or retrieve a specific key.
isSeekable()
Returns whether or not the stream is seekable.
seek($offset, $whence=SEEK_SET)
Attempts to seek to the given position.
tell()
Returns the current position of the file read/write pointer.