diff options
Diffstat (limited to 'lib/archive/zip.php')
-rw-r--r-- | lib/archive/zip.php | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/lib/archive/zip.php b/lib/archive/zip.php index 396b1f6c054..45992ee3d89 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -13,10 +13,10 @@ class OC_Archive_ZIP extends OC_Archive{ private $zip=null; private $path; - function __construct($source){ + function __construct($source) { $this->path=$source; $this->zip=new ZipArchive(); - if($this->zip->open($source,ZipArchive::CREATE)){ + if($this->zip->open($source,ZipArchive::CREATE)) { }else{ OCP\Util::writeLog('files_archive','Error while opening archive '.$source,OCP\Util::WARN); } @@ -26,7 +26,7 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string path * @return bool */ - function addFolder($path){ + function addFolder($path) { return $this->zip->addEmptyDir($path); } /** @@ -35,13 +35,13 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string source either a local file or string data * @return bool */ - function addFile($path,$source=''){ - if($source and $source[0]=='/' and file_exists($source)){ + function addFile($path,$source='') { + if($source and $source[0]=='/' and file_exists($source)) { $result=$this->zip->addFile($source,$path); }else{ $result=$this->zip->addFromString($path,$source); } - if($result){ + if($result) { $this->zip->close();//close and reopen to save the zip $this->zip->open($this->path); } @@ -53,7 +53,7 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string dest * @return bool */ - function rename($source,$dest){ + function rename($source,$dest) { $source=$this->stripPath($source); $dest=$this->stripPath($dest); $this->zip->renameName($source,$dest); @@ -63,7 +63,7 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string path * @return int */ - function filesize($path){ + function filesize($path) { $stat=$this->zip->statName($path); return $stat['size']; } @@ -72,7 +72,7 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string path * @return int */ - function mtime($path){ + function mtime($path) { return filemtime($this->path); } /** @@ -80,13 +80,13 @@ class OC_Archive_ZIP extends OC_Archive{ * @param path * @return array */ - function getFolder($path){ + function getFolder($path) { $files=$this->getFiles(); $folderContent=array(); $pathLength=strlen($path); - foreach($files as $file){ - if(substr($file,0,$pathLength)==$path and $file!=$path){ - if(strrpos(substr($file,0,-1),'/')<=$pathLength){ + foreach($files as $file) { + if(substr($file,0,$pathLength)==$path and $file!=$path) { + if(strrpos(substr($file,0,-1),'/')<=$pathLength) { $folderContent[]=substr($file,$pathLength); } } @@ -97,10 +97,10 @@ class OC_Archive_ZIP extends OC_Archive{ *get all files in the archive * @return array */ - function getFiles(){ + function getFiles() { $fileCount=$this->zip->numFiles; $files=array(); - for($i=0;$i<$fileCount;$i++){ + for($i=0;$i<$fileCount;$i++) { $files[]=$this->zip->getNameIndex($i); } return $files; @@ -110,7 +110,7 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string path * @return string */ - function getFile($path){ + function getFile($path) { return $this->zip->getFromName($path); } /** @@ -119,7 +119,7 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string dest * @return bool */ - function extractFile($path,$dest){ + function extractFile($path,$dest) { $fp = $this->zip->getStream($path); file_put_contents($dest,$fp); } @@ -129,7 +129,7 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string dest * @return bool */ - function extract($dest){ + function extract($dest) { return $this->zip->extractTo($dest); } /** @@ -137,7 +137,7 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string path * @return bool */ - function fileExists($path){ + function fileExists($path) { return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false); } /** @@ -145,8 +145,8 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string path * @return bool */ - function remove($path){ - if($this->fileExists($path.'/')){ + function remove($path) { + if($this->fileExists($path.'/')) { return $this->zip->deleteName($path.'/'); }else{ return $this->zip->deleteName($path); @@ -158,18 +158,18 @@ class OC_Archive_ZIP extends OC_Archive{ * @param string mode * @return resource */ - function getStream($path,$mode){ - if($mode=='r' or $mode=='rb'){ + function getStream($path,$mode) { + if($mode=='r' or $mode=='rb') { return $this->zip->getStream($path); }else{//since we cant directly get a writable stream, make a temp copy of the file and put it back in the archive when the stream is closed - if(strrpos($path,'.')!==false){ + if(strrpos($path,'.')!==false) { $ext=substr($path,strrpos($path,'.')); }else{ $ext=''; } $tmpFile=OCP\Files::tmpFile($ext); OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack'); - if($this->fileExists($path)){ + if($this->fileExists($path)) { $this->extractFile($path,$tmpFile); } self::$tempFiles[$tmpFile]=$path; @@ -181,15 +181,15 @@ class OC_Archive_ZIP extends OC_Archive{ /** * write back temporary files */ - function writeBack($tmpFile){ - if(isset(self::$tempFiles[$tmpFile])){ + function writeBack($tmpFile) { + if(isset(self::$tempFiles[$tmpFile])) { $this->addFile(self::$tempFiles[$tmpFile],$tmpFile); unlink($tmpFile); } } - private function stripPath($path){ - if(!$path || $path[0]=='/'){ + private function stripPath($path) { + if(!$path || $path[0]=='/') { return substr($path,1); }else{ return $path; |