Interface IFileHashingService
- Namespace
- CivitaiSharp.Tools.Hashing
- Assembly
- CivitaiSharp.Tools.dll
Service responsible for computing cryptographic hashes for files and streams.
public interface IFileHashingService
Methods
ComputeHashAsync(Stream, HashAlgorithm, CancellationToken)
Computes the hash of the data available in the provided stream.
Task<Result<HashedFile>> ComputeHashAsync(Stream stream, HashAlgorithm algorithm, CancellationToken cancellationToken = default)
Parameters
streamStreamThe stream to hash.
algorithmHashAlgorithmThe hash algorithm to use.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<Result<HashedFile>>
A result containing the hash information on success, or an error on failure.
Remarks
The stream will be read to completion. Callers should assume the stream position is advanced to the end after this call.
For non-seekable streams, the reported file size in the result will be -1.
Exceptions
- ArgumentNullException
Thrown when
streamis null.- OperationCanceledException
Thrown when the operation is cancelled.
ComputeHashAsync(string, HashAlgorithm, CancellationToken)
Computes the hash of a file at the given path using the specified algorithm.
Task<Result<HashedFile>> ComputeHashAsync(string filePath, HashAlgorithm algorithm, CancellationToken cancellationToken = default)
Parameters
filePathstringThe path to the file to hash.
algorithmHashAlgorithmThe hash algorithm to use.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<Result<HashedFile>>
A result containing the hash information on success, or an error on failure.
Exceptions
- ArgumentNullException
Thrown when
filePathis null.- ArgumentException
Thrown when
filePathis empty or whitespace.- OperationCanceledException
Thrown when the operation is cancelled.