Skip to content

Commit

Permalink
Add zx compression - issue #93
Browse files Browse the repository at this point in the history
You can now choose 'xz' for your target compression.
For this to work you must have the 'xz' binary installed
and available in your path.

To install the xz compressor you can do something like:
  Debian: apt-get install xz-utils
  OSX:    brew install xz
  • Loading branch information
sebastianfeldmann committed Apr 21, 2017
1 parent 3b41f9e commit da08c3c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Backup/Target/Compression/Factory.php
Expand Up @@ -24,6 +24,7 @@ class Factory
protected static $availableCompressors = [
'gzip' => 'Gzip',
'bzip2' => 'Bzip2',
'xz' => 'Xz',
'zip' => 'Zip'
];

Expand Down
44 changes: 44 additions & 0 deletions src/Backup/Target/Compression/Xz.php
@@ -0,0 +1,44 @@
<?php
namespace phpbu\App\Backup\Target\Compression;

/**
* Xz
*
* @package phpbu
* @subpackage Backup
* @author Sebastian Feldmann <sebastian@phpbu.de>
* @copyright Sebastian Feldmann <sebastian@phpbu.de>
* @license https://opensource.org/licenses/MIT The MIT License (MIT)
* @link http://phpbu.de/
* @since Class available since Release 5.0.0
*/
class Xz extends Abstraction
{
/**
* Command name
*
* @var string
*/
protected $cmd = 'xz';

/**
* Suffix for compressed files
*
* @var string
*/
protected $suffix = 'xz';

/**
* MIME type for compressed files
*
* @var string
*/
protected $mimeType = 'application/x-xz';

/**
* Can this compression compress piped output
*
* @var bool
*/
protected $pipeable = true;
}
1 change: 1 addition & 0 deletions src/Cli/Executable/Tar.php
Expand Up @@ -79,6 +79,7 @@ class Tar extends Abstraction implements Executable
private static $availableCompressions = [
'bzip2' => 'j',
'gzip' => 'z',
'xz' => 'J'
];

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/phpbu/Backup/Target/CompressionTest.php
Expand Up @@ -47,6 +47,17 @@ public function testBzip2()
$this->assertEquals('application/x-bzip2', $gzip->getMimeType());
}

/**
* Test xz compressor
*/
public function testXz()
{
$gzip = Compression\Factory::create('xz');
$this->assertEquals('xz', $gzip->getSuffix());
$this->assertEquals('xz', $gzip->getCommand());
$this->assertEquals('application/x-xz', $gzip->getMimeType());
}

/**
* Test Compression::isPipeable
*/
Expand All @@ -58,6 +69,9 @@ public function testIsPipeable()
$bzip = Compression\Factory::create('bzip2');
$this->assertTrue($bzip->isPipeable());

$xz = Compression\Factory::create('xz');
$this->assertTrue($bzip->isPipeable());

$zip = Compression\Factory::create('zip');
$this->assertFalse($zip->isPipeable());
}
Expand Down

0 comments on commit da08c3c

Please sign in to comment.