diff options
author | Robin Appelman <robin@icewind.nl> | 2019-03-12 13:38:45 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2019-03-13 16:32:18 +0100 |
commit | 6a47f924fca8c262129abba04772a8859871c9ba (patch) | |
tree | 457a26e46d15ccebb29c4ddaf72673ee826a9a7d /apps/dav/lib/Upload/AssemblyStream.php | |
parent | aff13a20721765b51108c14e4bba1916f4ba59a7 (diff) | |
download | nextcloud-server-6a47f924fca8c262129abba04772a8859871c9ba.tar.gz nextcloud-server-6a47f924fca8c262129abba04772a8859871c9ba.zip |
make assemblystream seekable
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/dav/lib/Upload/AssemblyStream.php')
-rw-r--r-- | apps/dav/lib/Upload/AssemblyStream.php | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/apps/dav/lib/Upload/AssemblyStream.php b/apps/dav/lib/Upload/AssemblyStream.php index eaf24f8741a..c8a1be82f6b 100644 --- a/apps/dav/lib/Upload/AssemblyStream.php +++ b/apps/dav/lib/Upload/AssemblyStream.php @@ -83,12 +83,46 @@ class AssemblyStream implements \Icewind\Streams\File { } /** - * @param string $offset + * @param int $offset * @param int $whence * @return bool */ public function stream_seek($offset, $whence = SEEK_SET) { - return false; + if ($whence === SEEK_CUR) { + $offset = $this->stream_tell() + $offset; + } else if ($whence === SEEK_END) { + $offset = $this->size + $offset; + } + + if ($offset > $this->size) { + return false; + } + + $nodeIndex = 0; + $nodeStart = 0; + while (true) { + if (!isset($this->nodes[$nodeIndex + 1])) { + break; + } + $node = $this->nodes[$nodeIndex]; + if ($nodeStart + $node->getSize() > $offset) { + break; + } + $nodeIndex++; + $nodeStart += $node->getSize(); + } + + $stream = $this->getStream($this->nodes[$nodeIndex]); + $nodeOffset = $offset - $nodeStart; + if(fseek($stream, $nodeOffset) === -1) { + return false; + } + $this->currentNode = $nodeIndex; + $this->currentNodeRead = $nodeOffset; + $this->currentStream = $stream; + $this->pos = $offset; + + return true; } /** @@ -210,7 +244,7 @@ class AssemblyStream implements \Icewind\Streams\File { * * @param string $name * @return array - * @throws \Exception + * @throws \BadMethodCallException */ protected function loadContext($name) { $context = stream_context_get_options($this->context); |