0

using SharpZipLib in C#, I'm using:

// ..
ZipEntry entry = new ZipEntry(Path.GetFileName(files[i].fullfilename));
entry.DateTime =files[i].datemodified //has everything including milliseconds
//.. some more code which i'm not writing

The zip file gets created just fine, but when i unzip it using any 3rd party decompresser, I see that the file has lost its milliseconds information in the file's modified date (milliseconds info is very important to me). I saw the code for ZipEntry, and its DateTime property: https://github.com/icsharpcode/SharpZipLib/blob/c49a22d70a77819b1dc88309c91e99565aa9099b/src/Zip/ZipEntry.cs#L695

you see that what gets written in the zip file as a datetime for this entry is: https://github.com/icsharpcode/SharpZipLib/blob/c49a22d70a77819b1dc88309c91e99565aa9099b/src/Zip/ZipOutputStream.cs#L344 which is a int cast of the ms dos format time. Can someone please help tell me how do I write this so that the final zipped file contains everything in its modified datetime that was in my original DateTime that I got from "LastWriteTime" of fileinfo.

Thanks.

Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
user734028
  • 1,021
  • 1
  • 9
  • 21
  • I just switched to https://dotnetzip.codeplex.com/ and this seems to be preserving the datetime much better so far, i hope it doesnt have any other drawbacks. there seems to be a bit of a problem with its AddProgress event, but maybe its a bug in my code. – user734028 Mar 28 '15 at 07:53

2 Answers2

0

You can read the zip specification for how to include a Unix extra field with the times down to the second. I am not aware of a defined extra field that carries millisecond information, so you would have to create your own, and write your own zipper and unzipper to process it.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
0

The only way (known to me) to store millisecond information is by using NTFS extra field. However, you'll need to learn how to write this field according to PKWARE specification. And there is no guarantee that third-party decompressor will support it (most likely it will not).

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48
  • would you recommend any other zipping library that can do this? have you used 7zip .net wrappers that can do this? – user734028 Mar 27 '15 at 17:38
  • I didn't use any other libraries, I just participated in development of commercial one for EldoS (https://www.eldos.com/sbb/). However, there is no support for NTFS extended attribute as well. Probably you can ask on their forum for it, if you plan to buy the library. – Nickolay Olshevsky Mar 28 '15 at 13:43
  • Probably, it would be easier for you to store file times in extra file in archive. – Nickolay Olshevsky Mar 28 '15 at 13:44