Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support seeking also from the end of file on S3 storage #28802

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/private/Files/Stream/SeekableHttpStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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 @@ -101,12 +103,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 @@ -140,7 +144,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