Decompression using GZipStream returns only the first line

I worked on a function that analyzes third-party phrase logs. Logs are in Gzip, so I use the decompress function, which works for any other Gzip files that we use.

When unpacking these files, I get only the first line of the compressed file, without exception, it just does not find the remaining bytes, as if the EOF in the first line. I tried using Ionic.Zlib instead of System.IO.Compression, but the result was the same. Files do not seem to be corrupted in any way, unpacking them using Winrar.

If anyone knows how to solve this, I will be happy for your help. Thanks

You can download a sample file here: http://www.adjustyourset.tv/fms_6F9E_20120621_0001.log.gz

This is my decompression function:

public static bool DecompressGZip(String fileRoot, String destRoot) { try { using (FileStream fileStram = new FileStream(fileRoot, FileMode.Open, FileAccess.Read)) { using (FileStream fOutStream = new FileStream(destRoot, FileMode.Create, FileAccess.Write)) { using (GZipStream zipStream = new GZipStream(fileStram, CompressionMode.Decompress, true)) { byte[] buffer = new byte[4096]; int numRead; while ((numRead = zipStream.Read(buffer, 0, buffer.Length)) != 0) { fOutStream.Write(buffer, 0, numRead); } return true; } } } } catch (Exception ex) { LogUtils.SaveToLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "Eror decompressing " + fileRoot + " : " + ex.Message, Constants.systemLog, 209715200, 6); return false; } } 
+3
source share
1 answer

I put the last 45 minutes wrapping my head around this problem, but I just can't explain why it doesn't work. Somehow the DeflateStream class does not decode your data correctly. I wrote my own GZip parser (I can share this code if someone wants to check it) that reads all the headers and checks for certainty (to make sure there is no funny stuff), and then use DeflateStream to inflate the actual data but with your file it will still just deliver me the first line.

If I recompress your log file using GZipStream (after unpacking it for the first time using winrar), it again unpacks just my own parser and your own sample.

There seems to be some criticism on the net about implementing Microsoft Deflate (http://www.virtualdub.org/blog/pivot/entry.php?id=335), so it may be that you found one of these quirks.

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

  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); } } 
+1
source

Source: https://habr.com/ru/post/1202899/


All Articles