Skip to content

Commit

Permalink
Support hashing files larger than 2 GB
Browse files Browse the repository at this point in the history
  • Loading branch information
fiddyschmitt committed Apr 7, 2024
1 parent 3f48e04 commit 295a477
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions clonezilla-util_tests/Mount/TestUtility.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 295a477

Please sign in to comment.