Method OfStreamAsync
OfStreamAsync(Stream, long, int, CancellationToken)
Spec 9.1's counted read. Streams stream in
bufferSize blocks, carries a running byte count, and returns
null the moment the count exceeds maxBytes.
A null result is NOT a hash of a truncated read and must never be persisted as one: storing
the hash of a partial read would make a later shrink of the file look unchanged. At most
maxBytes + bufferSize bytes are ever read and nothing is buffered.
public static ValueTask<ContentHash?> OfStreamAsync(Stream stream, long maxBytes, int bufferSize = 65536, CancellationToken ct = default)
Parameters
streamStreamThe stream to hash. Read from its current position.
maxByteslongThe source-byte ceiling. Non-negative.
bufferSizeintThe read block. 64 KiB by default.
ctCancellationTokenCancels the read.
Returns
- ValueTask<ContentHash?>
The hash, or null when the stream is over the ceiling.