Skip to content

Commit 439293a

Browse files
authored
Merge pull request #22 from twifty/gzip-fix
Gzip fix
2 parents 6b1c174 + ed78f7d commit 439293a

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ vendor/
55
composer.lock
66
apigen.phar
77
docs/
8-
8+
nbproject/

src/Tar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public function getArchive()
356356
}
357357

358358
if ($this->comptype === Archive::COMPRESS_GZIP) {
359-
return gzcompress($this->memory, $this->complevel);
359+
return gzencode($this->memory, $this->complevel);
360360
}
361361
if ($this->comptype === Archive::COMPRESS_BZIP) {
362362
return bzcompress($this->memory);

tests/tar.test.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,41 @@ public function test_blockdata()
556556

557557
$this->assertEquals(512 * 4, strlen($file)); // 1 header block + data block + 2 footer blocks
558558
}
559+
560+
/**
561+
* @depends test_ext_zlib
562+
*/
563+
public function test_gzipisvalid()
564+
{
565+
foreach (['tgz', 'tar.gz'] as $ext) {
566+
$input = glob(dirname(__FILE__) . '/../src/*');
567+
$archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.' . $ext;
568+
$extract = sys_get_temp_dir() . '/dwtartest' . md5(time() + 1);
569+
570+
$tar = new Tar();
571+
$tar->setCompression(9, Tar::COMPRESS_GZIP);
572+
$tar->create();
573+
foreach ($input as $path) {
574+
$file = basename($path);
575+
$tar->addFile($path, $file);
576+
}
577+
$tar->save($archive);
578+
$this->assertFileExists($archive);
579+
580+
try {
581+
$phar = new PharData($archive);
582+
$phar->extractTo($extract);
583+
} catch (\Exception $e) {};
584+
585+
$this->assertFileExists("$extract/Tar.php");
586+
$this->assertFileExists("$extract/Zip.php");
587+
588+
$this->nativeCheck($archive, $ext);
589+
590+
self::rdelete($extract);
591+
unlink($archive);
592+
}
593+
}
559594

560595
/**
561596
* recursive rmdir()/unlink()

0 commit comments

Comments
 (0)