1
|
|
|
<?php |
2
|
|
|
namespace wapmorgan\UnifiedArchive\Drivers\OneFile; |
3
|
|
|
|
4
|
|
|
use wapmorgan\UnifiedArchive\Formats; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Lzma |
8
|
|
|
* |
9
|
|
|
* @package wapmorgan\UnifiedArchive\Formats |
10
|
|
|
* @requires ext-lzma2 |
11
|
|
|
* @link https://github.com/payden/php-xz |
12
|
|
|
* @link https://github.com/codemasher/php-ext-xz |
13
|
|
|
*/ |
14
|
|
|
class Lzma extends OneFileDriver |
15
|
|
|
{ |
16
|
|
|
const EXTENSION_NAME = 'xz'; |
17
|
|
|
const FORMAT = Formats::LZMA; |
18
|
|
|
|
19
|
|
|
/** |
20
|
1 |
|
* @inheritDoc |
21
|
|
|
*/ |
22
|
|
|
public static function getDescription() |
23
|
1 |
|
{ |
24
|
|
|
return 'adapter for ext-xz'.(static::isInstalled() ? ' ('.phpversion(static::EXTENSION_NAME).')' : null); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritDoc |
29
|
|
|
*/ |
30
|
|
|
public static function getInstallationInstruction() |
31
|
|
|
{ |
32
|
|
|
return 'install [' . static::EXTENSION_NAME . '] extension' . "\n" . 'For 5.x: https://github.com/payden/php-xz' . "\n" . 'For 7.x/8.x: https://github.com/codemasher/php-ext-xz'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritDoc |
37
|
|
|
*/ |
38
|
|
|
public function __construct($archiveFileName, $format, $password = null) |
39
|
|
|
{ |
40
|
|
|
parent::__construct($archiveFileName, $format, $password); |
41
|
|
|
$this->modificationTime = filemtime($this->fileName); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $fileName |
46
|
|
|
* |
47
|
|
|
* @return string|false |
48
|
|
|
*/ |
49
|
|
|
public function getFileContent($fileName = null) |
50
|
|
|
{ |
51
|
|
|
return stream_get_contents(xzopen($this->fileName, 'r')); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $fileName |
56
|
|
|
* |
57
|
|
|
* @return bool|resource|string |
58
|
|
|
*/ |
59
|
|
|
public function getFileStream($fileName = null) |
60
|
|
|
{ |
61
|
|
|
return xzopen($this->fileName, 'r'); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param $data |
66
|
|
|
* @param $compressionLevel |
67
|
|
|
* @return mixed|string |
68
|
|
|
*/ |
69
|
|
|
protected static function compressData($data, $compressionLevel) |
70
|
|
|
{ |
71
|
|
|
return xzencode($data); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|