I was looking for a solution to read one or more files from a .tgz or .tar.gz archive using C # without having to extract the files to disk.
I have identified several third-party libraries published under the GNU licenses that allow someone to extract the .tgz archive, but did not manage to find a solution to read the file without first extracting it.
If possible, I would like to stick with the standard libraries - does anyone have a solution using GZipStream or any other / s method? Thanks!
EDIT:
I would like to implement something similar to the following:
public static void Decompress2(FileInfo fileToDecompress)
{
using (FileStream fileStream = fileToDecompress.OpenRead())
{
using (var memStream = new MemoryStream())
{
string currentFileName = fileToDecompress.FullName;
string newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);
using (FileStream decompressedFileStream = File.Create(newFileName))
{
using (GZipStream decompressionStream = new GZipStream(fileStream, CompressionMode.Decompress))
{
byte[] bytes = new byte[4096];
int n;
while ((n = decompressionStream.Read(bytes, 0, bytes.Length)) != 0)
{
memStream.Write(bytes, 0, n);
}
}
}
}
}
}
.tgz .tar.gz . . .gz, , .tar .