如何在C#中下载和解压缩Sitemap GZ文件? [英] How to download and unzip a sitemap gz file in c#?
本文介绍了如何在C#中下载和解压缩Sitemap GZ文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要下载一个已压缩(可能是tar + gzip?)的sitemap.xml文件并将其解压缩为sitemap.xml.gz
I need to download and unzip a sitemap.xml file that is compressed (maybe tar + gzip?) into a sitemap.xml.gz
在Windows上,我使用7zip.但是请注意,gz包含一个与压缩文件同名的目录(可能是由于tar + gx)
From Windows I use 7zip. But note that the gz contains a directory with the same name of the zipped file (maybe due to tar + gx)
我该如何使用c#?
谢谢
推荐答案
使用 GZip Stream 类来解压缩XML文档.
Use the GZip Stream class to unzip the XML document.
类似的东西:
var file = File.Open("C:\test.xml.gz", FileMode.Open);
var zip = new GZipStream(file, CompressionMode.Decompress);
var doc = new XmlDocument();
doc.Load(zip);
修改
要更加干净地使用我们的IDisposables:
To be more clean with our IDisposables:
var doc = new XmlDocument();
using(var file = File.Open("C:\test.xml.gz", FileMode.Open))
using(var zip = new GZipStream(file, CompressionMode.Decompress))
{
doc.Load(zip);
}
这篇关于如何在C#中下载和解压缩Sitemap GZ文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文