5

我正在使用extractToPHPPharData类的方法来检查 phar 文件的内容并遇到了一些 strage 结果。我已经达到了我的字节级侦探工作的极限,希望这里有人能够帮助我解决这个问题。

详细信息如下,但一般来说:当我用 提取我的存档文件时PharData::extractTo,我得到的文件似乎是一个变体bzip,但bzip2命令不喜欢它们。这是正常phar行为,还是特定存档有问题?(或者可能是我正在使用的 PHP/OS 组合)。有没有办法从 phar 存档中获取纯文本文件 - 或者纯文本应该是默认的,我正在寻找奇怪的系统行为?

具体来说,当我运行命令时

$phar = new Phar('n98-magerun.phar');
$phar->extractTo('/tmp/n98-magerun');

在我的 OS 10.6.8 上,基于 Intel 的 Mac 使用内置的 PHP 5.3.6,存档成功解压到 /tmp/n98-magerun 文件夹中。

在此处输入图像描述

我提取的档案可以在这里找到

如果我打开在 BBEdit 中提取的任何文本文件,我会看到正确的内容。

在此处输入图像描述

但是,如果我使用其他工具,例如 quicklook vi、 或cat,我会看到二进制数据。我在尝试ack/grep通过文件内容时注意到了这一点,但没有得到预期的结果。

在此处输入图像描述

如果我file在文件上使用命令,它会报告它是一个bzip文件。

$ file MIT-LICENSE.txt 
MIT-LICENSE.txt: bzip2 compressed data, block size = 400k

并使用十六进制编辑器检查文件确认文件以BZ标题开头

在此处输入图像描述

但是,尝试解压缩文件bzip2会导致以下错误

$ bzip2 -d MIT-LICENSE.txt 
bzip2: Can't guess original name for MIT-LICENSE.txt -- using MIT-LICENSE.txt.out

bzip2: Compressed file ends unexpectedly;
    perhaps it is corrupted?  *Possible* reason follows.
bzip2: No such file or directory
    Input file = MIT-LICENSE.txt, output file = MIT-LICENSE.txt.out

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

bzip2: Deleting output file MIT-LICENSE.txt.out, if it exists.

我可以bzcat成功地文件,尽管它在文件中间用这个

bzcat: Compressed file ends unexpectedly;
    perhaps it is corrupted?  *Possible* reason follows.
bzcat: Undefined error: 0
    Input file = MIT-LICENSE.txt, output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.
4

2 回答 2

1

这是一个bzip2文件,但要解压缩它,您需要使用--stdout(or -c) 选项(见下文)。

您需要该--stdout选项的原因是文件不以.bz2扩展名结尾,这将允许bunzip2确定要解压缩到的结果文件名。

$ bunzip2 --stdout MIT-LICENSE.txt 2>/dev/null
Copyright (c) 2012 netz98 new media GmbH

http://www.netz98.de

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

我不知道为什么bunzip2将以下内容输出到标准错误:

bzip2: Compressed file ends unexpectedly;
        perhaps it is corrupted?  *Possible* reason follows.
bzip2: Success
        Input file = MIT-LICENSE.txt, output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

正如file命令报告的那样,该文件是一个有效的 bzip2 文件,块大小为 400k:

$ file MIT-LICENSE.txt 
MIT-LICENSE.txt: bzip2 compressed data, block size = 400k

我尝试将-4选项添加到bunzip2,但它仍然抱怨:

$ bunzip2 -d -4 -vvvvv -c  MIT-LICENSE.txt >/dev/null 
  MIT-LICENSE.txt: 
    [1: huff+mtf rt+rld {0x2010d4b9, 0x2010d4b9}]
    combined CRCs: stored = 0x2010d4b9, computed = 0x2010d4b9
    [1: huff+mtf 
bunzip2: Compressed file ends unexpectedly;
        perhaps it is corrupted?  *Possible* reason follows.
bunzip2: Success
        Input file = MIT-LICENSE.txt, output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

所以我的猜测是创建这些 bzip2 文件的程序是这个问题的原因。

于 2013-04-25T04:33:22.593 回答
0

使用extractTo文件以与存档相同的格式存储!这可以是以下之一:无、gzip、bzip2

虽然您当然可以以这种格式保存它们,然后尝试以某种方式提取它,但我建议如下:将 phar 转换为未压缩的phar 并提取该存档!

方法如下:

<?php
$phar = new Phar('Someclass.phar');
$phar2 = $phar->convertToExecutable (Phar::TAR,Phar::NONE); //convert to an uncompressed tar archive
$phar2->extractTo('/some/path/'); // extract all files

这将为您提供所有未压缩的文件!

于 2015-01-23T14:12:09.430 回答