get-composite-details.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. /*
  3. Copyright 2018 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. var __importDefault = (this && this.__importDefault) || function (mod) {
  9. return (mod && mod.__esModule) ? mod : { "default": mod };
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. exports.getCompositeDetails = void 0;
  13. const crypto_1 = __importDefault(require("crypto"));
  14. function getCompositeDetails(compositeURL, dependencyDetails) {
  15. let totalSize = 0;
  16. let compositeHash = '';
  17. for (const fileDetails of dependencyDetails) {
  18. totalSize += fileDetails.size;
  19. compositeHash += fileDetails.hash;
  20. }
  21. const md5 = crypto_1.default.createHash('md5');
  22. md5.update(compositeHash);
  23. const hashOfHashes = md5.digest('hex');
  24. return {
  25. file: compositeURL,
  26. hash: hashOfHashes,
  27. size: totalSize,
  28. };
  29. }
  30. exports.getCompositeDetails = getCompositeDetails;