import crypto, { BinaryToTextEncoding } from 'crypto'; import { IOFail } from '@spinajs/exceptions'; import { FileHasher } from './interfaces.js'; /** * Default {@link FileHasher} implementation backed by node's `crypto` module. * * The algorithm is fixed per instance and provided as the first constructor * argument ( eg. `DI.resolve(FileHasher, ['md5'])` ). When no algorithm is * given it falls back to the value configured under `fs.hasher.defaultAlgorithm`, * and finally to {@link DEFAULT_ALGORITHM} ( sha256 ). * * Instances are cached per algorithm and hash options via {@link PerInstanceCheck} / * {@link __checkInstance__}, so resolving the same arguments twice reuses the * same hasher while different ones get distinct instances. */ export declare class DefaultFileHasher extends FileHasher { Algorithm?: string | undefined; HashOptions?: crypto.HashOptions | undefined; /** * Default algorithm read from configuration ( `fs.hasher.defaultAlgorithm` ), * falling back to {@link DEFAULT_ALGORITHM} when the key is not set. * * Exposed as a lazily evaluated config property so both the constructor and * {@link __checkInstance__} resolve the default the same way. */ protected ConfiguredAlgorithm: string; /** * Per-instance cache predicate used by {@link PerInstanceCheck}. * * Returns `true` when this instance was created for the algorithm and hash * options requested in `creationOptions`. The requested algorithm is resolved * exactly like the constructor does ( explicit arg, else the configured * default ), so cached instances match reliably. * * @param creationOptions constructor arguments the container is resolving with */ __checkInstance__(creationOptions: any): boolean; /** * @param Algorithm hash algorithm to use ( eg. `sha256`, `md5` ). When omitted, * the configured default ( `fs.hasher.defaultAlgorithm` ) or * sha256 is used. * @param HashOptions optional node `crypto` hash options ( eg. `outputLength` * for XOF algorithms such as shake256 ) */ constructor(Algorithm?: string | undefined, HashOptions?: crypto.HashOptions | undefined); /** * Creates a `crypto.Hash` for the configured algorithm. * * The algorithm is validated against the platform's supported hashes first so * an unsupported/typo'd algorithm produces a clear {@link IOFail} instead of a * cryptic native crypto error. * * @throws {IOFail} when the configured algorithm is not supported */ protected createHasher(): crypto.Hash; /** * Hashes the content of a file by streaming it through the hash. * * @param pathToFile absolute path to the file to hash * @param encoding digest output encoding ( default `hex` ) * @returns the digest string in the requested encoding * @throws {IOFail} when the file does not exist, the algorithm is unsupported, * or the file cannot be read */ hash(pathToFile: string, encoding?: BinaryToTextEncoding): Promise; /** * Consumes a readable stream through a fresh hasher and resolves with the * digest. Stream errors are wrapped by `wrapError` so file and raw-stream * callers surface their own context. */ protected digestStream(stream: NodeJS.ReadableStream, encoding: BinaryToTextEncoding, wrapError: (err: Error) => IOFail): Promise; /** * Hashes raw in-memory data. * * @param data string or binary data to hash * @param encoding digest output encoding ( default `hex` ) * @returns the digest string in the requested encoding * @throws {IOFail} when the configured algorithm is unsupported */ hashData(data: string | Uint8Array, encoding?: BinaryToTextEncoding): Promise; /** * Hashes the content of a readable stream by consuming it to the end. * * @param stream readable stream to consume * @param encoding digest output encoding ( default `hex` ) * @returns the digest string in the requested encoding * @throws {IOFail} when the configured algorithm is unsupported or the stream errors */ hashStream(stream: NodeJS.ReadableStream, encoding?: BinaryToTextEncoding): Promise; } //# sourceMappingURL=file-hasher.d.ts.map