mirror of
https://github.com/splitbrain/php-archive.git
synced 2025-01-17 13:38:26 +01:00
Merge branch 'master' into magicbytes
* master: added compression example to README fixed various calls in the tests fixed compression setting on saving inmemory tars
This commit is contained in:
commit
1ae8687e13
@ -54,12 +54,13 @@ $tar->close();
|
|||||||
// To create a TAR archive directly in memory, create() it, add*()
|
// To create a TAR archive directly in memory, create() it, add*()
|
||||||
// files and then either save() or getArchive() it:
|
// files and then either save() or getArchive() it:
|
||||||
$tar = new Tar();
|
$tar = new Tar();
|
||||||
|
$tar->setCompression(9, Archive::COMPRESS_BZIP);
|
||||||
$tar->create();
|
$tar->create();
|
||||||
$tar->addFile(...);
|
$tar->addFile(...);
|
||||||
$tar->addData(...);
|
$tar->addData(...);
|
||||||
...
|
...
|
||||||
$tar->save('myfile.tgz'); // compresses and saves it
|
$tar->save('myfile.tbz'); // compresses and saves it
|
||||||
echo $tar->getArchive(Archive::COMPRESS_GZIP); // compresses and returns it
|
echo $tar->getArchive(); // compresses and returns it
|
||||||
```
|
```
|
||||||
|
|
||||||
Differences between Tar and Zip: Tars are compressed as a whole, while Zips compress each file individually. Therefore
|
Differences between Tar and Zip: Tars are compressed as a whole, while Zips compress each file individually. Therefore
|
||||||
|
@ -36,6 +36,8 @@ class Tar extends Archive
|
|||||||
$this->compressioncheck($type);
|
$this->compressioncheck($type);
|
||||||
$this->comptype = $type;
|
$this->comptype = $type;
|
||||||
$this->complevel = $level;
|
$this->complevel = $level;
|
||||||
|
if($level == 0) $this->comptype = Archive::COMPRESS_NONE;
|
||||||
|
if($type == Archive::COMPRESS_NONE) $this->complevel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -366,7 +368,7 @@ class Tar extends Archive
|
|||||||
public function save($file)
|
public function save($file)
|
||||||
{
|
{
|
||||||
if ($this->comptype === Archive::COMPRESS_AUTO) {
|
if ($this->comptype === Archive::COMPRESS_AUTO) {
|
||||||
$this->setCompression($this->filetype($this->complevel, $file));
|
$this->setCompression($this->complevel, $this->filetype($file));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_put_contents($file, $this->getArchive())) {
|
if (!file_put_contents($file, $this->getArchive())) {
|
||||||
|
@ -101,7 +101,7 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
$tdir = ltrim($dir, '/');
|
$tdir = ltrim($dir, '/');
|
||||||
$tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
|
$tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
|
||||||
|
|
||||||
$tar->create($tmp, Tar::COMPRESS_NONE);
|
$tar->create($tmp);
|
||||||
$tar->AddFile("$dir/testdata1.txt");
|
$tar->AddFile("$dir/testdata1.txt");
|
||||||
$tar->AddFile("$dir/foobar/testdata2.txt", 'noway/testdata2.txt');
|
$tar->AddFile("$dir/foobar/testdata2.txt", 'noway/testdata2.txt');
|
||||||
$tar->addData('another/testdata3.txt', 'testcontent3');
|
$tar->addData('another/testdata3.txt', 'testcontent3');
|
||||||
@ -332,11 +332,12 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
public function test_createlongfile()
|
public function test_createlongfile()
|
||||||
{
|
{
|
||||||
$tar = new Tar();
|
$tar = new Tar();
|
||||||
|
$tar->setCompression(0);
|
||||||
$tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
|
$tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
|
||||||
|
|
||||||
$path = '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.txt';
|
$path = '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.txt';
|
||||||
|
|
||||||
$tar->create($tmp, Tar::COMPRESS_NONE);
|
$tar->create($tmp);
|
||||||
$tar->addData($path, 'testcontent1');
|
$tar->addData($path, 'testcontent1');
|
||||||
$tar->close();
|
$tar->close();
|
||||||
|
|
||||||
@ -354,6 +355,7 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
public function test_createlongpathustar()
|
public function test_createlongpathustar()
|
||||||
{
|
{
|
||||||
$tar = new Tar();
|
$tar = new Tar();
|
||||||
|
$tar->setCompression(0);
|
||||||
$tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
|
$tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
|
||||||
|
|
||||||
$path = '';
|
$path = '';
|
||||||
@ -362,7 +364,7 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
$path = rtrim($path, '/');
|
$path = rtrim($path, '/');
|
||||||
|
|
||||||
$tar->create($tmp, Tar::COMPRESS_NONE);
|
$tar->create($tmp);
|
||||||
$tar->addData("$path/test.txt", 'testcontent1');
|
$tar->addData("$path/test.txt", 'testcontent1');
|
||||||
$tar->close();
|
$tar->close();
|
||||||
|
|
||||||
@ -382,6 +384,7 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
public function test_createlongpathgnu()
|
public function test_createlongpathgnu()
|
||||||
{
|
{
|
||||||
$tar = new Tar();
|
$tar = new Tar();
|
||||||
|
$tar->setCompression(0);
|
||||||
$tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
|
$tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
|
||||||
|
|
||||||
$path = '';
|
$path = '';
|
||||||
@ -390,7 +393,7 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
$path = rtrim($path, '/');
|
$path = rtrim($path, '/');
|
||||||
|
|
||||||
$tar->create($tmp, Tar::COMPRESS_NONE);
|
$tar->create($tmp);
|
||||||
$tar->addData("$path/test.txt", 'testcontent1');
|
$tar->addData("$path/test.txt", 'testcontent1');
|
||||||
$tar->close();
|
$tar->close();
|
||||||
|
|
||||||
@ -437,9 +440,10 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$dir = dirname(__FILE__).'/tar';
|
$dir = dirname(__FILE__).'/tar';
|
||||||
$tar = new Tar();
|
$tar = new Tar();
|
||||||
|
$tar->setCompression(0);
|
||||||
$tar->create();
|
$tar->create();
|
||||||
$tar->addFile("$dir/zero.txt", 'zero.txt');
|
$tar->addFile("$dir/zero.txt", 'zero.txt');
|
||||||
$file = $tar->getArchive(Tar::COMPRESS_NONE);
|
$file = $tar->getArchive();
|
||||||
|
|
||||||
$this->assertEquals(512 * 3, strlen($file)); // 1 header block + 2 footer blocks
|
$this->assertEquals(512 * 3, strlen($file)); // 1 header block + 2 footer blocks
|
||||||
}
|
}
|
||||||
@ -447,9 +451,10 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
public function test_zerodata()
|
public function test_zerodata()
|
||||||
{
|
{
|
||||||
$tar = new Tar();
|
$tar = new Tar();
|
||||||
|
$tar->setCompression(0);
|
||||||
$tar->create();
|
$tar->create();
|
||||||
$tar->addData('zero.txt', '');
|
$tar->addData('zero.txt', '');
|
||||||
$file = $tar->getArchive(Tar::COMPRESS_NONE);
|
$file = $tar->getArchive();
|
||||||
|
|
||||||
$this->assertEquals(512 * 3, strlen($file)); // 1 header block + 2 footer blocks
|
$this->assertEquals(512 * 3, strlen($file)); // 1 header block + 2 footer blocks
|
||||||
}
|
}
|
||||||
@ -461,9 +466,10 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$dir = dirname(__FILE__).'/tar';
|
$dir = dirname(__FILE__).'/tar';
|
||||||
$tar = new Tar();
|
$tar = new Tar();
|
||||||
|
$tar->setCompression(0);
|
||||||
$tar->create();
|
$tar->create();
|
||||||
$tar->addFile("$dir/block.txt", 'block.txt');
|
$tar->addFile("$dir/block.txt", 'block.txt');
|
||||||
$file = $tar->getArchive(Tar::COMPRESS_NONE);
|
$file = $tar->getArchive();
|
||||||
|
|
||||||
$this->assertEquals(512 * 4, strlen($file)); // 1 header block + data block + 2 footer blocks
|
$this->assertEquals(512 * 4, strlen($file)); // 1 header block + data block + 2 footer blocks
|
||||||
}
|
}
|
||||||
@ -471,9 +477,10 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
public function test_blockdata()
|
public function test_blockdata()
|
||||||
{
|
{
|
||||||
$tar = new Tar();
|
$tar = new Tar();
|
||||||
|
$tar->setCompression(0);
|
||||||
$tar->create();
|
$tar->create();
|
||||||
$tar->addData('block.txt', str_pad('', 512, 'x'));
|
$tar->addData('block.txt', str_pad('', 512, 'x'));
|
||||||
$file = $tar->getArchive(Tar::COMPRESS_NONE);
|
$file = $tar->getArchive();
|
||||||
|
|
||||||
$this->assertEquals(512 * 4, strlen($file)); // 1 header block + data block + 2 footer blocks
|
$this->assertEquals(512 * 4, strlen($file)); // 1 header block + data block + 2 footer blocks
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user