.NET ZipArchive
类似乎没有正确存储条目的LastWriteTime
值。我知道文件格式只允许两秒钟的分辨率。但更重要的是,它似乎也降低了偏移量。例如:
var now = DateTimeOffset.UtcNow;
var stream = new MemoryStream();
using(var zipCreateArchive = new ZipArchive(stream,
ZipArchiveMode.Create, true))
{
var entry = zipCreateArchive.CreateEntry("Test");
entry.LastWriteTime = now;
using(var writer = new StreamWriter(entry.Open()))
writer.WriteLine("This is a test");
}
stream.Seek(0, SeekOrigin.Begin);
using(var zipReadArchive = new ZipArchive(stream, ZipArchiveMode.Read))
{
foreach(var entry in zipReadArchive.Entries)
System.Diagnostics.Debug.WriteLine(entry.LastWriteTime);
}
创建后,LastWriteTime
的偏移量为零。但是当你读取该值时,它现在具有非零偏移量,因为(显然)它采用本地时区。我似乎无法在任何地方找到ZipArchive源,所以我无法证明这是正在发生的事情。关于如何正确存储LastWriteTime
?