I need to extract the content of a zipfile to an SD-card.
ZipFile.ExtractToDirectory(@"D:\RcCardData.zip", this.selectedDrive);
Works like a charm. However I was wondering if this uses the Write-cache of the disk. If yes, is there a way to ensure that all of the data is written to the card before I tell the user he can remove it?
At first I've tried using code to "safe remove" the SD-card but the problem here was that it was ejecting the whole USB card-reader and not just the card.
UPDATE
I've done some extra research on this matter.
When looking at the code for ExtractToDirectory
via dotPeek it boils down to the following method:
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);
}
And since a Dispose() is executed on the stream when exiting the using-block, the stream is Close()
-d and Flush()
-ed.
Now I've recently read somewhere that since .Net 4.0
the write cache is emptied when executing a flush (not sure about this)?
With the extra information given above, can someone tell me if it's safe to remove the SD-card when the extraction is completed?