在 c# 中解压缩 gz 文件:System.IO.InvalidDataException:'The archive entry was compressed using an unsupported compression method.'

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

我已按照 Microsoft 推荐的方式解压 .gz 文件:

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

我正在尝试从 CommonCrawl 下载和解析文件。我可以成功下载它们,并用 7-zip

解压它们

但是,在 c# 中我得到:

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}");
                    }
                }
            }
        }

文件来自那里:

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

有人知道问题出在哪里吗?我需要一个特殊的图书馆吗?

我不确定问题出在哪里,但在阅读这篇文章后 post

Decompressing using GZipStream returns only the first line

我改用 SharZipLib (http://www.icsharpcode.net/opensource/sharpziplib/) 并且有效

我再次查看了那个源文件,它似乎是大量 (52,593) 个 gzip 流连接在一起。根据规范显然是合法的,但 GZipStream 似乎处理得不好。很高兴你成功了!