chunked implementation for readfile

prevents memory issues when downloading large files
This commit is contained in:
Robin Appelman 2012-02-26 03:54:21 +01:00
parent 0b19af5e10
commit c8c3b8a63e
5 changed files with 8 additions and 21 deletions

View File

@ -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;

View File

@ -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){}

View File

@ -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);
}

View File

@ -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'];

View File

@ -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);