From 9999e05660637c77947c71656d2f03d841e19ab9 Mon Sep 17 00:00:00 2001 From: Piotr Filiciak Date: Fri, 20 May 2016 18:16:44 +0200 Subject: Http Range requests support in downloads Http range requests support is required for video preview --- lib/private/Files/View.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lib/private/Files/View.php') diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 22e53a00706..136b2c2ac34 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -53,6 +53,7 @@ use OCP\Files\InvalidCharacterInPathException; use OCP\Files\InvalidPathException; use OCP\Files\NotFoundException; use OCP\Files\ReservedWordException; +use OCP\Files\UnseekableException; use OCP\Files\Storage\ILockingStorage; use OCP\IUser; use OCP\Lock\ILockingProvider; @@ -423,6 +424,39 @@ class View { return false; } + /** + * @param string $path + * @param int $from + * @param int $to + * @return bool|mixed + * @throws \OCP\Files\InvalidPathException, \OCP\Files\UnseekableException + */ + public function readfilePart($path, $from, $to) { + $this->assertPathLength($path); + @ob_end_clean(); + $handle = $this->fopen($path, 'rb'); + if ($handle) { + if (fseek($handle, $from) === 0) { + $chunkSize = 8192; // 8 kB chunks + $end = $to + 1; + while (!feof($handle) && ftell($handle) < $end) { + $len = $end-ftell($handle); + if ($len > $chunkSize) { + $len = $chunkSize; + } + echo fread($handle, $len); + flush(); + } + $size = ftell($handle) - $from; + return $size; + } + else { + throw new \OCP\Files\UnseekableException('fseek error'); + } + } + return false; + } + /** * @param string $path * @return mixed -- cgit v1.2.3