Skip to content

Commit

Permalink
Merge pull request #11980 from nextcloud/assemblly-stream-lazy
Browse files Browse the repository at this point in the history
lazy open first source stream in assemblystream
  • Loading branch information
MorrisJobke authored Oct 23, 2018
2 parents 9b092fd + 2f518b6 commit 869df2e
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 869df2e

Please sign in to comment.