【发布时间】:2013-04-06 22:29:23
【问题描述】:
我正在使用 PHP PharData 类的 extractTo 方法来检查 phar 文件的内容并遇到一些策略结果。我已经达到了我的字节级侦探工作的极限,希望这里的人能够帮助我解决这个问题。
细节如下,但一般来说:当我使用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 文件夹中。
我正在提取的存档can be found here。
如果我打开在 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.
【问题讨论】:
-
你看到php.net/manual/en/phardata.extractto.php下面的评论了吗?它说的是旧 Mac 系统上的
pax存档格式。 -
我看到了,但我不确定我是否遵循它的应用方式(如果有的话)。似乎是说一些较旧的 Mac OS 版本的 PHP 会生成 pax 样式的 phar 存档,但
extractTo仅支持取消存档 ustar 变体。由于我没有生成存档,并且存档确实提取正确,因此我不确定它是否相关。 (我的意思是,我真的不确定:我以前没有研究过 phar 的东西) -
抱歉,我弄错了 - 在第一次阅读后,我理解为某些系统(并提到您正在使用的 Mac OS)将 phar 提取到 pax 档案中......