You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
2.9 KiB
138 lines
2.9 KiB
![]()
13 years ago
|
<?php
|
||
|
/**
|
||
|
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
|
||
|
* This file is licensed under the Affero General Public License version 3 or
|
||
|
* later.
|
||
|
* See the COPYING-README file.
|
||
|
*/
|
||
|
|
||
|
abstract class OC_Archive{
|
||
|
/**
|
||
![]()
12 years ago
|
* open any of the supported archive types
|
||
![]()
13 years ago
|
* @param string path
|
||
|
* @return OC_Archive
|
||
|
*/
|
||
![]()
13 years ago
|
public static function open($path) {
|
||
![]()
13 years ago
|
$ext=substr($path, strrpos($path, '.'));
|
||
![]()
13 years ago
|
switch($ext) {
|
||
![]()
13 years ago
|
case '.zip':
|
||
|
return new OC_Archive_ZIP($path);
|
||
![]()
13 years ago
|
case '.gz':
|
||
|
case '.bz':
|
||
|
case '.bz2':
|
||
![]()
13 years ago
|
if(strpos($path, '.tar.')) {
|
||
![]()
13 years ago
|
return new OC_Archive_TAR($path);
|
||
|
}
|
||
|
break;
|
||
|
case '.tgz':
|
||
|
return new OC_Archive_TAR($path);
|
||
![]()
13 years ago
|
}
|
||
|
}
|
||
![]()
13 years ago
|
|
||
![]()
13 years ago
|
abstract function __construct($source);
|
||
|
/**
|
||
|
* add an empty folder to the archive
|
||
|
* @param string path
|
||
|
* @return bool
|
||
|
*/
|
||
|
abstract function addFolder($path);
|
||
|
/**
|
||
|
* add a file to the archive
|
||
|
* @param string path
|
||
|
* @param string source either a local file or string data
|
||
|
* @return bool
|
||
|
*/
|
||
![]()
13 years ago
|
abstract function addFile($path, $source='');
|
||
![]()
13 years ago
|
/**
|
||
|
* rename a file or folder in the archive
|
||
|
* @param string source
|
||
|
* @param string dest
|
||
|
* @return bool
|
||
|
*/
|
||
![]()
13 years ago
|
abstract function rename($source, $dest);
|
||
![]()
13 years ago
|
/**
|
||
|
* get the uncompressed size of a file in the archive
|
||
|
* @param string path
|
||
|
* @return int
|
||
|
*/
|
||
|
abstract function filesize($path);
|
||
|
/**
|
||
|
* get the last modified time of a file in the archive
|
||
|
* @param string path
|
||
|
* @return int
|
||
|
*/
|
||
|
abstract function mtime($path);
|
||
|
/**
|
||
|
* get the files in a folder
|
||
|
* @param path
|
||
|
* @return array
|
||
|
*/
|
||
|
abstract function getFolder($path);
|
||
|
/**
|
||
![]()
12 years ago
|
* get all files in the archive
|
||
![]()
13 years ago
|
* @return array
|
||
|
*/
|
||
|
abstract function getFiles();
|
||
|
/**
|
||
|
* get the content of a file
|
||
|
* @param string path
|
||
|
* @return string
|
||
|
*/
|
||
|
abstract function getFile($path);
|
||
|
/**
|
||
|
* extract a single file from the archive
|
||
|
* @param string path
|
||
|
* @param string dest
|
||
|
* @return bool
|
||
|
*/
|
||
![]()
13 years ago
|
abstract function extractFile($path, $dest);
|
||
![]()
13 years ago
|
/**
|
||
|
* extract the archive
|
||
|
* @param string path
|
||
|
* @param string dest
|
||
|
* @return bool
|
||
|
*/
|
||
|
abstract function extract($dest);
|
||
![]()
13 years ago
|
/**
|
||
|
* check if a file or folder exists in the archive
|
||
|
* @param string path
|
||
|
* @return bool
|
||
|
*/
|
||
|
abstract function fileExists($path);
|
||
|
/**
|
||
|
* remove a file or folder from the archive
|
||
|
* @param string path
|
||
|
* @return bool
|
||
|
*/
|
||
|
abstract function remove($path);
|
||
|
/**
|
||
|
* get a file handler
|
||
|
* @param string path
|
||
|
* @param string mode
|
||
|
* @return resource
|
||
|
*/
|
||
![]()
13 years ago
|
abstract function getStream($path, $mode);
|
||
![]()
13 years ago
|
/**
|
||
![]()
12 years ago
|
* add a folder and all its content
|
||
![]()
13 years ago
|
* @param string $path
|
||
|
* @param string source
|
||
|
* @return bool
|
||
|
*/
|
||
![]()
13 years ago
|
function addRecursive($path, $source) {
|
||
![]()
12 years ago
|
$dh = opendir($source);
|
||
|
if(is_resource($dh)) {
|
||
![]()
13 years ago
|
$this->addFolder($path);
|
||
![]()
12 years ago
|
while (($file = readdir($dh)) !== false) {
|
||
![]()
13 years ago
|
if($file=='.' or $file=='..') {
|
||
![]()
13 years ago
|
continue;
|
||
|
}
|
||
![]()
13 years ago
|
if(is_dir($source.'/'.$file)) {
|
||
![]()
13 years ago
|
$this->addRecursive($path.'/'.$file, $source.'/'.$file);
|
||
![]()
13 years ago
|
}else{
|
||
![]()
13 years ago
|
$this->addFile($path.'/'.$file, $source.'/'.$file);
|
||
![]()
13 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
![]()
13 years ago
|
}
|