我需要将 zipfile 的内容提取到 SD 卡中。
ZipFile.ExtractToDirectory(@"D:\RcCardData.zip", this.selectedDrive);
奇迹般有效。但是我想知道这是否使用磁盘的写入缓存。如果是,在我告诉用户他可以删除它之前,有没有办法确保所有数据都写入卡?
起初,我尝试使用代码“安全移除”SD 卡,但这里的问题是它弹出了整个 USB 读卡器,而不仅仅是卡。
更新
我对这个问题做了一些额外的研究。
查看ExtractToDirectory
通过dotPeek的代码时,可以归结为以下方法:
public static void ExtractToFile(this ZipArchiveEntry source, string destinationFileName, bool overwrite)
{
if (source == null)
throw new ArgumentNullException("source");
if (destinationFileName == null)
throw new ArgumentNullException("destinationFileName");
FileMode mode = overwrite ? FileMode.Create : FileMode.CreateNew;
using (Stream destination = (Stream) File.Open(destinationFileName, mode, FileAccess.Write, FileShare.None))
{
using (Stream stream = source.Open())
stream.CopyTo(destination);
}
File.SetLastWriteTime(destinationFileName, source.LastWriteTime.DateTime);
}
并且由于在退出 using 块时在流上执行 Dispose(),因此流是Close()
-d 和Flush()
-ed。
现在我最近在某处读到,因为.Net 4.0
执行刷新时写缓存被清空(不确定)?
有了上面给出的额外信息,有人能告诉我提取完成后取出 SD 卡是否安全吗?