开发者

Appending to a compressed file using GZipStream

I'm trying to use GZipStream to write some application traces (they tend to grow to huge sizes in product开发者_JAVA百科ion). So in this case i need the ability to open an existing file and append to it using GZipStream. All things seem to work well until we try to decompress the file. It seems that on decompression GZipStream reads only the first chunk of data and then behaves like it reached EOF (even if the file contains a whole lot more). Strange thing is that when opening the file using windows or Winrar all the data seems to be present and extracted properly. Has anyone encountered this issue before?


I've encountered same problem. The idea is to implement something like what http://zlib.net/pigz/ does


This took an incredibly long time for me to figure out. The standard C# implementation, GZipStream has a bug in that it does not support concatenated gzip files. It will only decompress the first part of a gzip file created from concatenation, and will report end of stream after that.

Here is an example that will work for concatinated gzip files:

new StreamReader(new ICSharpCode.SharpZipLib.GZip.GZipInputStream(Console.OpenStandardInput()));

You can get the library you need from nuget. I recommend jetbrain's version, JetBrains.SharpZLib.Stripped. Nuget threw an error when I tried to use the other option in a .net core project

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜