'在c#中解压缩gz文件:System.IO.InvalidDataException:'使用不受支持的压缩方法压缩了存档条目. [英] Unzipping a gz file in c# : System.IO.InvalidDataException: 'The archive entry was compressed using an unsupported compression method.'
问题描述
我已经按照Microsoft推荐的方法来解压缩.gz文件:
I have followed Microsoft's recommended way to unzip a .gz file :
https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.gzipstream?view=netcore-3.1
我正在尝试从CommonCrawl下载和解析文件.我可以成功下载它们,并使用7-zip解压缩它们.
I am trying to download and parse files from the CommonCrawl. I can successfully download them, and unzip them with 7-zip
但是,在C#中我得到了:
However, in c# I get:
System.IO.InvalidDataException:'存档条目已压缩使用不受支持的压缩方法.'
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}");
}
}
}
}
文件从那里:
Does anyone know what the problem could be? do I need a special library?
推荐答案
我不确定是什么问题,但是在阅读了这篇文章之后
I am not sure what the issue is but after reading this post
我改为SharZipLib( http://www.icsharpcode.net/opensource/sharpziplib/),并且有效
I changed to SharZipLib (http://www.icsharpcode.net/opensource/sharpziplib/) and it worked
这篇关于'在c#中解压缩gz文件:System.IO.InvalidDataException:'使用不受支持的压缩方法压缩了存档条目.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!