ElwigData: Check zip file integrity
All checks were successful
Test / Run tests (push) Successful in 1m59s

This commit is contained in:
2025-08-06 12:31:19 +02:00
parent 73fe4531cc
commit d3157e4d48
5 changed files with 21 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.IO.Compression;
using System.IO.Hashing;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Threading;
@@ -95,5 +97,16 @@ namespace Elwig.Helpers {
await download.CopyToAsync(destination, 81920, relativeProgress, cancellationToken);
progress.Report(100.0);
}
public static async Task CheckIntegrity(this ZipArchive zip) {
var crc = new Crc32();
foreach (var entry in zip.Entries) {
crc.Reset();
using var stream = entry.Open();
await crc.AppendAsync(stream);
if (crc.GetCurrentHashAsUInt32() != entry.Crc32)
throw new InvalidDataException($"CRC-32 mismatch in '{entry.FullName}'");
}
}
}
}