]> source.dussan.org Git - nextcloud-server.git/commitdiff
lazy open first source stream in assemblystream 11994/head
authorRobin Appelman <robin@icewind.nl>
Mon, 22 Oct 2018 13:54:37 +0000 (15:54 +0200)
committerRobin Appelman <robin@icewind.nl>
Tue, 23 Oct 2018 15:44:31 +0000 (17:44 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/dav/lib/Upload/AssemblyStream.php

index 24417851f2f2f60f408cc9bfebfa635b69a6d544..95e324f046878bb286229e490f44f77b4c594ccc 100644 (file)
@@ -76,9 +76,6 @@ class AssemblyStream implements \Icewind\Streams\File {
                        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);
@@ -107,7 +104,11 @@ class AssemblyStream implements \Icewind\Streams\File {
         */
        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 {
@@ -191,7 +192,7 @@ class AssemblyStream implements \Icewind\Streams\File {
         * @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);
        }
 
        /**