From 295a477e77c4a7cba4cd6ae4c6862b2df12483d8 Mon Sep 17 00:00:00 2001 From: Fidel <15338956+fiddyschmitt@users.noreply.github.com> Date: Sun, 7 Apr 2024 21:58:57 +1000 Subject: [PATCH] Support hashing files larger than 2 GB --- clonezilla-util_tests/Mount/TestUtility.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clonezilla-util_tests/Mount/TestUtility.cs b/clonezilla-util_tests/Mount/TestUtility.cs index 41d1e8a..0e28d7c 100644 --- a/clonezilla-util_tests/Mount/TestUtility.cs +++ b/clonezilla-util_tests/Mount/TestUtility.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Drawing; +using System.IO.MemoryMappedFiles; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -34,10 +36,20 @@ public static void ConfirmFilesExist(string exeUnderTest, string args, IEnumerab bool fileIsAsExpected = false; if (File.Exists(expectedFile.FullPath)) { + //slow //var md5 = libCommon.Utility.CalculateMD5(expectedFile.FullPath); + + //doesn't support files larger than 2 GB + /* using var ms = new MemoryStream(); using var fs = File.OpenRead(expectedFile.FullPath); fs.CopyTo(ms, 10 * 1024 * 1024); + */ + + using var fs = File.OpenRead(expectedFile.FullPath); + using var memoryMappedFile = MemoryMappedFile.CreateNew(mapName: null, fs.Length); + using var ms = memoryMappedFile.CreateViewStream(); + fs.CopyTo(ms, 10 * 1024 * 1024); var md5 = libCommon.Utility.CalculateMD5(ms);