Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/92'
Browse files Browse the repository at this point in the history
Close #92
Fix #41
  • Loading branch information
michalbundyra committed Aug 18, 2019
2 parents a582487 + 063fca8 commit 63e7fe3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ All notable changes to this project will be documented in this file, in reverse
- [#89](https://github.com/zendframework/zend-filter/pull/89) fixes infinite
loop on malformed HTML comments in StripTags filter.

- [#92](https://github.com/zendframework/zend-filter/pull/92) fixes Tar adapter
to not require `archive` in options when decompressing.

## 2.9.1 - 2018-12-17

### Added
Expand Down
5 changes: 3 additions & 2 deletions src/Compress/Tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,12 @@ public function compress($content)
public function decompress($content)
{
$archive = $this->getArchive();
if (empty($archive) || ! file_exists($archive)) {
if (file_exists($content)) {
$archive = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, realpath($content));
} elseif (empty($archive) || ! file_exists($archive)) {
throw new Exception\RuntimeException('Tar Archive not found');
}

$archive = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, realpath($content));
$archive = new Archive_Tar($archive, $this->getMode());
$target = $this->getTarget();
if (! is_dir($target)) {
Expand Down
28 changes: 28 additions & 0 deletions test/Compress/TarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,32 @@ public function testTarToString()
$filter = new TarCompression();
$this->assertEquals('Tar', $filter->toString());
}

/**
* @see https://github.com/zendframework/zend-filter/issues/41
*/
public function testDecompressionDoesNotRequireArchive()
{
$filter = new TarCompression([
'archive' => $this->tmp . '/compressed.tar',
'target' => $this->tmp . '/zipextracted.txt',
]);

$content = 'compress me ' . microtime(true);
$compressed = $filter->compress($content);

self::assertSame($this->tmp . DIRECTORY_SEPARATOR . 'compressed.tar', $compressed);

$target = $this->tmp;
$filter = new TarCompression([
'target' => $target,
]);

$decompressed = $filter->decompress($compressed);
self::assertSame($target, $decompressed);
// per documentation, tar includes full path
$file = $target . DIRECTORY_SEPARATOR . $target . DIRECTORY_SEPARATOR . '/zipextracted.txt';
self::assertFileExists($file);
self::assertSame($content, file_get_contents($file));
}
}

0 comments on commit 63e7fe3

Please sign in to comment.