UNPKG

463 BJavaScriptView Raw
1"use strict";
2
3const crypto = require('crypto');
4
5const fs = require('fs');
6
7function md5(string, encoding = 'hex') {
8 return crypto.createHash('md5').update(string).digest(encoding);
9}
10
11md5.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
19module.exports = md5;
\No newline at end of file