123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- class ArchiverTar implements ArchiverInterface {
-
- protected $tar;
- public function __construct($file_path) {
- $this->tar = new Archive_Tar($file_path);
- }
- public function add($file_path) {
- $this->tar->add($file_path);
- return $this;
- }
- public function remove($file_path) {
-
-
-
-
- return $this;
- }
- public function extract($path, Array $files = array()) {
- if ($files) {
- $this->tar->extractList($files, $path);
- }
- else {
- $this->tar->extract($path);
- }
- return $this;
- }
- public function listContents() {
- $files = array();
- foreach ($this->tar->listContent() as $file_data) {
- $files[] = $file_data['filename'];
- }
- return $files;
- }
-
- public function getArchive() {
- return $this->tar;
- }
- }
- class ArchiverZip implements ArchiverInterface {
-
- protected $zip;
- public function __construct($file_path) {
- $this->zip = new ZipArchive();
- if ($this->zip->open($file_path) !== TRUE) {
-
- throw new Exception(t('Cannot open %file_path', array('%file_path' => $file_path)));
- }
- }
- public function add($file_path) {
- $this->zip->addFile($file_path);
- return $this;
- }
- public function remove($file_path) {
- $this->zip->deleteName($file_path);
- return $this;
- }
- public function extract($path, Array $files = array()) {
- if ($files) {
- $this->zip->extractTo($path, $files);
- }
- else {
- $this->zip->extractTo($path);
- }
- return $this;
- }
- public function listContents() {
- $files = array();
- for ($i=0; $i < $this->zip->numFiles; $i++) {
- $files[] = $this->zip->getNameIndex($i);
- }
- return $files;
- }
-
- public function getArchive() {
- return $this->zip;
- }
- }
|