| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2009-09-07 15:57 UTC] wes dot harris at gmail dot com
 Description:
------------
PharData::compress truncates filenames if dots exist in the filename.
The code/results explain more that I can here....
Reproduce code:
---------------
<?php
    $p = new PharData('./wes-laptop.local.test.tar');
    $p->addFile('./test.php'); 
    $p1 = $p->compress(Phar::GZ);
    $p2 = $p->compress(Phar::BZ2);
?>
Expected result:
----------------
2009-09-07 20:49 wes-laptop.local.test.tar
2009-09-07 20:49 wes-laptop.local.test.tar.bz2
2009-09-07 20:49 wes-laptop.local.test.tar.gz
Actual result:
--------------
2009-09-07 20:49 wes-laptop.local.test.tar
2009-09-07 20:49 wes-laptop.tar.bz2
2009-09-07 20:49 wes-laptop.tar.gz
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 00:00:01 2025 UTC | 
I create a file name toto.123.file1.tar with $phar->buildFromDirectory("$directory") I create a file name toto.123.file1.tar.md5 -> no problem How to create a compressed file named toto.123.file1.tar.gz? I must do a special script to keep 123.file1 in a variable???Sorry to differ with you "greg at chiaraquartet dot net". But the way Phar deals with extensions is incoherent with SPL. CODE -------- <?php $test = new \SplFileInfo('/tmp/someroute/archive.tar'); echo $test->getExtension() . "\n"; $test = new \SplFileInfo('/tmp/someroute/archive.tar,gz'); echo $test->getExtension() . "\n"; RESULT -------- tar gz So, it seems very clear what is a consistent extension to PHP. To add up, cli command gzip deals the situation just adding '.gz' at the end, not truncating after the first 'period'. From a 'tar' approach, tar create an archive of files (hence the .tar extension), and if you have specified the compress option runs a compress process at the end (hence the .gz, .bzip extensions). It's a "concatenation of formats". But the problem here is not what we think is right or wrong, the thing is that PharData::compress() does not work as expected when the filename has dots in it. As a final note. Current documentation states: "In addition, this method automatically renames the archive, appending .gz, .bz2 or removing the extension if passed Phar::NONE to remove compression. Alternatively, a file extension may be specified with the second parameter.", Appending is not the same as substituting. This bug needs to be reopen.