This project contains useful pipeline wrappers and utilities.
dotnet add package StepWise.IO.Pipelines
HashPipeReader and HashPipeWriter compute incremental hash sums on the data passing through the wrapped pipe.
HashPipeReader incrementally computes the hash on examined data.
This can be useful for computing etags or other data fingerprints.
var buffer = new byte[4098];
var rnd = new Random();
rnd.NextBytes(buffer);
var pipe = new Pipe();
pipe.Writer.Write(buffer);
await pipe.Writer.FlushAsync();
// ♫ I've got my hash pipe ♫
var hashPipe = pipe.Reader.HashPipe(HashAlgorithmName.SHA256);
var result = await hashPipe.ReadAtLeastAsync(size);
hashPipe.AdvanceTo(result.Buffer.End, result.Buffer.End);
string hash = Convert.ToHexString(hashPipe.GetHash());