Skip to content

Instantly share code, notes, and snippets.

@AnthonyGiretti
Created January 7, 2026 20:08
Show Gist options
  • Select an option

  • Save AnthonyGiretti/9d2aaf64b6824350a1b54801121618bc to your computer and use it in GitHub Desktop.

Select an option

Save AnthonyGiretti/9d2aaf64b6824350a1b54801121618bc to your computer and use it in GitHub Desktop.
.NET 10 ZipExtractor better async performances
using System;
using System.IO;
using System.IO.Compression;
using System.Threading;
using System.Threading.Tasks;
public static class ZipExtractor
{
public static async Task ExtractZipAsync(
string zipPath,
string destination,
CancellationToken ct = default)
{
Directory.CreateDirectory(destination);
await using var fs = File.OpenRead(zipPath);
using var archive = new ZipArchive(fs, ZipArchiveMode.Read, leaveOpen: false);
foreach (var entry in archive.Entries)
{
// Skip directory entries
if (string.IsNullOrEmpty(entry.Name))
continue;
string outPath = Path.Combine(destination, entry.FullName);
Directory.CreateDirectory(Path.GetDirectoryName(outPath)!);
await using var entryStream = entry.Open();
await using var outStream = File.Create(outPath);
// Asynchronous copy avoids blocking the calling thread
await entryStream.CopyToAsync(outStream, ct);
Console.WriteLine($"Extracted: {entry.FullName}");
}
}
}
// Usage:
// No code changes with .NET 10, only better performances
await ZipExtractor.ExtractZipAsync("sample.zip", "./out", CancellationToken.None);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment