GZipStream does not unzip csv file correctly

62 Views Asked by At

For some reason, the file is unzipped incorrectly, the output is a 1KB file, inside there is 1 line of the original file. The archived file is downloaded from here: https://epss.cyentia.com/epss_scores-current.csv.gz

Program code:

public void DownloadExcelCsv(string url)
    {
        string pathFile = path + @"\epss.csv.gz";

        using (WebClient web = new WebClient())
        {
            web.DownloadFile(new Uri(url[i]), pathFile[i]);
        }

        Decompressed(pathFile);
    }

private void Decompressed(string file)
    {
        string decomprssedFile = path + @"\epss.csv";

        using (FileStream sourceFile = File.OpenRead(file))
        {
            using (GZipStream gZip = new GZipStream(sourceFile, CompressionMode.Decompress))
            {
                using (FileStream targetFile = File.Create(decomprssedFile))
                {        
                    gZip.CopyTo(targetFile);

                    MessageBox.Show(String.Format("Восстановление файла {0} завершено.\nБыло: {1}, стало: {2}",
                            sourceFile.Name,
                            sourceFile.Length,
                            targetFile.Length));
                }
            }
        }
    }
0

There are 0 best solutions below