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 14function contentPath (cache, integrity) { 15 const sri = ssri.parse(integrity, { single: true }) 16 // contentPath is the *strongest* algo given 17 return path.join.apply(path, [ 18 contentDir(cache), 19 sri.algorithm 20 ].concat(hashToSegments(sri.hexDigest()))) 21} 22 23module.exports._contentDir = contentDir 24function contentDir (cache) { 25 return path.join(cache, `content-v${contentVer}`) 26} 27