C#解压gzip⽂件(.tgz)
1、引⽤ SharpCompress.dll
2、代码
using System;
using System.IO;
using System.Text;
using SharpCompress.Reader;
using SharpCompress.Common;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
unTAR(@"E:\ConsoleApplication1\");
Console.WriteLine("Decompress Succeed!");
Console.ReadLine();
}
private static string directoryPath = @"E:\ConsoleApplication1\ConsoleApplication1\新建⽂件夹";
static void unTAR(string tarFilePath)
{gzip是什么文件夹
// UTF7: support chinese font -> UTF.7
SharpCompress.Common.ArchiveEncoding.Default = Encoding.UTF7;
using (Stream stream = File.OpenRead(tarFilePath))
{
var reader = ReaderFactory.Open(stream);
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
reader.WriteEntryToDirectory(directoryPath,
ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
}
}
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。