| @@ 12-70 (lines=59) @@ | ||
| 9 | use Graze\DataFile\Node\LocalFileNodeInterface; |
|
| 10 | use Psr\Log\LoggerAwareInterface; |
|
| 11 | ||
| 12 | class Gzip implements |
|
| 13 | CompressionTypeInterface, |
|
| 14 | CompressorInterface, |
|
| 15 | DeCompressorInterface, |
|
| 16 | LoggerAwareInterface, |
|
| 17 | ProcessFactoryAwareInterface |
|
| 18 | { |
|
| 19 | use GetOptionTrait; |
|
| 20 | use FileProcessTrait; |
|
| 21 | use OptionalLoggerTrait; |
|
| 22 | use CompressorTrait; |
|
| 23 | use DeCompressorTrait; |
|
| 24 | ||
| 25 | const NAME = 'gzip'; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * Get the extension used by this compressor |
|
| 29 | * |
|
| 30 | * @return string |
|
| 31 | */ |
|
| 32 | public function getExtension() |
|
| 33 | { |
|
| 34 | return 'gz'; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @return string |
|
| 39 | */ |
|
| 40 | public function getName() |
|
| 41 | { |
|
| 42 | return static::NAME; |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * Get the command line to compress a file |
|
| 47 | * |
|
| 48 | * @param LocalFileNodeInterface $from |
|
| 49 | * @param LocalFileNodeInterface $to |
|
| 50 | * |
|
| 51 | * @return string |
|
| 52 | */ |
|
| 53 | public function getCompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
| 54 | { |
|
| 55 | return sprintf("gzip -c %s > %s", escapeshellarg($from->getPath()), escapeshellarg($to->getPath())); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Get the command line to decompress a file |
|
| 60 | * |
|
| 61 | * @param LocalFileNodeInterface $from |
|
| 62 | * @param LocalFileNodeInterface $to |
|
| 63 | * |
|
| 64 | * @return string |
|
| 65 | */ |
|
| 66 | public function getDecompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
| 67 | { |
|
| 68 | return sprintf("gunzip -c %s > %s", escapeshellarg($from->getPath()), escapeshellarg($to->getPath())); |
|
| 69 | } |
|
| 70 | } |
|
| 71 | ||
| @@ 12-71 (lines=60) @@ | ||
| 9 | use Graze\DataFile\Node\LocalFileNodeInterface; |
|
| 10 | use Psr\Log\LoggerAwareInterface; |
|
| 11 | ||
| 12 | class Zip implements |
|
| 13 | CompressionTypeInterface, |
|
| 14 | CompressorInterface, |
|
| 15 | DeCompressorInterface, |
|
| 16 | LoggerAwareInterface, |
|
| 17 | ProcessFactoryAwareInterface |
|
| 18 | { |
|
| 19 | use GetOptionTrait; |
|
| 20 | use FileProcessTrait; |
|
| 21 | use OptionalLoggerTrait; |
|
| 22 | use CompressorTrait; |
|
| 23 | use DeCompressorTrait; |
|
| 24 | ||
| 25 | const NAME = 'zip'; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * Get the extension used by this compressor |
|
| 29 | * |
|
| 30 | * @return string |
|
| 31 | */ |
|
| 32 | public function getExtension() |
|
| 33 | { |
|
| 34 | return 'zip'; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @return string |
|
| 39 | */ |
|
| 40 | public function getName() |
|
| 41 | { |
|
| 42 | return static::NAME; |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * Get the command line to compress a file |
|
| 47 | * |
|
| 48 | * @param LocalFileNodeInterface $from |
|
| 49 | * @param LocalFileNodeInterface $to |
|
| 50 | * |
|
| 51 | * @return string |
|
| 52 | */ |
|
| 53 | public function getCompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
| 54 | { |
|
| 55 | return sprintf("zip %s %s", escapeshellarg($to->getPath()), escapeshellarg($from->getPath())); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Get the command line to decompress a file |
|
| 60 | * |
|
| 61 | * @param LocalFileNodeInterface $from |
|
| 62 | * @param LocalFileNodeInterface $to |
|
| 63 | * |
|
| 64 | * @return string |
|
| 65 | * |
|
| 66 | */ |
|
| 67 | public function getDecompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
| 68 | { |
|
| 69 | return sprintf("unzip -p %s > %s", escapeshellarg($from->getPath()), escapeshellarg($to->getPath())); |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||