Decompressing using GZipStream returns only the first line

南笙酒味 提交于 2019-12-01 08:58:10

I've put the last 45 minutes wrapping my head around this problem but I just can't explain why it isn't working. Somehow the DeflateStream-class isn't decoding your data properly. I wrote up my own GZip-parser (I can share the code if anyone wants to check it) which reads all the headers and checks them for validity (to make sure that there are no funny stuff there) and then use DeflateStream to inflate the actual data but with your file it still just gets me the first line.

If I recompress using your logfile using GZipStream (after first decompressing it with winrar) then it is decompressed just fine again both my my own parser and your own sample.

There seems to be some critizism on the net about Microsofts implementation of Deflate (http://www.virtualdub.org/blog/pivot/entry.php?id=335) so it might be that you found one of it's quirks.

However, a simple solution to your problem is to switch to SharZipLib (http://www.icsharpcode.net/opensource/sharpziplib/), I tried it out and it can decompress your file just fine.

    public static void DecompressGZip(String fileRoot, String destRoot)
    {
        using (FileStream fileStram = new FileStream(fileRoot, FileMode.Open, FileAccess.Read))
        using (GZipInputStream zipStream = new GZipInputStream(fileStram))
        using (StreamReader sr = new StreamReader(zipStream))
        {
            string data = sr.ReadToEnd();
            File.WriteAllText(destRoot, data);
        }
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!