PharData compress nests original tar

153 Views Asked by At

Maybe it is intended but i find it weird that "PharData compress" nests the original tar inside of the compressed tar.gz. So you have to open the .tar.gz and you will see the original.tar which you have to open again?

Code:

    $tarPath  = $_SERVER['DOCUMENT_ROOT'].'api/sample2.tar';
    $pharData = new PharData( $tarPath  );
    $pharData->addFile( $_SERVER['DOCUMENT_ROOT'].'api/callback_post.txt', 'callback_post.txt' );
    $pharData->compress(Phar::GZ);

Php 7.4

1

There are 1 best solutions below

4
Fran Cerezo On

These are two diferent concepts. Tar packs files, while gz compress tar package.

You may try ZipArchive

$zip = new ZipArchive;
$zip->open($_SERVER['DOCUMENT_ROOT'].'api/sample2.zip')
$zip->addFile($_SERVER['DOCUMENT_ROOT'].'api/callback_post.txt', 'callback_post.txt');
$zip->close();