我有一个完全有效的压缩文件,它只包含一个压缩文件,可以通过外部实用程序进行解压缩,而且它不会让任何有用的东西从DeflateStream中流出。我删除了前两个字节的前缀("50h 4Bh",总是产生“块长度与其补码不匹配”的异常),但随后没有进展- unzipped[]总是包含零,读取也返回0。
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);
}
}
}发布于 2017-04-16 06:50:58
这是一个zip文件,不是zlib流。使用ZipFile类。
https://stackoverflow.com/questions/43431924
复制相似问题