get-composite-details.js 661 B

1234567891011121314151617181920212223242526272829
  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. const crypto = require('crypto');
  9. module.exports = (compositeURL, dependencyDetails) => {
  10. let totalSize = 0;
  11. let compositeHash = '';
  12. for (const fileDetails of dependencyDetails) {
  13. totalSize += fileDetails.size;
  14. compositeHash += fileDetails.hash;
  15. }
  16. const md5 = crypto.createHash('md5');
  17. md5.update(compositeHash);
  18. const hashOfHashes = md5.digest('hex');
  19. return {
  20. file: compositeURL,
  21. hash: hashOfHashes,
  22. size: totalSize
  23. };
  24. };