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