我正在使用PHP PharData
类的extractTo
方法来检查phar文件的内容并运行一些平稳的结果。我已经达到了我的字节级侦探工作的极限,并希望这里有人能够帮我解决这个问题。什么文件格式PharData :: extractTo将文件解压缩为?
详情如下,但一般来说:当我使用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中提取的任何文本文件,我会看到正确的内容。
然而,如果我使用其他工具,如快速查找,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
文件成功,虽然它在中期barf该文件与此
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.
你见过下面的评论http://php.net/manual/en/phardata.extractto.php吗?它介绍了旧版Mac系统上的'pax'存档格式。 –
我看到了这一点,但我不确定我是否遵循了它的适用方式(如果有的话)。这似乎是说一些较旧的Mac OS版本的PHP生成pax样式的phar归档文件,但'extractTo'只支持取消归档ustar变体。由于我没有生成档案,并且档案没有正确提取,所以我不确定它是否相关。 (我的意思是,我真的不知道:我之前没有在phar的东西上砍过) –
对不起,我错了 - 第一次阅读后,我将它理解为一些系统(并提到Mac OS,正在使用)提取phar到pax档案... –