Ala*_*orm 5 php hex phar bzip2
我正在使用extractToPHP PharData类的方法来检查phar文件的内容并运行一些strage结果.我已经达到了我的字节级侦探工作的极限,并希望有人能够帮助我解决这个问题.
详细信息如下,但一般来说:当我提取我的存档文件时PharData::extractTo,我得到的文件显示为varient bzip,但bzip2命令不喜欢它们.这是正常的phar行为,还是特定档案的问题?(或者我正在使用的PHP/OS组合).有没有办法从phar存档中获取纯文本文件 - 或者纯文本应该是默认文件,而我正在查看奇怪的系统行为?
具体来说,当我运行命令时
$phar = new Phar('n98-magerun.phar');
$phar->extractTo('/tmp/n98-magerun');
Run Code Online (Sandbox Code Playgroud)
在我的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
Run Code Online (Sandbox Code Playgroud)
并使用十六进制编辑器检查文件,确认文件以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.
Run Code Online (Sandbox Code Playgroud)
我可以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.
Run Code Online (Sandbox Code Playgroud)
它是一个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
Run Code Online (Sandbox Code Playgroud)
我不知道为什么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.
Run Code Online (Sandbox Code Playgroud)
该file命令报告该文件是一个有效的 bzip2 文件,块大小为 400k:
$ file MIT-LICENSE.txt
MIT-LICENSE.txt: bzip2 compressed data, block size = 400k
Run Code Online (Sandbox Code Playgroud)
我尝试添加-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.
Run Code Online (Sandbox Code Playgroud)
所以我的猜测是创建这些 bzip2 文件的程序是导致此问题的原因。