summaryrefslogtreecommitdiffstats
path: root/lib/private/Files
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-05-23 21:01:26 +0200
committerVincent Petry <pvince81@owncloud.com>2016-05-23 21:01:26 +0200
commitadcf942901fd567d97dbe105e8f3dfb7cea738e3 (patch)
tree3f3721d872941383689ba8ff661960d521af69c4 /lib/private/Files
parent5a8af2f0be87cada2827ee3b86d2900146a62f77 (diff)
parent6577bbe887840889e16634b9bf1c4ce247ec265e (diff)
downloadnextcloud-server-adcf942901fd567d97dbe105e8f3dfb7cea738e3.tar.gz
nextcloud-server-adcf942901fd567d97dbe105e8f3dfb7cea738e3.zip
Merge pull request #24750 from owncloud/lenz1111-share_download_range_requests_support
Http Range requests support in downloads
Diffstat (limited to 'lib/private/Files')
-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..27613903086 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
+ * @throws \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;
+ }
+
+ throw new \OCP\Files\UnseekableException('fseek error');
+ }
+ return false;
+ }
+
+ /**
+ * @param string $path
* @return mixed
*/
public function isCreatable($path) {