1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/data-file |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/data-file/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/data-file |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\DataFile\Modify\Compress; |
15
|
|
|
|
16
|
|
|
use Graze\DataFile\Helper\Builder\BuilderAwareInterface; |
17
|
|
|
use Graze\DataFile\Helper\GetOptionTrait; |
18
|
|
|
use Graze\DataFile\Helper\OptionalLoggerTrait; |
19
|
|
|
use Graze\DataFile\Modify\FileProcessTrait; |
20
|
|
|
use Graze\DataFile\Node\LocalFileNodeInterface; |
21
|
|
|
use Psr\Log\LoggerAwareInterface; |
22
|
|
|
|
23
|
|
View Code Duplication |
class Gzip implements |
|
|
|
|
24
|
|
|
CompressionTypeInterface, |
25
|
|
|
CompressorInterface, |
26
|
|
|
DeCompressorInterface, |
27
|
|
|
LoggerAwareInterface, |
28
|
|
|
BuilderAwareInterface |
29
|
|
|
{ |
30
|
|
|
use GetOptionTrait; |
31
|
|
|
use FileProcessTrait; |
32
|
|
|
use OptionalLoggerTrait; |
33
|
|
|
use CompressorTrait; |
34
|
|
|
use DeCompressorTrait; |
35
|
|
|
|
36
|
|
|
const NAME = 'gzip'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get the extension used by this compressor |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
11 |
|
public function getExtension() |
44
|
|
|
{ |
45
|
11 |
|
return 'gz'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
21 |
|
public function getName() |
52
|
|
|
{ |
53
|
21 |
|
return static::NAME; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the command line to compress a file |
58
|
|
|
* |
59
|
|
|
* @param LocalFileNodeInterface $from |
60
|
|
|
* @param LocalFileNodeInterface $to |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
11 |
|
public function getCompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
65
|
|
|
{ |
66
|
11 |
|
return sprintf("gzip -c %s > %s", escapeshellarg($from->getPath()), escapeshellarg($to->getPath())); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get the command line to decompress a file |
71
|
|
|
* |
72
|
|
|
* @param LocalFileNodeInterface $from |
73
|
|
|
* @param LocalFileNodeInterface $to |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
6 |
|
public function getDecompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
78
|
|
|
{ |
79
|
6 |
|
return sprintf("gunzip -c %s > %s", escapeshellarg($from->getPath()), escapeshellarg($to->getPath())); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.