ElwigData: Check zip file integrity
All checks were successful
Test / Run tests (push) Successful in 1m59s
All checks were successful
Test / Run tests (push) Successful in 1m59s
This commit is contained in:
@@ -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}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user