我正在使用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檔案... –