在C#.net平台下,怎么用C#将多个文件打包为.tar包 30
usingICSharpCode.SharpZipLib.Tar;usingICSharpCode.SharpZipLib.GZip;namespaceNetToTar{...
using ICSharpCode.SharpZipLib.Tar;
using ICSharpCode.SharpZipLib.GZip;
namespace NetToTar
{
public class CompressFile
{
/// <summary>
/// 压缩为tar包
/// </summary>
/// <param name="fileName">压缩后的文件名</param>
/// <param name="directory">压缩的文件夹</param>
public static void CompressTarFile(string fileName, string directory)
{
Stream outStream = File.OpenWrite(fileName);
outStream = new GZipOutputStream(outStream);
TarArchive archive = TarArchive.CreateOutputTarArchive(outStream, TarBuffer.DefaultBlockFactor);
String[] files = Directory.GetFiles(directory);
foreach (String name in files)
{
TarEntry entry = TarEntry.CreateEntryFromFile(name);
archive.WriteEntry(entry, true);
}
if (archive != null)
{
archive.CloseArchive();
}
}
}
} 展开
using ICSharpCode.SharpZipLib.GZip;
namespace NetToTar
{
public class CompressFile
{
/// <summary>
/// 压缩为tar包
/// </summary>
/// <param name="fileName">压缩后的文件名</param>
/// <param name="directory">压缩的文件夹</param>
public static void CompressTarFile(string fileName, string directory)
{
Stream outStream = File.OpenWrite(fileName);
outStream = new GZipOutputStream(outStream);
TarArchive archive = TarArchive.CreateOutputTarArchive(outStream, TarBuffer.DefaultBlockFactor);
String[] files = Directory.GetFiles(directory);
foreach (String name in files)
{
TarEntry entry = TarEntry.CreateEntryFromFile(name);
archive.WriteEntry(entry, true);
}
if (archive != null)
{
archive.CloseArchive();
}
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询