0

I’m trying to decompress a compress file with multiple files on it

the following code works to .tgz files, but don’t for .tar.gz files

What is wrong here?

FileInfo infoCompressed = new FileInfo(compressedFilePath);
DirectoryInfo destinyDir = new DirectoryInfo(infoCompressed.Directory.ToString());

if (!destinyDir.Exists)
     destinyDir.Create();

using(Stream originFile = new GZipInputStream(infoCompressed.OpenRead()))
{
     using(TarArchive tarFile = TarArchive.CreateInputTarArchive(originFile, TarBuffer.DefaultBlockFactor, Encoding.Default))
     {
          tarFile.ExtractContents(destinyDir.FullName);
     }
}
ErikEJ
  • 40,951
  • 5
  • 75
  • 115
  • `.tgz` is the DOS-style extension for `.tar.gz` files, so it should be the same. Do you know what software created the `.tar.gz` files? – Corey Feb 08 '22 at 22:05
  • Hi Erik, the .tar.gz file is created by an internal application. Is not created by an user manually – Arnell Vasquez C Feb 09 '22 at 13:42
  • Additionally, I can decompress the .tar.gz file if I use whatever commercial application to do this work. That is to say, the file is not corrupt – Arnell Vasquez C Feb 09 '22 at 14:13
  • Sounds like you have a gzip-like compression that isn't literal gzip. DEFLATE or zlib would be my guess. Can you grab out the first 16 bytes of the file as hex values for me? It might show what format is actually in use here. – Corey Feb 10 '22 at 00:13
  • Nope, scratch that. Plain zlib or DEFLATE don't work with other gzip code. And since your code looks fine there's something else going on. Have you tried `System.IO.Compression.GZipStream` instead of `GZipInputStream`? – Corey Feb 10 '22 at 01:39

0 Answers0