2013-04-14 41 views
5

Bir phar dosyasının içeriğini incelemek ve bazı sıkışma sonuçlarıyla çalışmak için PharData sınıfının extractTo yöntemini kullanıyorum. Bayt seviyesinde dedektif çalışmamın sınırlarına ulaştım ve buradaki birisinin bana yardım etmesine yardımcı olabileceğini umuyordum.Hangi Dosya Biçimi PharData :: extractTo Dosyalarını Ayıklıyor mu?

Detaylar izleyin ama genel olarak konuşursak: Ben PharData::extractTo ile benim arşiv dosyaları ayıklamak, dosyalar bir bzip varyant olarak appeart çıkmak, ancak bzip2 komut bunları sevmez. Bu normal phar davranış mı, yoksa belirli bir arşivle ilgili bir sorun mu var? (veya kullanıyorum PHP/OS kombinasyonu). Düz metin dosyalarını phar arşivinden çıkarmanın bir yolu var mı - yoksa düz metin varsayılan mı olmalı ve garip sistem davranışına mı bakıyorum? Benim OS 10.6.8 Açık komutunu

$phar = new Phar('n98-magerun.phar'); 
$phar->extractTo('/tmp/n98-magerun'); 

çalıştırdığınızda

Özellikle, Intel Mac PHP 5.3.6 yerleşik, arşiv başarıyla/tmp/N98-magerun içine ayıklanır kullanarak tabanlı Klasör.

enter image description here

Ben can be found here ayıklanması ediyorum arşivi.

BBEdit'te ayıklanan herhangi bir metin dosyasını açarsam, doğru içeriği görüyorum. Böyle QuickLook vi veya cat gibi diğer araçları kullanmak Ancak

enter image description here

, ben ikili verileri görmek. Dosyaların içeriği üzerinden ack/grep'u denerken bunu fark ettim ve beklediğim sonuçları alamadım. Ben dosya üzerinde file komutunu kullanırsanız

enter image description here

, bunun bir bzip dosya olduğunu rapor veriyor.

$ file MIT-LICENSE.txt 
MIT-LICENSE.txt: bzip2 compressed data, block size = 400k 

ve bir onaltılık editörü ile dosyayı inceleyen dosyası aşağıdaki hata

$ 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. 
yılında bzip2 sonuçlarla dosya sıkıştırması çalışılırken,

enter image description here

Ancak bir BZ başlığı ile başlar doğruladı

ve bzcat dosyasını başarılı bir şekilde yapabilirim. Bu bir bzip2 dosyasıdır bu

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

http://php.net/manual/en/phardata.extractto.php? Eski Mac sistemlerinde 'pax' arşiv formatı hakkında yazıyor. –

+0

Bunu gördüm, ancak nasıl uygulandığından emin değilim (eğer). PHP'nin bazı eski Mac OS sürümlerinin pax stili phar arşivlerini oluşturduğunu, ancak 'extractTo' sadece ustar varyantının arşivden kaldırılmasını desteklediğini söylüyor. Arşivi üretmediğim ve arşivin doğru şekilde çıkarıldığından, alakalı olduğundan emin değilim. (Yani, ben tam olarak emin değilim: Daha önce phar şeyler etrafında hacklemedim) –

+0

Üzgünüz, yanlış anladım - ilk okumadan sonra bazı sistemler olarak anladım (ve Mac OS kullanıyorlar) dedektif çalışma için phar özleri phar ayıklar ... –

cevap

1

ile dosyanın dle, ancak bunu açmak için, sen --stdout (veya -c) seçeneğini (aşağıya bakınız) kullanmak gerekir.

Eğer --stdout seçeneği gerek sebebi, bunzip2 için sıkıştırmasını çıkan dosya adı belirlemek için izin verecek bir .bz2 uzantılı bitmiyor dosyasıdır.

$ 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 

Ben bunzip2 standart hataya aşağıdaki çıkış olanağı neden hiçbir fikrim yok:

: Dosya 400k bir blok boyutu ile geçerli bir bzip2 dosyasıdır file komut raporları gibi

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 MIT-LICENSE.txt 
MIT-LICENSE.txt: bzip2 compressed data, block size = 400k 

-4 seçeneğini bunzip2 eklemeye çalıştım, ancak yine de şikayet ediyor:

$ 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. 

Bu nedenle, bzip2 dosyalarını oluşturan programın, bu sorunun nedeni olduğunu düşünüyorum.

+0

+1, ve muhtemelen bir en iyi cevap. PHP'nin 'phar' kodunu yaratmaya çalıştım ve bu tuhaf 'bz' dosyalarının bir nedeni olarak işaret edemediğim halde, beni suçlu bir uygulama olarak gösterdim. –

0

Dosyaları, extractTo kullanarak arşivdeki aynı biçimde depolanır! Bu biri olabilir: hiçbiri, gzip, bzip2

kesinlikle bu biçimde saklayabilirsiniz ve sonra bir şekilde onu çıkarmak için çalışırken, aşağıdaki önermek: bir sıkıştırılmamış phar ve özü içine phar dönüştürme o Arşiv!

<?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 

Bu, sıkıştırılmamış tüm dosyaları verecektir: Burada

nasıl!