cacache 17.0.7 → 17.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -101,7 +101,7 @@ cacache.get.byDigest(cachePath, integrityHash).then(data => {
101
101
 
102
102
  ### Contributing
103
103
 
104
- The cacache team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute! The [Contributor Guide](CONTRIBUTING.md) has all the information you need for everything from reporting bugs to contributing entire new features. Please don't hesitate to jump in if you'd like to, or even ask us questions if something isn't clear.
104
+ The cacache team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute! Please don't hesitate to jump in if you'd like to, or even ask us questions if something isn't clear.
105
105
 
106
106
  All participants and maintainers in this project are expected to follow [Code of Conduct](CODE_OF_CONDUCT.md), and just generally be excellent to each other.
107
107
 
@@ -17,9 +17,6 @@ module.exports = write
17
17
 
18
18
  async function write (cache, data, opts = {}) {
19
19
  const { algorithms, size, integrity } = opts
20
- if (algorithms && algorithms.length > 1) {
21
- throw new Error('opts.algorithms only supports a single algorithm for now')
22
- }
23
20
 
24
21
  if (typeof size === 'number' && data.length !== size) {
25
22
  throw sizeError(size, data.length)
@@ -30,16 +27,19 @@ async function write (cache, data, opts = {}) {
30
27
  throw checksumError(integrity, sri)
31
28
  }
32
29
 
33
- const tmp = await makeTmp(cache, opts)
34
- try {
35
- await fs.writeFile(tmp.target, data, { flag: 'wx' })
36
- await moveToDestination(tmp, cache, sri, opts)
37
- return { integrity: sri, size: data.length }
38
- } finally {
39
- if (!tmp.moved) {
40
- await fs.rm(tmp.target, { recursive: true, force: true })
30
+ for (const algo in sri) {
31
+ const tmp = await makeTmp(cache, opts)
32
+ const hash = sri[algo].toString()
33
+ try {
34
+ await fs.writeFile(tmp.target, data, { flag: 'wx' })
35
+ await moveToDestination(tmp, cache, hash, opts)
36
+ } finally {
37
+ if (!tmp.moved) {
38
+ await fs.rm(tmp.target, { recursive: true, force: true })
39
+ }
41
40
  }
42
41
  }
42
+ return { integrity: sri, size: data.length }
43
43
  }
44
44
 
45
45
  module.exports.stream = writeStream
@@ -109,12 +109,12 @@ async function compact (cache, key, matchFn, opts = {}) {
109
109
  module.exports.insert = insert
110
110
 
111
111
  async function insert (cache, key, integrity, opts = {}) {
112
- const { metadata, size } = opts
112
+ const { metadata, size, time } = opts
113
113
  const bucket = bucketPath(cache, key)
114
114
  const entry = {
115
115
  key,
116
116
  integrity: integrity && ssri.stringify(integrity),
117
- time: Date.now(),
117
+ time: time || Date.now(),
118
118
  size,
119
119
  metadata,
120
120
  }
package/lib/verify.js CHANGED
@@ -100,7 +100,11 @@ async function garbageCollect (cache, opts) {
100
100
  return
101
101
  }
102
102
 
103
- liveContent.add(entry.integrity.toString())
103
+ // integrity is stringified, re-parse it so we can get each hash
104
+ const integrity = ssri.parse(entry.integrity)
105
+ for (const algo in integrity) {
106
+ liveContent.add(integrity[algo].toString())
107
+ }
104
108
  })
105
109
  await new Promise((resolve, reject) => {
106
110
  indexStream.on('end', resolve).on('error', reject)
@@ -220,6 +224,7 @@ async function rebuildBucket (cache, bucket, stats, opts) {
220
224
  await index.insert(cache, entry.key, entry.integrity, {
221
225
  metadata: entry.metadata,
222
226
  size: entry.size,
227
+ time: entry.time,
223
228
  })
224
229
  stats.totalEntries++
225
230
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cacache",
3
- "version": "17.0.7",
3
+ "version": "17.1.0",
4
4
  "cache-version": {
5
5
  "content": "2",
6
6
  "index": "5"