UNPKG

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