Search code examples
c#.net-coregzipgzipstream

How To Find Out The Original Filename From A GZIP File In C# .Net Core Which Has Been Renamed


I am downloading a gzipped file from a web source and I can see from the microsoft docs (https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.gzipstream?view=net-7.0) that it is fairly simple to decompress a gzip, but there doesn't seem to be a way to get the original filename.

I understand that gzips don't have to store the original filename, but there is provision for doing so in the headers and I can see that in this case, the filename is likely to be in there as I can see it if I open the archive in 7Zip.

Is there a simple way in .net core to get the original filename or is the only option to somehow manually decode the gzip file headers?

(I did see a stackoverflow question like this which was self-answered, but it was from 2010 and I am wondering if anything has changed since then)


Solution

  • It appears that the only option is to manually decode the gzip header. However the header format is quite simple, so this would be easy and straightforward to implement. See RFC 1952 for the specification.