Skip to content

Commit

Permalink
lazy open first source stream in assemblystream
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Oct 22, 2018
1 parent f737ae7 commit 2f518b6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions apps/dav/lib/Upload/AssemblyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ public function stream_open($path, $mode, $options, &$opened_path) {
return strnatcmp($a->getName(), $b->getName());
});
$this->nodes = array_values($nodes);
if (count($this->nodes) > 0) {
$this->currentStream = $this->getStream($this->nodes[0]);
}
$this->size = array_reduce($this->nodes, function ($size, IFile $file) {
return $size + $file->getSize();
}, 0);
Expand Down Expand Up @@ -107,7 +104,11 @@ public function stream_tell() {
*/
public function stream_read($count) {
if (is_null($this->currentStream)) {
return '';
if ($this->currentNode < count($this->nodes)) {
$this->currentStream = $this->getStream($this->nodes[$this->currentNode]);
} else {
return '';
}
}

do {
Expand Down Expand Up @@ -191,7 +192,7 @@ public function stream_flush() {
* @return bool
*/
public function stream_eof() {
return $this->pos >= $this->size || $this->currentStream === null;
return $this->pos >= $this->size || ($this->currentNode >= count($this->nodes) && $this->currentNode === null);
}

/**
Expand Down

0 comments on commit 2f518b6

Please sign in to comment.