Skip to content

Commit c3919b8

Browse files
authored
Merge pull request #11997 from nextcloud/assemblly-stream-lazy-13
lazy open first source stream in assemblystream
2 parents 56812b0 + 13317da commit c3919b8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

apps/dav/lib/Upload/AssemblyStream.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ public function stream_open($path, $mode, $options, &$opened_path) {
7373
return strnatcmp($a->getName(), $b->getName());
7474
});
7575
$this->nodes = array_values($nodes);
76-
if (count($this->nodes) > 0) {
77-
$this->currentStream = $this->getStream($this->nodes[0]);
78-
}
7976
$this->size = array_reduce($this->nodes, function ($size, IFile $file) {
8077
return $size + $file->getSize();
8178
}, 0);
@@ -104,7 +101,11 @@ public function stream_tell() {
104101
*/
105102
public function stream_read($count) {
106103
if (is_null($this->currentStream)) {
107-
return '';
104+
if ($this->currentNode < count($this->nodes)) {
105+
$this->currentStream = $this->getStream($this->nodes[$this->currentNode]);
106+
} else {
107+
return '';
108+
}
108109
}
109110

110111
do {
@@ -182,7 +183,7 @@ public function stream_flush() {
182183
* @return bool
183184
*/
184185
public function stream_eof() {
185-
return $this->pos >= $this->size || $this->currentStream === null;
186+
return $this->pos >= $this->size || ($this->currentNode >= count($this->nodes) && $this->currentNode === null);
186187
}
187188

188189
/**

0 commit comments

Comments
 (0)