* This file is part of the ManageWP Worker plugin.
* (c) ManageWP LLC <contact@managewp.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
class MWP_Stream_Append implements MWP_Stream_Interface
* @var MWP_Stream_Interface[]
private $streams = array();
* Add a stream to the AppendStream
* @param MWP_Stream_Interface $stream Stream to append. Must be readable.
public function addStream(MWP_Stream_Interface $stream)
$this->streams[] = $stream;
public function isSeekable()
public function seek($offset, $whence = SEEK_SET)
return $this->isAtLastStream() && $this->getCurrentStream()->eof();
public function read($length)
while ($this->getCurrentStream()->eof() && !$this->eof()) {
$this->moveToNextStream();
$currentStreamData = $this->getCurrentStream()->read($length);
$data .= $currentStreamData;
$length -= strlen($currentStreamData);
foreach ($this->streams as $stream) {
public function __toString()
$buffer .= $this->read(1048576);
private function moveToNextStream()
if ($this->current >= count($this->streams)) {
private function isAtLastStream()
return $this->current === count($this->streams) - 1;
private function getCurrentStream()
return $this->streams[$this->current];