Skip to content

Commit

Permalink
Merge pull request #28909 from nextcloud/backport/28802/stable21
Browse files Browse the repository at this point in the history
[stable21] Support seeking also from the end of file on S3 storage
  • Loading branch information
MichaIng authored Sep 21, 2021
2 parents 1ede2d5 + 61acaf1 commit 0365d3b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/private/Files/Stream/SeekableHttpStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public static function open(callable $callback) {
private $current;
/** @var int */
private $offset = 0;
/** @var int */
private $length = 0;

private function reconnect(int $start) {
$range = $start . '-';
Expand All @@ -102,12 +104,14 @@ private function reconnect(int $start) {
$content = trim(explode(':', $contentRange)[1]);
$range = trim(explode(' ', $content)[1]);
$begin = intval(explode('-', $range)[0]);
$length = intval(explode('/', $range)[1]);

if ($begin !== $start) {
return false;
}

$this->offset = $begin;
$this->length = $length;

return true;
}
Expand Down Expand Up @@ -141,7 +145,12 @@ public function stream_seek($offset, $whence = SEEK_SET) {
}
return $this->reconnect($this->offset + $offset);
case SEEK_END:
return false;
if ($this->length === 0) {
return false;
} elseif ($this->length + $offset === $this->offset) {
return true;
}
return $this->reconnect($this->length + $offset);
}
return false;
}
Expand Down

0 comments on commit 0365d3b

Please sign in to comment.