cacache 12.0.4 → 15.0.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/CHANGELOG.md +108 -2
- package/README.md +66 -38
- package/get.js +173 -165
- package/index.js +39 -1
- package/lib/content/.write.js.swp +0 -0
- package/lib/content/path.js +7 -4
- package/lib/content/read.js +128 -73
- package/lib/content/rm.js +8 -9
- package/lib/content/write.js +126 -106
- package/lib/entry-index.js +144 -127
- package/lib/memoization.js +15 -10
- package/lib/util/disposer.js +30 -0
- package/lib/util/fix-owner.js +36 -19
- package/lib/util/hash-to-segments.js +1 -5
- package/lib/util/move-file.js +45 -28
- package/lib/util/tmp.js +11 -13
- package/lib/verify.js +168 -108
- package/ls.js +1 -1
- package/package.json +30 -31
- package/put.js +65 -67
- package/rm.js +5 -2
- package/README.es.md +0 -628
- package/en.js +0 -3
- package/es.js +0 -3
- package/lib/util/y.js +0 -25
- package/locales/en.js +0 -47
- package/locales/en.json +0 -7
- package/locales/es.js +0 -49
- package/locales/es.json +0 -6
package/put.js
CHANGED
|
@@ -1,86 +1,84 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const figgyPudding = require('figgy-pudding')
|
|
4
3
|
const index = require('./lib/entry-index')
|
|
5
4
|
const memo = require('./lib/memoization')
|
|
6
5
|
const write = require('./lib/content/write')
|
|
7
|
-
const
|
|
6
|
+
const Flush = require('minipass-flush')
|
|
7
|
+
const { PassThrough } = require('minipass-collect')
|
|
8
|
+
const Pipeline = require('minipass-pipeline')
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
-
algorithms:
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
integrity: {},
|
|
14
|
-
memoize: {},
|
|
15
|
-
metadata: {},
|
|
16
|
-
pickAlgorithm: {},
|
|
17
|
-
size: {},
|
|
18
|
-
tmpPrefix: {},
|
|
19
|
-
single: {},
|
|
20
|
-
sep: {},
|
|
21
|
-
error: {},
|
|
22
|
-
strict: {}
|
|
10
|
+
const putOpts = (opts) => ({
|
|
11
|
+
algorithms: ['sha512'],
|
|
12
|
+
...opts
|
|
23
13
|
})
|
|
24
14
|
|
|
25
15
|
module.exports = putData
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
|
|
17
|
+
function putData (cache, key, data, opts = {}) {
|
|
18
|
+
const { memoize } = opts
|
|
19
|
+
opts = putOpts(opts)
|
|
20
|
+
return write(cache, data, opts).then((res) => {
|
|
21
|
+
return index
|
|
22
|
+
.insert(cache, key, res.integrity, { ...opts, size: res.size })
|
|
23
|
+
.then((entry) => {
|
|
24
|
+
if (memoize) {
|
|
25
|
+
memo.put(cache, entry, data, opts)
|
|
26
|
+
}
|
|
27
|
+
return res.integrity
|
|
28
|
+
})
|
|
37
29
|
})
|
|
38
30
|
}
|
|
39
31
|
|
|
40
32
|
module.exports.stream = putStream
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
|
|
34
|
+
function putStream (cache, key, opts = {}) {
|
|
35
|
+
const { memoize } = opts
|
|
36
|
+
opts = putOpts(opts)
|
|
43
37
|
let integrity
|
|
44
38
|
let size
|
|
45
|
-
|
|
46
|
-
cache, opts
|
|
47
|
-
).on('integrity', int => {
|
|
48
|
-
integrity = int
|
|
49
|
-
}).on('size', s => {
|
|
50
|
-
size = s
|
|
51
|
-
})
|
|
39
|
+
|
|
52
40
|
let memoData
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
memoTotal += chunk.length
|
|
60
|
-
}
|
|
61
|
-
cb()
|
|
41
|
+
const pipeline = new Pipeline()
|
|
42
|
+
// first item in the pipeline is the memoizer, because we need
|
|
43
|
+
// that to end first and get the collected data.
|
|
44
|
+
if (memoize) {
|
|
45
|
+
const memoizer = new PassThrough().on('collect', data => {
|
|
46
|
+
memoData = data
|
|
62
47
|
})
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
})
|
|
48
|
+
pipeline.push(memoizer)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// contentStream is a write-only, not a passthrough
|
|
52
|
+
// no data comes out of it.
|
|
53
|
+
const contentStream = write.stream(cache, opts)
|
|
54
|
+
.on('integrity', (int) => {
|
|
55
|
+
integrity = int
|
|
72
56
|
})
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
57
|
+
.on('size', (s) => {
|
|
58
|
+
size = s
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
pipeline.push(contentStream)
|
|
62
|
+
|
|
63
|
+
// last but not least, we write the index and emit hash and size,
|
|
64
|
+
// and memoize if we're doing that
|
|
65
|
+
pipeline.push(new Flush({
|
|
66
|
+
flush () {
|
|
67
|
+
return index
|
|
68
|
+
.insert(cache, key, integrity, { ...opts, size })
|
|
69
|
+
.then((entry) => {
|
|
70
|
+
if (memoize && memoData) {
|
|
71
|
+
memo.put(cache, entry, memoData, opts)
|
|
72
|
+
}
|
|
73
|
+
if (integrity) {
|
|
74
|
+
pipeline.emit('integrity', integrity)
|
|
75
|
+
}
|
|
76
|
+
if (size) {
|
|
77
|
+
pipeline.emit('size', size)
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
}))
|
|
82
|
+
|
|
83
|
+
return pipeline
|
|
86
84
|
}
|
package/rm.js
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const util = require('util')
|
|
4
4
|
|
|
5
5
|
const index = require('./lib/entry-index')
|
|
6
6
|
const memo = require('./lib/memoization')
|
|
7
7
|
const path = require('path')
|
|
8
|
-
const rimraf =
|
|
8
|
+
const rimraf = util.promisify(require('rimraf'))
|
|
9
9
|
const rmContent = require('./lib/content/rm')
|
|
10
10
|
|
|
11
11
|
module.exports = entry
|
|
12
12
|
module.exports.entry = entry
|
|
13
|
+
|
|
13
14
|
function entry (cache, key) {
|
|
14
15
|
memo.clearMemoized()
|
|
15
16
|
return index.delete(cache, key)
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
module.exports.content = content
|
|
20
|
+
|
|
19
21
|
function content (cache, integrity) {
|
|
20
22
|
memo.clearMemoized()
|
|
21
23
|
return rmContent(cache, integrity)
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
module.exports.all = all
|
|
27
|
+
|
|
25
28
|
function all (cache) {
|
|
26
29
|
memo.clearMemoized()
|
|
27
30
|
return rimraf(path.join(cache, '*(content-*|index-*)'))
|