You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
750 B

4 years ago
  1. 'use strict'
  2. const contentVer = require('../../package.json')['cache-version'].content
  3. const hashToSegments = require('../util/hash-to-segments')
  4. const path = require('path')
  5. const ssri = require('ssri')
  6. // Current format of content file path:
  7. //
  8. // sha512-BaSE64Hex= ->
  9. // ~/.my-cache/content-v2/sha512/ba/da/55deadbeefc0ffee
  10. //
  11. module.exports = contentPath
  12. function contentPath (cache, integrity) {
  13. const sri = ssri.parse(integrity, { single: true })
  14. // contentPath is the *strongest* algo given
  15. return path.join.apply(path, [
  16. contentDir(cache),
  17. sri.algorithm
  18. ].concat(hashToSegments(sri.hexDigest())))
  19. }
  20. module.exports._contentDir = contentDir
  21. function contentDir (cache) {
  22. return path.join(cache, `content-v${contentVer}`)
  23. }