37 }
catch (\Exception $e) {
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) {
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) {
154 }
catch (\Exception $e) {
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 : [];
An exception for terminatinating execution or to throw for unit testing.
Reads from multiple streams, one after the other.
tell()
Returns the current position of the file read/write pointer.
seek($offset, $whence=SEEK_SET)
Attempts to seek to the given position.
__toString()
Reads all data from the stream into a string, from the beginning to end.
rewind()
Seek to the beginning of the stream.
read($length)
Reads from all of the appended streams until the length is met or EOF.
write($string)
Write data to the stream.
getSize()
Tries to calculate the size by adding the size of each stream.
addStream(StreamInterface $stream)
Add a stream to the AppendStream.
eof()
Returns true if the stream is at the end of the stream.
detach()
Detaches each attached stream.
isSeekable()
Returns whether or not the stream is seekable.
isReadable()
Returns whether or not the stream is readable.
close()
Closes each attached stream.
__construct(array $streams=[])
getContents()
Returns the remaining contents in a string.
isWritable()
Returns whether or not the stream is writable.
getMetadata($key=null)
Get stream metadata as an associative array or retrieve a specific key.
$stream
PHP stream implementation.
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.
if($state['core:TerminatedAssocId'] !==null) $remaining