@דניאל שטרית, thanks for the feedback, based on my test, I find use ZipArchiveEntry.ExtractToFile method will be faster than the ZipFile.ExtractToDirectory method.
Here is a code example you could refer to.
static void Main(string[] args)
{
string zipapth = @"B:\Test.zip";
string destination1 = @"B:\a";
string destination2 = @"B:\b";
Stopwatch stopwatch1=new Stopwatch();
Stopwatch stopwatch2= new Stopwatch();
stopwatch1.Start();
FirstMethod(zipapth, destination1);
stopwatch1.Stop();
stopwatch2.Start();
SecondMethod(zipapth, destination2);
stopwatch2.Stop();
Console.WriteLine( stopwatch1.ElapsedMilliseconds);
Console.WriteLine( stopwatch2.ElapsedMilliseconds);
Console.ReadKey();
}
static void FirstMethod(string zippath,string destination)
{
ZipFile.ExtractToDirectory(zippath,destination);
}
public static void SecondMethod(string sourceArchive, string destinationDirectoryName)
{
if (!Directory.Exists(destinationDirectoryName))
{
Directory.CreateDirectory(destinationDirectoryName);
}
var entries = ZipFile.Open(sourceArchive, ZipArchiveMode.Read).Entries;
foreach (ZipArchiveEntry entry in entries)
{
string path = Path.Combine(destinationDirectoryName, entry.Name);
entry.ExtractToFile(path);
}
}
Result:
As the result is shown, the second method is faster than the first method.
Hope my solution could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.