Search code examples
c#gzipcommon-crawl

Unzipping a gz file in c# : System.IO.InvalidDataException: 'The archive entry was compressed using an unsupported compression method.'


I have followed Microsoft's recommended way to unzip a .gz file :

https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.gzipstream?view=netcore-3.1

I am trying to download and parse files from the CommonCrawl. I can successfully download them, and unzip them with 7-zip

However, in c# I get:

System.IO.InvalidDataException: 'The archive entry was compressed using an unsupported compression method.'

public static void Decompress(FileInfo fileToDecompress)
        {
            using (FileStream originalFileStream = fileToDecompress.OpenRead())
            {
                string currentFileName = fileToDecompress.FullName;
                string newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);

                using (FileStream decompressedFileStream = File.Create(newFileName))
                {
                    using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
                    {
                        decompressionStream.CopyTo(decompressedFileStream);
                        Console.WriteLine($"Decompressed: {fileToDecompress.Name}");
                    }
                }
            }
        }

The file is from there:

https://commoncrawl.s3.amazonaws.com/crawl-data/CC-MAIN-2020-16/segments/1585370490497.6/wet/CC-MAIN-20200328074047-20200328104047-00010.warc.wet.gz

Does anyone know what the problem could be? do I need a special library?


Solution

  • I am not sure what the issue is but after reading this post

    Decompressing using GZipStream returns only the first line

    I changed to SharZipLib (http://www.icsharpcode.net/opensource/sharpziplib/) and it worked