UNPKG

1.8 kBTypeScriptView Raw
1import { Transform } from 'stream';
2import { CRC32CValidatorGenerator, CRC32CValidator } from './crc32c.js';
3interface HashStreamValidatorOptions {
4 /** Enables CRC32C calculation. To validate a provided value use `crc32cExpected`. */
5 crc32c: boolean;
6 /** Enables MD5 calculation. To validate a provided value use `md5Expected`. */
7 md5: boolean;
8 /** A CRC32C instance for validation. To validate a provided value use `crc32cExpected`. */
9 crc32cInstance: CRC32CValidator;
10 /** Set a custom CRC32C generator. Used if `crc32cInstance` has not been provided. */
11 crc32cGenerator: CRC32CValidatorGenerator;
12 /** Sets the expected CRC32C value to verify once all data has been consumed. Also sets the `crc32c` option to `true` */
13 crc32cExpected?: string;
14 /** Sets the expected MD5 value to verify once all data has been consumed. Also sets the `md5` option to `true` */
15 md5Expected?: string;
16 /** Indicates whether or not to run a validation check or only update the hash values */
17 updateHashesOnly?: boolean;
18}
19declare class HashStreamValidator extends Transform {
20 #private;
21 readonly crc32cEnabled: boolean;
22 readonly md5Enabled: boolean;
23 readonly crc32cExpected: string | undefined;
24 readonly md5Expected: string | undefined;
25 readonly updateHashesOnly: boolean;
26 constructor(options?: Partial<HashStreamValidatorOptions>);
27 /**
28 * Return the current CRC32C value, if available.
29 */
30 get crc32c(): string | undefined;
31 _flush(callback: (error?: Error | null | undefined) => void): void;
32 _transform(chunk: Buffer, encoding: BufferEncoding, callback: (e?: Error) => void): void;
33 test(hash: 'crc32c' | 'md5', sum: Buffer | string): boolean;
34}
35export { HashStreamValidator, HashStreamValidatorOptions };