using System.Security.Cryptography; namespace AIStudio.Tools; /// /// Computes the hash of the content of a file. /// internal static class FileContentHash { /// /// Computes a lowercase SHA-256 hash for a file without loading it fully into memory. /// /// The file path. /// The cancellation token. /// The lowercase hexadecimal hash. internal static async Task ComputeAsync(string path, CancellationToken token) { await using var stream = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read, 65_536, FileOptions.Asynchronous | FileOptions.SequentialScan); return Convert.ToHexStringLower(await SHA256.HashDataAsync(stream, token)); } }