0
我有一個完全有效的zip文件,它只包含一個打包文件,可以通過外部實用程序進行解壓縮,並且不會讓任何有用的DeflateStream。我已經刪除了前兩個字節的前綴(「50h 4Bh」,這些總是產生「塊長度與其補碼不匹配」的例外),但是然後沒有進展 - 解壓縮[]總是包含零且讀取也返回0.DeflateStream.Read總是返回零
byte[] zipped = new byte[] { 0x03, 0x04, 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0xe4, 0x6e, 0x89, 0x4a, 0x1d, 0x42, 0x8f, 0xb7, 0x1d, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x63, 0x64, 0x60, 0x60, 0xa8, 0xd7, 0x0b, 0x62, 0x60, 0xa8, 0x65, 0xc4, 0x8e, 0x41, 0x0a, 0x18, 0x18, 0xeb, 0x41, 0x14, 0xa3, 0x08, 0x03, 0x8c, 0x0f, 0x27, 0x40, 0x00, 0x00, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0xe4, 0x6e, 0x89, 0x4a, 0x1d, 0x42, 0x8f, 0xb7, 0x1d, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00 };
MemoryStream zipstream = new MemoryStream(zipped);
byte[] unzipped = new byte[1024];
using (MemoryStream unzipstream = new MemoryStream(unzipped))
{
using (DeflateStream worker = new DeflateStream(zipstream, CompressionMode.Decompress))
{
try
{
int length = worker.Read(unzipped, 0, 1024);
//worker.CopyTo(unzipstream);
//Console.Write(unzipstream.Length);
//int length = unzipstream.Read(unzipped,0,1024);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
}
謝謝,這將工作。 'ZipArchive ziparc = ZipFile.Open(openFileDialog1.FileName,ZipArchiveMode.Read); DeflateStream defstream0 =(DeflateStream)ziparc.Entries [0] .Open(); byte [] buffer = new byte [1024]; defstream0.Read(buffer,0,1024);' 但我應該更好地描述我的情況。我試圖避免磁盤操作,因爲我將這個存檔作爲byte []接收。 – ZuOverture
在這種情況下,您可以使用'ZipInputStream',它可以在包裝在ByteArrayInputStream中的內存數組中工作。 @ZuOverture – BeeOnRope