UNPKG

1.09 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.md5FromString = md5FromString;
7exports.md5FromReadableStream = md5FromReadableStream;
8exports.md5FromObject = md5FromObject;
9exports.md5FromFilePath = md5FromFilePath;
10
11var _crypto = _interopRequireDefault(require("crypto"));
12
13var _collection = require("./collection");
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17function md5FromString(string, encoding = 'hex') {
18 return _crypto.default.createHash('md5').update(string).digest(encoding);
19}
20
21function md5FromReadableStream(stream) {
22 return new Promise((resolve, reject) => {
23 stream.pipe(_crypto.default.createHash('md5').setEncoding('hex')).on('finish', function () {
24 resolve(this.read());
25 }).on('error', reject);
26 });
27}
28
29function md5FromObject(obj, encoding = 'hex') {
30 return md5FromString(JSON.stringify((0, _collection.objectSortedEntriesDeep)(obj)), encoding);
31}
32
33function md5FromFilePath(fs, filePath) {
34 return md5FromReadableStream(fs.createReadStream(filePath));
35}
\No newline at end of file