Merge pull request #7082 from nextcloud/12-6974

[stable12] Fix seeking on object storage
This commit is contained in:
Morris Jobke 2017-11-06 20:21:35 +01:00 committed by GitHub
commit 3cc7c03ddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 2 deletions

View File

@ -456,8 +456,28 @@ class View {
@ob_end_clean();
$handle = $this->fopen($path, 'rb');
if ($handle) {
if (fseek($handle, $from) === 0) {
$chunkSize = 8192; // 8 kB chunks
$chunkSize = 8192; // 8 kB chunks
$startReading = true;
if ($from !== 0 && $from !== '0' && fseek($handle, $from) !== 0) {
// forward file handle via chunked fread because fseek seem to have failed
$end = $from + 1;
while (!feof($handle) && ftell($handle) < $end) {
$len = $from - ftell($handle);
if ($len > $chunkSize) {
$len = $chunkSize;
}
$result = fread($handle, $len);
if ($result === false) {
$startReading = false;
break;
}
}
}
if ($startReading) {
$end = $to + 1;
while (!feof($handle) && ftell($handle) < $end) {
$len = $end - ftell($handle);