summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/View.php
diff options
context:
space:
mode:
authorPiotr Filiciak <piotr@filiciak.pl>2016-05-20 18:16:44 +0200
committerVincent Petry <pvince81@owncloud.com>2016-05-20 18:16:44 +0200
commit9999e05660637c77947c71656d2f03d841e19ab9 (patch)
tree3eac375c092a2013e7d9fdb6be8d0f74d298defd /lib/private/Files/View.php
parent59a85a4c76b80658d9373e3acf4f71b872b244a0 (diff)
downloadnextcloud-server-9999e05660637c77947c71656d2f03d841e19ab9.tar.gz
nextcloud-server-9999e05660637c77947c71656d2f03d841e19ab9.zip
Http Range requests support in downloads
Http range requests support is required for video preview
Diffstat (limited to 'lib/private/Files/View.php')
-rw-r--r--lib/private/Files/View.php34
1 files changed, 34 insertions, 0 deletions
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;
@@ -425,6 +426,39 @@ class View {
/**
* @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
*/
public function isCreatable($path) {