Skip to content

Commit f99b048

Browse files
authored
Merge pull request #28908 from nextcloud/backport/28802/stable20
[stable20] Support seeking also from the end of file on S3 storage
2 parents 49157ca + 50729e2 commit f99b048

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/private/Files/Stream/SeekableHttpStream.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public static function open(callable $callback) {
7777
private $current;
7878
/** @var int */
7979
private $offset = 0;
80+
/** @var int */
81+
private $length = 0;
8082

8183
private function reconnect(int $start) {
8284
$range = $start . '-';
@@ -102,12 +104,14 @@ private function reconnect(int $start) {
102104
$content = trim(explode(':', $contentRange)[1]);
103105
$range = trim(explode(' ', $content)[1]);
104106
$begin = intval(explode('-', $range)[0]);
107+
$length = intval(explode('/', $range)[1]);
105108

106109
if ($begin !== $start) {
107110
return false;
108111
}
109112

110113
$this->offset = $begin;
114+
$this->length = $length;
111115

112116
return true;
113117
}
@@ -141,7 +145,12 @@ public function stream_seek($offset, $whence = SEEK_SET) {
141145
}
142146
return $this->reconnect($this->offset + $offset);
143147
case SEEK_END:
144-
return false;
148+
if ($this->length === 0) {
149+
return false;
150+
} elseif ($this->length + $offset === $this->offset) {
151+
return true;
152+
}
153+
return $this->reconnect($this->length + $offset);
145154
}
146155
return false;
147156
}

0 commit comments

Comments
 (0)