/** * WHATWG Streams support for browser environments * Provides streaming MD5 hashing for ReadableStream, File, and Blob objects */ /** * Result type for MD5 computation */ interface MD5Result { /** * MD5 hash as hex string */ digest: string; /** * Number of bytes processed */ bytesProcessed: number; } /** * Interface for WHATWG Streams MD5 options */ interface MD5ReadableStreamOptions { /** * Custom add32 function for compatibility testing */ add32?: (x: number, y: number) => number; } /** * Internal state interface for MD5 computation */ interface MD5State { state: number[]; bytesProcessed: number; bufferLength: number; buffer: Uint8Array; } /** * MD5ReadableStream - Wrapper for computing MD5 hashes while reading from a ReadableStream * * This class wraps a ReadableStream and computes MD5 hash while reading data. * It follows the ReadableStream API pattern for browser environments. */ declare class MD5ReadableStream { private sourceStream; private state; private add32; private result; private resultResolver; private resultPromise; private consumed; private readonly bufferCapacity; private buffer; /** * Create new MD5ReadableStream instance * @param source - Source ReadableStream to hash * @param options - Stream options */ constructor(source: ReadableStream, options?: MD5ReadableStreamOptions); /** * Get a reader for this stream * @returns ReadableStreamDefaultReader */ getReader(): ReadableStreamDefaultReader; /** * Process a data chunk and update MD5 state * @param chunk - Data chunk (ArrayBuffer or Uint8Array) */ private processChunk; /** * Process the current buffer as a complete block */ private _processBufferBlock; /** * Finalize MD5 computation */ private finalize; /** * Get the MD5 result promise * @returns Promise with MD5 result */ getResult(): Promise; /** * Get current MD5 state (for debugging/testing) * @returns Current internal state */ getCurrentState(): { state: number[]; bytesProcessed: number; }; /** * Get bytes processed so far * @returns Number of bytes processed */ getBytesProcessed(): number; /** * Static method to hash a ReadableStream and return MD5 result * @param source - Source ReadableStream to hash * @param options - Stream options * @returns Promise with MD5 result */ static hash(source: ReadableStream, options?: MD5ReadableStreamOptions): Promise; /** * Static method to hash a File object * @param file - File object to hash * @param options - Stream options * @returns Promise with MD5 result */ static hashFile(file: File, options?: MD5ReadableStreamOptions): Promise; /** * Static method to hash a Blob object * @param blob - Blob object to hash * @param options - Stream options * @returns Promise with MD5 result */ static hashBlob(blob: Blob, options?: MD5ReadableStreamOptions): Promise; } /** * Factory function to create MD5ReadableStream instance * @param source - Source ReadableStream to hash * @param options - Stream options * @returns New MD5ReadableStream instance */ declare function createMD5ReadableStream(source: ReadableStream, options?: MD5ReadableStreamOptions): MD5ReadableStream; /** * Hash a ReadableStream and return MD5 result * @param stream - ReadableStream to hash * @param options - Stream options * @returns Promise with MD5 result (digest and bytes processed) * * @example * ```ts * import { hashReadableStream } from 'pure-md5'; * * const response = await fetch('https://example.com/file.txt'); * const result = await hashReadableStream(response.body!); * console.log('MD5:', result.digest); * console.log('Bytes:', result.bytesProcessed); * ``` */ declare function hashReadableStream(stream: ReadableStream, options?: MD5ReadableStreamOptions): Promise; /** * Hash a File object and return MD5 result * @param file - File object to hash * @param options - Stream options * @returns Promise with MD5 result * * @example * ```ts * import { hashFile } from 'pure-md5'; * * const input = document.querySelector('input[type="file"]'); * input.addEventListener('change', async (e) => { * const file = (e.target as HTMLInputElement).files![0]; * const result = await hashFile(file); * console.log('MD5:', result.digest); * }); * ``` */ declare function hashFile(file: File, options?: MD5ReadableStreamOptions): Promise; /** * Hash a Blob object and return MD5 result * @param blob - Blob object to hash * @param options - Stream options * @returns Promise with MD5 result * * @example * ```ts * import { hashBlob } from 'pure-md5'; * * const canvas = document.querySelector('canvas'); * canvas.toBlob(async (blob) => { * const result = await hashBlob(blob!); * console.log('MD5:', result.digest); * }); * ``` */ declare function hashBlob(blob: Blob, options?: MD5ReadableStreamOptions): Promise; /** * Consume a ReadableStream while computing MD5 * @param source - Source ReadableStream to consume and hash * @param options - Stream options * @returns Promise with MD5 result */ declare function consumeWithMD5(source: ReadableStream, options?: MD5ReadableStreamOptions): Promise; export { MD5ReadableStream, type MD5ReadableStreamOptions, type MD5Result, type MD5State, consumeWithMD5, createMD5ReadableStream, hashBlob, hashFile, hashReadableStream };