Table of Contents

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

stream Stream

The stream to hash.

algorithm HashAlgorithm

The hash algorithm to use.

cancellationToken CancellationToken

Cancellation 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 stream is 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

filePath string

The path to the file to hash.

algorithm HashAlgorithm

The hash algorithm to use.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<HashedFile>>

A result containing the hash information on success, or an error on failure.

Exceptions

ArgumentNullException

Thrown when filePath is null.

ArgumentException

Thrown when filePath is empty or whitespace.

OperationCanceledException

Thrown when the operation is cancelled.