1

Decompressing gz file in c# has been asked and answered all over Internet, but thats not exactly what I'm looking for. I need a library that would give me:

1) the name of the file inside the gz file. 2) its modified time as it was in it originally where it came from.

Every example of gz decompression creates a filename that is gz's own filename minus the ".gz" extension, but thats not what I want. I want the filename that is inside the gz file, and I also want the modified date of it. Then when I decompress the file, I assign it the modified date that was meant to be, or the library do it for me.

But almost all examples I have seen, creates a new file, write the decompressed bytes, and close it, well of course it wont have that original modified date that belong it since it just got created and written to.

Can anyone help. I have used that dotnetzip and also the sharpziplibs their examples have the same problem and their forums don't have that answered.

eYe
  • 1,695
  • 2
  • 29
  • 54
user734028
  • 1,021
  • 1
  • 9
  • 21
  • I don't think gzip even *has* such a concept - what makes you think it does? – Jon Skeet Apr 07 '15 at 13:06
  • 1
    Ooh, according to https://www.ietf.org/rfc/rfc1952.txt it *might* be set - but that only supports ISO-8859-1, which is somewhat awful... – Jon Skeet Apr 07 '15 at 13:07
  • yea that MTIME stuff, i read about. You know the gz files that I have, if i decompress them using winrar, they have the good modified time in them, the one they had originally before they got compressed. I need to be able to do that in c# – user734028 Apr 07 '15 at 13:09
  • yes i can, can you point me to the docs. – user734028 Apr 07 '15 at 13:11
  • 1
    What was your problem with DotNetZip? The GZipStream iirc had LastModified I beleive? - http://dotnetzip.herobo.com/DNZHelp/html/4f608070-9922-7310-017f-aac469d1d9e0.htm – Lloyd Apr 07 '15 at 13:12
  • where on this planet is that property, i can see it on the github page of theirs but its just not there in the dll intellisense i'm using from their website. OR i am doing something really really wrong and embarrassing. – user734028 Apr 07 '15 at 13:24
  • i used source from here https://github.com/jstedfast/Ionic.Zlib, built it and tried the LastModified property but it doesnt work, it contains null after the decompression has been done. I traced the assignment of it to find out that it only is used during compression, not decompression. The version of the dll downloaded from here https://dotnetzip.codeplex.com/downloads/get/258012 doesnt even has a LastModified property in it. Namespaces are the same though. – user734028 Apr 07 '15 at 16:03

1 Answers1

0

zlib provides the inflateGetHeader() function which fills a structure with all of the information in the gzip header.

You can also just decode the header yourself, where the format is relatively simple. The gzip header and trailer format is documented in RFC 1952.

Community
  • 1
  • 1
Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • well i'll see, zlib will add a new dll to my project, i guess its ok to just open the file, seek to the mtime starting location (which probably is 5th byte), read 4 bytes from there and convert to datetime (sharpziplib does that I have seen it so i will use that source). Once i'm done i will update this post. – user734028 Apr 07 '15 at 16:10