生成TAR或者生成TAR.gz

using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Tar;

public static void Create_Tar_Archive(string IN,string OUT)
{
//IN and OUT are directories
if (IN=="" || OUT=="" || !System.IO.Directory.Exists(IN)
|| !System.IO.Directory.Exists(OUT)) return;
string OutName=OUT+"\\"+System.IO.Path.GetFileName(IN)+". tar";

Stream stmout=new FileStream(OutName,FileMode.OpenOrCreate);
TarArchive
TA=ICSharpCode.SharpZipLib.Tar.TarArchive.CreateOu tputTarArchive(stmout);
TarEntry TE=TarEntry.CreateEntryFromFile(IN);
TA.WriteEntry(TE,true);
TA.CloseArchive();
stmout.Close();
}

 

 

 public void CompressTarFile(string fileName)
        {

    fileName="f:\\teat.tar.gz";
            string _fileName = fileName;//压缩后的文件名
            Stream outStream;
            outStream = File.OpenWrite(_fileName);
            outStream = new GZipOutputStream(outStream);
            TarArchive archive = TarArchive.CreateOutputTarArchive(outStream, TarBuffer.DefaultBlockFactor);
            String[] files = Directory.GetFiles("F:");
            foreach (String name in files)
            {
                TarEntry entry = TarEntry.CreateEntryFromFile(name);
                archive.WriteEntry(entry, true);
            }
            if (archive != null)
            {
                archive.CloseArchive();
            }
        }

/Files/lbg280/生成压缩动态库.rar

 

 

你可能感兴趣的:(tar)