Skip to content

Commit

Permalink
Flush last output buffer after fclose in readfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Nov 28, 2016
1 parent c075d3d commit 4a8ba08
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,14 @@ public function readfile($path) {
\OCP\Util::writeLog('DEBUG', 'readfile: before loop', \OCP\Util::DEBUG);
while (!feof($handle)) {
echo fread($handle, $chunkSize);
flush();
// keep the last flush for after fclose
if (!feof($handle)) {
flush();
}
}
\OCP\Util::writeLog('DEBUG', 'readfile: after loop, preparing to fclose', \OCP\Util::DEBUG);
fclose($handle);
flush();
\OCP\Util::writeLog('DEBUG', 'readfile: fclose called', \OCP\Util::DEBUG);
$size = $this->filesize($path);
\OCP\Util::writeLog('DEBUG', 'readfile: got filesize: ' . $size, \OCP\Util::DEBUG);
Expand Down Expand Up @@ -468,12 +472,16 @@ public function readfilePart($path, $from, $to) {
$len = $chunkSize;
}
echo fread($handle, $len);
flush();
// keep the last flush for after fclose
if (!feof($handle)) {
flush();
}
}
\OCP\Util::writeLog('DEBUG', 'readfilePart: after loop', \OCP\Util::DEBUG);
$size = ftell($handle) - $from;
\OCP\Util::writeLog('DEBUG', 'readfilePart: preparing to fclose', \OCP\Util::DEBUG);
fclose($handle);
flush();
\OCP\Util::writeLog('DEBUG', 'readfile: fclose called', \OCP\Util::DEBUG);
return $size;
}
Expand Down

0 comments on commit 4a8ba08

Please sign in to comment.