1 | "use strict";
|
2 |
|
3 | const crypto = require('crypto');
|
4 |
|
5 | const fs = require('fs');
|
6 |
|
7 | function md5(string, encoding = 'hex') {
|
8 | return crypto.createHash('md5').update(string).digest(encoding);
|
9 | }
|
10 |
|
11 | md5.file = function (filename) {
|
12 | return new Promise((resolve, reject) => {
|
13 | fs.createReadStream(filename).on('error', reject).pipe(crypto.createHash('md5').setEncoding('hex')).on('finish', function () {
|
14 | resolve(this.read());
|
15 | });
|
16 | });
|
17 | };
|
18 |
|
19 | module.exports = md5; |
\ | No newline at end of file |