How to use the cacache.get.hasContent function in cacache

To help you get started, we’ve selected a few cacache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github npm / tink / lib / pkglock.js View on Github external
async function stat ({ cache, hash, pkg, resolvedPath, isDir }, verify) {
  if (isDir || path.basename(resolvedPath) === '.package-map.json') {
    return Object.assign(fs.lstatSync.orig(process.tink.cache), {
      mode: 16676, // read-only
      size: 64
    })
  }
  if (!cache || !hash) {
    throw new Error('stat() requires a fully-resolved pkgmap file address')
  }
  let info
  try {
    info = await ccGet.hasContent(cache, hash)
  } catch (err) {
    await fetchPackage(cache, hash, pkg)
    info = await ccGet.hasContent(cache, hash)
  }
  if (!info) {
    return false
  }
  const cpath = ccPath(cache, info.sri)
  if (verify) {
    try {
      await ssri.checkStream(
        fs.createReadStream.orig(cpath),
        info.sri
      )
    } catch (err) {
      const newResolved = await fetchPackage(cache, pkg, hash)