make zip unpacking and saving data to storage
This commit is contained in:
parent
c6a0b39ded
commit
297a784956
7 changed files with 78 additions and 12 deletions
|
|
@ -30,9 +30,29 @@ public class ZipScrapper
|
|||
// }
|
||||
}
|
||||
|
||||
public static string ExtractZip(ZipArchive archive, string outputPath)
|
||||
public static string ExtractZip(ZipArchive archive, string outputPath, IProgress<double>? progress = null)
|
||||
{
|
||||
archive.ExtractToDirectory(outputPath);
|
||||
var entries = archive.Entries.Where(e => !string.IsNullOrEmpty(e.Name)).ToList();
|
||||
var totalEntries = entries.Count;
|
||||
var processedEntries = 0;
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
var destinationPath = Path.Combine(outputPath, entry.FullName);
|
||||
var destinationDir = Path.GetDirectoryName(destinationPath);
|
||||
|
||||
if (!string.IsNullOrEmpty(destinationDir))
|
||||
{
|
||||
Directory.CreateDirectory(destinationDir);
|
||||
Console.WriteLine($"Extracting {entry.FullName} to {destinationPath}");
|
||||
}
|
||||
|
||||
entry.ExtractToFile(destinationPath, overwrite: true);
|
||||
|
||||
processedEntries++;
|
||||
progress?.Report((double)processedEntries / totalEntries * 100);
|
||||
}
|
||||
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue