hexo/node_modules/hexo-deployer-cos-cdn/lib/util.js

29 lines
613 B
JavaScript
Raw Normal View History

2023-09-25 15:58:56 +08:00
'use strict';
const crypto = require('crypto');
let md5 = function (str, encoding) {
return crypto.createHash('md5').update(str).digest(encoding || 'hex');
};
let getFileMd5 = function (readStream, callback) {
let md5 = crypto.createHash('md5');
readStream.on('data', function (chunk) {
md5.update(chunk);
});
readStream.on('error', function (err) {
callback(err);
});
readStream.on('end', function () {
let hash = md5.digest('hex');
callback(null, hash);
});
};
let util = {
md5: md5,
getFileMd5: getFileMd5,
};
module.exports = util;