Re: decompressing phar file not getting sane results

[email protected] ("Christoph M. Becker")
Newsgroups php.general
Message-ID <[email protected]>
On 29.04.2022 at 06:51, Dennis Gearon wrote:

> running in CLI mode. readonly for Phars is set to 'off'
> If I do $p->extractTo() BEFORE compressing it, I ca the right results when
> I do
> cat *.txt in directory extracted to. But if I compress it and then
> decompress it, I get garbage.
>
> -------------------------------------------------------------------------
> CODE
> ----------------------------------------------------------------------------
>
> <?php
> $p = new Phar('/home/gearond/my.phar', FilesystemIterator::SKIP_DOTS |
> FilesystemIterator::UNIX_PATHS, 'my.phar');
> $p['myfile.txt'] = 'four score and seven years ago our fathers.';
> $p['myfile2.txt'] = 'four score and severn years ago our mothers.';
> foreach ($p as $file) {
>     var_dump($file->getFileName());
>     var_dump($file->isCompressed());
>     var_dump($file->isCompressed(Phar::BZ2));
>     var_dump($file->isCompressed(Phar::GZ));
> }
> var_dump($p->getSupportedCompression() );
> var_dump( $p->compressFiles(Phar::GZ) );
> foreach ($p as $file) {
>     var_dump($file->getFileName());
>     var_dump($file->isCompressed());
>     var_dump($file->isCompressed(Phar::BZ2));
>     var_dump($file->isCompressed(Phar::GZ));
> }
> var_dump( $p->decompressFiles() );
> foreach ($p as $file) {
>     var_dump($file->getFileName());
>     var_dump($file->isCompressed());
>     var_dump($file->isCompressed(Phar::BZ2));
>     var_dump($file->isCompressed(Phar::GZ));
> }
> var_dump( $p->extractTo("./", null, true) );
> ?>
>
>
> ---------------------------------------------------------------------------
> RESULTS
> ----------------------------------------------------------------------------
>
> string(10) "myfile.txt"
> bool(false)
> bool(false)
> bool(false)
> string(11) "myfile2.txt"
> bool(false)
> bool(false)
> bool(false)
> array(2) {
>   [0]=>
>   string(2) "GZ"
>   [1]=>
>   string(5) "BZIP2"
> }
> NULL
> string(10) "myfile.txt"
> bool(true)
> bool(false)
> bool(true)
> string(11) "myfile2.txt"
> bool(true)
> bool(false)
> bool(true)
> bool(true)
> string(10) "myfile.txt"
> bool(false)
> bool(false)
> bool(false)
> string(11) "myfile2.txt"
> bool(false)
> bool(false)
> bool(false)
> bool(true)
>
> ---------------------------------------------------------------------------
> FILE CONTENT
> ----------------------------------------------------------------------------
> The results of cat *.txt in the director extracted to are:
>
> cat *.txt
> K�/-R(N�/JUH�KQ(N-K-�S�LM,*VHL�WI��d��K�/-R(N�/JUH�KQ(N-K�S�LM,*VHL�Wɦ%�d��

I can reproduce this.  Apparently, the files are neither uncompressed in
the phar archive.  That looks like a bug.  Consider to file a ticket at
<https://github.com/php/php-src/issues>.

--
Christoph M. Becker
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.