From 2f518b6ac880cff556e3e52a84a4aa048eeaecbe Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 22 Oct 2018 15:54:37 +0200 Subject: [PATCH] lazy open first source stream in assemblystream Signed-off-by: Robin Appelman --- apps/dav/lib/Upload/AssemblyStream.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/dav/lib/Upload/AssemblyStream.php b/apps/dav/lib/Upload/AssemblyStream.php index 24417851f2f2f..95e324f046878 100644 --- a/apps/dav/lib/Upload/AssemblyStream.php +++ b/apps/dav/lib/Upload/AssemblyStream.php @@ -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); @@ -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 { @@ -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); } /**