files tar.gz

Code Example - files tar.gz

                
                        tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
                    
                
 

save file tar.gz csharp

                        
                                //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);
    }
}
                            
                        
 

Related code examples