Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created February 1, 2026 13:10
Show Gist options
  • Select an option

  • Save wullemsb/1825ad693bcfc1fa363824fa24109106 to your computer and use it in GitHub Desktop.

Select an option

Save wullemsb/1825ad693bcfc1fa363824fa24109106 to your computer and use it in GitHub Desktop.
using System.Security.Cryptography;
using System.Threading.Tasks.Dataflow;
// The recursive block: takes a folder path, returns all entries inside it.
// TransformManyBlock is ideal here because one folder produces many entries.
var getFolderContents = new TransformManyBlock<string, string>(folder =>
{
return Directory.GetFileSystemEntries(folder);
});
// Computes the MD5 hash of a file and pairs it with the filename.
var computeMD5 = new TransformBlock<string, (string FilePath, string Hash)>(filePath =>
{
using var md5 = MD5.Create();
using var stream = File.OpenRead(filePath);
var hashBytes = md5.ComputeHash(stream);
var hash = BitConverter.ToString(hashBytes).Replace("-", "");
return (filePath, hash);
});
// Displays the result.
var displayResult = new ActionBlock<(string FilePath, string Hash)>(result =>
{
Console.WriteLine($"{result.Hash} {Path.GetFileName(result.FilePath)}");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment