Files
2026-07-01 16:44:17 +03:00

112 lines
2.2 KiB
PHP

<?php namespace ZN\Compression\Drivers;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Base;
use ZN\Support;
use ZN\Singleton;
use ZN\Compression\DriverMappingAbstract;
/**
* @codeCoverageIgnore
*/
class RarDriver extends DriverMappingAbstract
{
/**
* Magic constructor
*
* Checking if your driver is supported.
*
* @param void
*
* @return void
*/
public function __construct()
{
Support::func('rar_open', 'RAR');
}
/**
* Extract data
*
* @param string $source
* @param string $target = NULL
* @param string $password = NULL
*
* @return bool
*/
public function extract($source, $target, $password)
{
$rarFile = rar_open(Base::suffix($source, '.rar'), $password);
$list = rar_list($rarFile);
if( ! empty($list) ) foreach( $list as $file )
{
$entry = rar_entry_get($rarFile, $file);
$entry->extract($target);
}
else
{
return false;
}
rar_close($rarFile);
}
/**
* Write data to file
*
* @param string $file
* @param string $data
*
* @return bool
*/
public function write($file, $data)
{
return Singleton::class('ZN\Compression\Drivers\GzDriver')->write($file, $data);
}
/**
* Read file
*
* @param string $file
*
* @return bool
*/
public function read($file)
{
return Singleton::class('ZN\Compression\Drivers\GzDriver')->read($file);
}
/**
* Force do
*
* @param string $data
*
* @return string
*/
public function do($data)
{
return Singleton::class('ZN\Compression\Drivers\GzDriver')->do($data);
}
/**
* Force undo
*
* @param string $data
*
* @return string
*/
public function undo($data)
{
return Singleton::class('ZN\Compression\Drivers\GzDriver')->undo($data);
}
}