aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-02-26 03:54:21 +0100
committerRobin Appelman <icewind@owncloud.com>2012-02-26 03:54:21 +0100
commitc8c3b8a63ea1c4763e1a5197487f0ae3506339c1 (patch)
tree681345340a80215eb1e26403f2605d01536fd1bb
parent0b19af5e10ea83400e114c8b2d4252fb8d50cc33 (diff)
downloadnextcloud-server-c8c3b8a63ea1c4763e1a5197487f0ae3506339c1.tar.gz
nextcloud-server-c8c3b8a63ea1c4763e1a5197487f0ae3506339c1.zip
chunked implementation for readfile
prevents memory issues when downloading large files
-rw-r--r--apps/files_sharing/sharedstorage.php8
-rw-r--r--lib/filestorage.php1
-rw-r--r--lib/filestorage/local.php3
-rw-r--r--lib/filestoragecommon.php8
-rw-r--r--lib/filesystemview.php9
5 files changed, 8 insertions, 21 deletions
diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
index cb641e68a84..0e110da30b1 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -281,14 +281,6 @@ class OC_Filestorage_Shared extends OC_Filestorage {
}
}
- public function readfile($path) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->readfile($this->getInternalPath($source));
- }
- }
-
public function filectime($path) {
if ($path == "" || $path == "/") {
$ctime = 0;
diff --git a/lib/filestorage.php b/lib/filestorage.php
index 4523144f6f4..989f5b311f3 100644
--- a/lib/filestorage.php
+++ b/lib/filestorage.php
@@ -36,7 +36,6 @@ class OC_Filestorage{
public function is_readable($path){}
public function is_writable($path){}
public function file_exists($path){}
- public function readfile($path){}
public function filectime($path){}
public function filemtime($path){}
public function file_get_contents($path){}
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index dcb516a3afb..243fdd3ba6b 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -52,9 +52,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
public function file_exists($path){
return file_exists($this->datadir.$path);
}
- public function readfile($path){
- return readfile($this->datadir.$path);
- }
public function filectime($path){
return filectime($this->datadir.$path);
}
diff --git a/lib/filestoragecommon.php b/lib/filestoragecommon.php
index f522d15c4e9..45ad11fcde8 100644
--- a/lib/filestoragecommon.php
+++ b/lib/filestoragecommon.php
@@ -37,14 +37,6 @@ class OC_Filestorage_Common extends OC_Filestorage {
public function is_readable($path){}
public function is_writable($path){}
public function file_exists($path){}
- public function readfile($path) {
- $handle = $this->fopen($path, "r");
- $chunk = 1024;
- while (!feof($handle)) {
- echo fread($handle, $chunk);
- }
- return $this->filesize($path);
- }
public function filectime($path) {
$stat = $this->stat($path);
return $stat['ctime'];
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
index 91c6cd17720..ab254cc512f 100644
--- a/lib/filesystemview.php
+++ b/lib/filesystemview.php
@@ -136,7 +136,14 @@ class OC_FilesystemView {
return $this->basicOperation('filesize',$path);
}
public function readfile($path){
- return $this->basicOperation('readfile',$path,array('read'));
+ $handle=$this->fopen($path,'r');
+ $chunkSize = 1024*1024;// 1 MB chunks
+ while (!feof($handle)) {
+ echo fread($handle, $chunkSize);
+ @ob_flush();
+ flush();
+ }
+ return $this->filesize($path);
}
public function is_readable($path){
return $this->basicOperation('is_readable',$path);