📜  保存文件 tar.gz c# 代码示例

📅  最后修改于: 2022-03-11 14:49:09.636000             🧑  作者: Mango

代码示例2
//Perhaps the most popular package in NuGet that supports TAR is SharpZipLib. 
//Its wiki includes examples for working with tar.gz files, including creation. 
//The linked example archives an entire folder.
//To archive a single file, the sample can be simplified to this:
private void CreateTarGZ(string tgzFilename, string fileName)
{
    using (var outStream = File.Create(tgzFilename))
    using (var gzoStream = new GZipOutputStream(outStream))
    using (var tarArchive = TarArchive.CreateOutputTarArchive(gzoStream))
    {
        tarArchive.RootPath = Path.GetDirectoryName(fileName);

        var tarEntry = TarEntry.CreateEntryFromFile(fileName);
        tarEntry.Name = Path.GetFileName(fileName);

        tarArchive.WriteEntry(tarEntry,true);
    }
}