Table of Contents

Method OfStreamAsync

Namespace
Qavren.Edge.Ingestion
Assembly
Qavren.Edge.Ingestion.dll

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

stream Stream

The stream to hash. Read from its current position.

maxBytes long

The source-byte ceiling. Non-negative.

bufferSize int

The read block. 64 KiB by default.

ct CancellationToken

Cancels the read.

Returns

ValueTask<ContentHash?>

The hash, or null when the stream is over the ceiling.