| @@ 23-81 (lines=59) @@ | ||
| 20 | use Graze\DataFile\Node\LocalFileNodeInterface; |
|
| 21 | use Psr\Log\LoggerAwareInterface; |
|
| 22 | ||
| 23 | class Gzip implements |
|
| 24 | CompressionTypeInterface, |
|
| 25 | CompressorInterface, |
|
| 26 | DeCompressorInterface, |
|
| 27 | LoggerAwareInterface, |
|
| 28 | ProcessFactoryAwareInterface |
|
| 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 | public function getExtension() |
|
| 44 | { |
|
| 45 | return 'gz'; |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @return string |
|
| 50 | */ |
|
| 51 | public function getName() |
|
| 52 | { |
|
| 53 | 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 | public function getCompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
| 65 | { |
|
| 66 | 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 | public function getDecompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
| 78 | { |
|
| 79 | return sprintf("gunzip -c %s > %s", escapeshellarg($from->getPath()), escapeshellarg($to->getPath())); |
|
| 80 | } |
|
| 81 | } |
|
| 82 | ||
| @@ 23-82 (lines=60) @@ | ||
| 20 | use Graze\DataFile\Node\LocalFileNodeInterface; |
|
| 21 | use Psr\Log\LoggerAwareInterface; |
|
| 22 | ||
| 23 | class Zip implements |
|
| 24 | CompressionTypeInterface, |
|
| 25 | CompressorInterface, |
|
| 26 | DeCompressorInterface, |
|
| 27 | LoggerAwareInterface, |
|
| 28 | ProcessFactoryAwareInterface |
|
| 29 | { |
|
| 30 | use GetOptionTrait; |
|
| 31 | use FileProcessTrait; |
|
| 32 | use OptionalLoggerTrait; |
|
| 33 | use CompressorTrait; |
|
| 34 | use DeCompressorTrait; |
|
| 35 | ||
| 36 | const NAME = 'zip'; |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Get the extension used by this compressor |
|
| 40 | * |
|
| 41 | * @return string |
|
| 42 | */ |
|
| 43 | public function getExtension() |
|
| 44 | { |
|
| 45 | return 'zip'; |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @return string |
|
| 50 | */ |
|
| 51 | public function getName() |
|
| 52 | { |
|
| 53 | 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 | public function getCompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
| 65 | { |
|
| 66 | return sprintf("zip %s %s", escapeshellarg($to->getPath()), escapeshellarg($from->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 | */ |
|
| 78 | public function getDecompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
| 79 | { |
|
| 80 | return sprintf("unzip -p %s > %s", escapeshellarg($from->getPath()), escapeshellarg($to->getPath())); |
|
| 81 | } |
|
| 82 | } |
|
| 83 | ||