diff --git a/src/SharpCompress/Archives/IArchiveExtensions.cs b/src/SharpCompress/Archives/IArchiveExtensions.cs
index 51e07693..2a504b39 100644
--- a/src/SharpCompress/Archives/IArchiveExtensions.cs
+++ b/src/SharpCompress/Archives/IArchiveExtensions.cs
@@ -26,54 +26,53 @@ public static class IArchiveExtensions
}
///
- /// Extracts the archive to the destination directory in the thread pool. Directories will be created as needed.
+ /// Extracts the archive to the destination directory. Directories will be created as needed.
///
/// The archive to extract.
/// The folder to extract into.
/// Optional progress report callback.
- /// Optional cancellation token
- public static Task ExtractToDirectoryAsync(
+ /// Optional cancellation token.
+ public static void ExtractToDirectory(
this IArchive archive,
string destination,
Action? progressReport = null,
CancellationToken cancellationToken = default
- ) => Task.Run(() =>
- {
- // Prepare for progress reporting
- var totalBytes = archive.TotalUncompressSize;
- var bytesRead = 0L;
+ )
+ {
+ // Prepare for progress reporting
+ var totalBytes = archive.TotalUncompressSize;
+ var bytesRead = 0L;
- // Tracking for created directories.
- var seenDirectories = new HashSet();
+ // Tracking for created directories.
+ var seenDirectories = new HashSet();
- // Extract
- var entries = archive.ExtractAllEntries();
- while (entries.MoveToNextEntry())
- {
- cancellationToken.ThrowIfCancellationRequested();
+ // Extract
+ var entries = archive.ExtractAllEntries();
+ while (entries.MoveToNextEntry())
+ {
+ cancellationToken.ThrowIfCancellationRequested();
- var entry = entries.Entry;
- if (entry.IsDirectory)
- {
- continue;
- }
+ var entry = entries.Entry;
+ if (entry.IsDirectory)
+ {
+ continue;
+ }
- // Create each directory
- var path = Path.Combine(destination, entry.Key);
- if (Path.GetDirectoryName(path) is { } directory
- && seenDirectories.Add(path))
- {
- Directory.CreateDirectory(directory);
- }
+ // Create each directory
+ var path = Path.Combine(destination, entry.Key);
+ if (Path.GetDirectoryName(path) is { } directory
+ && seenDirectories.Add(path))
+ {
+ Directory.CreateDirectory(directory);
+ }
- // Write file
- using var fs = File.OpenWrite(path);
- entries.WriteEntryTo(fs); // TODO: Some day, this may be async.
+ // Write file
+ using var fs = File.OpenWrite(path);
+ entries.WriteEntryTo(fs);
- // Update progress
- bytesRead += entry.Size;
- progressReport?.Invoke(bytesRead / (double)totalBytes);
- }
- },
- cancellationToken);
+ // Update progress
+ bytesRead += entry.Size;
+ progressReport?.Invoke(bytesRead / (double)totalBytes);
+ }
+ }
}