1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.computeData = void 0;
|
7 |
|
8 | function _bluebirdLst() {
|
9 | const data = _interopRequireWildcard(require("bluebird-lst"));
|
10 |
|
11 | _bluebirdLst = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _crypto() {
|
19 | const data = require("crypto");
|
20 |
|
21 | _crypto = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _fs() {
|
29 | const data = require("fs");
|
30 |
|
31 | _fs = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _fsExtraP() {
|
39 | const data = require("fs-extra-p");
|
40 |
|
41 | _fsExtraP = function () {
|
42 | return data;
|
43 | };
|
44 |
|
45 | return data;
|
46 | }
|
47 |
|
48 | var path = _interopRequireWildcard(require("path"));
|
49 |
|
50 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
51 |
|
52 | let computeData = (() => {
|
53 | var _ref = (0, _bluebirdLst().coroutine)(function* (resourcesPath, options) {
|
54 |
|
55 | const names = (yield (0, _fsExtraP().readdir)(resourcesPath)).filter(it => it.endsWith(".asar")).sort();
|
56 | const checksums = yield _bluebirdLst().default.map(names, it => hashFile(path.join(resourcesPath, it)));
|
57 | const result = {};
|
58 |
|
59 | for (let i = 0; i < names.length; i++) {
|
60 | result[names[i]] = checksums[i];
|
61 | }
|
62 |
|
63 | return Object.assign({
|
64 | checksums: result
|
65 | }, options);
|
66 | });
|
67 |
|
68 | return function computeData(_x, _x2) {
|
69 | return _ref.apply(this, arguments);
|
70 | };
|
71 | })();
|
72 |
|
73 | exports.computeData = computeData;
|
74 |
|
75 | function hashFile(file, algorithm = "sha512", encoding = "base64") {
|
76 | return new Promise((resolve, reject) => {
|
77 | const hash = (0, _crypto().createHash)(algorithm);
|
78 | hash.on("error", reject).setEncoding(encoding);
|
79 | (0, _fs().createReadStream)(file).on("error", reject).on("end", () => {
|
80 | hash.end();
|
81 | resolve(hash.read());
|
82 | }).pipe(hash, {
|
83 | end: false
|
84 | });
|
85 | });
|
86 | }
|
87 |
|
\ | No newline at end of file |