我正在使用PHP PharData
类的extractTo
方法来检查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文件夹中。
我正在提取的档案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
该文件,虽然它在文件中间用这个barfs
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.
答案 0 :(得分:1)
这是bzip2
文件,但要解压缩,您需要使用--stdout
(或-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
命令报告文件是块大小为400k的有效bzip2文件时:
$ 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文件的程序是造成这个问题的原因。
答案 1 :(得分:0)
使用extractTo
文件以与存档中相同的格式存储!这可以是以下之一:none,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
这将为您提供所有未压缩的文件!