1
/**
2
 * @author WMXPY
3
 * @namespace Internal
4
 * @description Hash
5
 */
6

7 3
import * as Crypto from "crypto";
8 3
import * as Fs from "fs";
9

10 3
export const md5File = (path: Fs.PathLike): Promise<string> =>
11 0
    new Promise<string>((resolve: (result: string) => void, reject: (reason: Error) => void) => {
12

13 0
        const readStream: Fs.ReadStream = Fs.createReadStream(path);
14 0
        const hash: Crypto.Hash = Crypto.createHash('md5');
15

16 0
        readStream.on('data', hash.update.bind(hash));
17 0
        readStream.on('end', () => {
18 0
            resolve(hash.digest('hex'));
19
        });
20 0
        readStream.on('error', (error: Error) => {
21 0
            reject(error);
22
        });
23
    });
24

25 3
export const md5String = (target: string): string => {
26

27 3
    const hash: Crypto.Hash = Crypto.createHash('md5');
28

29 3
    hash.update(target);
30 3
    return hash.digest('hex');
31
};

Read our documentation on viewing source code .

Loading