0

Using GZipStream to open downloaded gzip files and get the xml file inside.

Problem is that sometimes the whole xml file isn't extracted by my code:

    private static string Unzip(string fileToUnzip, string format)
    {
        string unzippedFileName = fileToUnzip.Replace(".zip", format);

        FileInfo fi = new FileInfo(fileToUnzip);

        using (FileStream inFile = fi.OpenRead())
        {
            try
            {
                using (FileStream outFile = File.Create(unzippedFileName))
                {
                    using (GZipStream Decompress = new GZipStream(inFile,
                            CompressionMode.Decompress, true))
                    {
                        Decompress.CopyTo(outFile);
                    }
                }
            }
            catch(Exception ex)
            {
                int k = 0;
            }
        }

        return unzippedFileName;
    }

There is nothing wrong with the gzip files, I can get the xml fil manually using WinRAR.

No exceptions are thrown.

Any ideas for what is going wrong?

Loofer
  • 6,841
  • 9
  • 61
  • 102
Louisa
  • 552
  • 1
  • 9
  • 22

1 Answers1

0

Using 7-zip fixed the problem.

See GZipStream not reading the whole file

Thanks Anders Forsgren!

Community
  • 1
  • 1
Louisa
  • 552
  • 1
  • 9
  • 22