Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

GZipStream Failed to Unzip Gzip File, Is it a BUG?

$
0
0

Hi, I have a Gzip file, which can be unzip by 7zip. But when I try to unzip it by C# GZipStream, it failed. 

GZipStream can only extract frist 11 bytes, it's "OutputWindows" property is 11. 

And I've tried SharpZipLib and DotNetZip, and got the same result.

Anyone know the reason? Is it a GZipStream Bug? And how can i unzip the file?

Here's my code:

        public void Decompress(string strPath)
        {
            DateTime current;
            string dstFile = "";

            FileStream fsIn = null;
            FileStream fsOut = null;
            GZipStream gzip = null;
            const int bufferSize = 4096;
            byte[] buffer = new byte[bufferSize];
            int count = 0;

            try
            {
                current = DateTime.Now;
                dstFile = "z:\\" + current.Day.ToString() + current.Month.ToString() + current.Year.ToString() + current.Hour.ToString() + current.Minute.ToString() + current.Second.ToString() + ".txt";
                fsIn = new FileStream(strPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                fsOut = new FileStream(dstFile, FileMode.Create, FileAccess.Write, FileShare.None);
                gzip = new GZipStream(fsIn, CompressionMode.Decompress, true);
                while (true)
                {
                    count = gzip.Read(buffer, 0, bufferSize);
                    if (count != 0)
                    {
                        fsOut.Write(buffer, 0, count);
                    }
                    if (count != bufferSize)
                    {
                        // have reached the end
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // handle or display the error 
                System.Diagnostics.Debug.Assert(false, ex.ToString());
            }
            finally
            {
                if (gzip != null)
                {
                    gzip.Close();
                    gzip = null;
                }
                if (fsOut != null)
                {
                    fsOut.Close();
                    fsOut = null;
                }
                if (fsIn != null)
                {
                    fsIn.Close();
                    fsIn = null;
                }
            }
        } 

Here's my Gzip file:


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>