RarArchiveReader.php 889 Bytes
<?php
/**
 * Created by PhpStorm.
 * User: Tsurkanov
 * Date: 03.11.2015
 * Time: 15:12
 */

namespace common\components\archives;


class RarArchiveReader extends  ArchiveReader {

    protected $resource;
    public  function open( $file, $password = '' ){

        $this->resource = rar_open( $file, $password );
        if ($this->resource === FALSE)
            throw new \Exception("Failed opening rar file");
    }

    public  function extractTo( $destination){
        $list = rar_list($this->resource);

        foreach($list as $file) {
            $entry = rar_entry_get($this->resource, $file);
            $entry->extract($destination);

            $this->setExtractedFiles($entry->getName(), pathinfo($entry->getName(), PATHINFO_EXTENSION));

        }

        rar_close($this->resource);
    }
    public static  function getExtension(){
        return 'rar';
    }




}