I am working on a project where I need to deal with some .taz compressed files. Is there a way to decompress and extract those kind of files, in C# dotnet core ?
Thank you !
I am working on a project where I need to deal with some .taz compressed files. Is there a way to decompress and extract those kind of files, in C# dotnet core ?
Thank you !
tar.Z is an archive file that can be created with the help of the UNIX compress
utility. Its files are compressed into a tarball (.tar) and then further compressed by use of the now rather antiquated 80s compression algorithm known as LZW.
You can extract these packages with help of the popular SharpZipLib library.
Here's an example of how to open the TAZ file and then write the TAR file it contains to disk. You can of course extract the TAR file in memory right away if the file is feasible in size to be kept in memory in its entirety.
using (var inputStream = File.Open(PATH_TO_TARZ_FILE, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (var tazStream = new LzwInputStream(inputStream))
{
using (var outputStream = PATH_TO_OUTPUT_TAR_FILE, 4096))
{
tazStream.CopyTo(outputStream);
}
}
}
I found a workaround by using the UNIX command line "gunzip"
gunzip myfilename.taz
gunzip works with files with the following extensions : .gz, -gz, .z, -z, _z or .Z (and also recognizes the special extensions .tgz and .taz as shorthands for .tar.gz and .tar.Z respectively.)
To run this process, I wrote the following code :
public string ExtractFileFromTaz (string tazFilePath)
{
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "gunzip",
Arguments = tazFilePath,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return result;
}
The resulting output is the file with the .tar extension, which replaced the original .taz file in the same directory.