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/get.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const figgyPudding = require('figgy-pudding')
|
|
3
|
+
const util = require('util')
|
|
6
4
|
const fs = require('fs')
|
|
7
5
|
const index = require('./lib/entry-index')
|
|
8
6
|
const memo = require('./lib/memoization')
|
|
9
|
-
const pipe = require('mississippi').pipe
|
|
10
|
-
const pipeline = require('mississippi').pipeline
|
|
11
7
|
const read = require('./lib/content/read')
|
|
12
|
-
const through = require('mississippi').through
|
|
13
8
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const Minipass = require('minipass')
|
|
10
|
+
const Collect = require('minipass-collect')
|
|
11
|
+
const Pipeline = require('minipass-pipeline')
|
|
12
|
+
|
|
13
|
+
const writeFile = util.promisify(fs.writeFile)
|
|
19
14
|
|
|
20
15
|
module.exports = function get (cache, key, opts) {
|
|
21
16
|
return getData(false, cache, key, opts)
|
|
@@ -23,44 +18,53 @@ module.exports = function get (cache, key, opts) {
|
|
|
23
18
|
module.exports.byDigest = function getByDigest (cache, digest, opts) {
|
|
24
19
|
return getData(true, cache, digest, opts)
|
|
25
20
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
|
|
22
|
+
function getData (byDigest, cache, key, opts = {}) {
|
|
23
|
+
const { integrity, memoize, size } = opts
|
|
24
|
+
const memoized = byDigest
|
|
25
|
+
? memo.get.byDigest(cache, key, opts)
|
|
26
|
+
: memo.get(cache, key, opts)
|
|
27
|
+
if (memoized && memoize !== false) {
|
|
28
|
+
return Promise.resolve(
|
|
29
|
+
byDigest
|
|
30
|
+
? memoized
|
|
31
|
+
: {
|
|
32
|
+
metadata: memoized.entry.metadata,
|
|
33
|
+
data: memoized.data,
|
|
34
|
+
integrity: memoized.entry.integrity,
|
|
35
|
+
size: memoized.entry.size
|
|
36
|
+
}
|
|
37
|
+
)
|
|
40
38
|
}
|
|
41
|
-
return (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
throw new index.NotFoundError(cache, key)
|
|
46
|
-
}
|
|
47
|
-
return read(cache, byDigest ? key : entry.integrity, {
|
|
48
|
-
integrity: opts.integrity,
|
|
49
|
-
size: opts.size
|
|
50
|
-
}).then(data => byDigest ? data : {
|
|
51
|
-
metadata: entry.metadata,
|
|
52
|
-
data: data,
|
|
53
|
-
size: entry.size,
|
|
54
|
-
integrity: entry.integrity
|
|
55
|
-
}).then(res => {
|
|
56
|
-
if (opts.memoize && byDigest) {
|
|
57
|
-
memo.put.byDigest(cache, key, res, opts)
|
|
58
|
-
} else if (opts.memoize) {
|
|
59
|
-
memo.put(cache, entry, res.data, opts)
|
|
39
|
+
return (byDigest ? Promise.resolve(null) : index.find(cache, key, opts)).then(
|
|
40
|
+
(entry) => {
|
|
41
|
+
if (!entry && !byDigest) {
|
|
42
|
+
throw new index.NotFoundError(cache, key)
|
|
60
43
|
}
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
return read(cache, byDigest ? key : entry.integrity, {
|
|
45
|
+
integrity,
|
|
46
|
+
size
|
|
47
|
+
})
|
|
48
|
+
.then((data) =>
|
|
49
|
+
byDigest
|
|
50
|
+
? data
|
|
51
|
+
: {
|
|
52
|
+
data,
|
|
53
|
+
metadata: entry.metadata,
|
|
54
|
+
size: entry.size,
|
|
55
|
+
integrity: entry.integrity
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
.then((res) => {
|
|
59
|
+
if (memoize && byDigest) {
|
|
60
|
+
memo.put.byDigest(cache, key, res, opts)
|
|
61
|
+
} else if (memoize) {
|
|
62
|
+
memo.put(cache, entry, res.data, opts)
|
|
63
|
+
}
|
|
64
|
+
return res
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
)
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
module.exports.sync = function get (cache, key, opts) {
|
|
@@ -69,33 +73,30 @@ module.exports.sync = function get (cache, key, opts) {
|
|
|
69
73
|
module.exports.sync.byDigest = function getByDigest (cache, digest, opts) {
|
|
70
74
|
return getDataSync(true, cache, digest, opts)
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
|
|
77
|
+
function getDataSync (byDigest, cache, key, opts = {}) {
|
|
78
|
+
const { integrity, memoize, size } = opts
|
|
79
|
+
const memoized = byDigest
|
|
80
|
+
? memo.get.byDigest(cache, key, opts)
|
|
81
|
+
: memo.get(cache, key, opts)
|
|
82
|
+
if (memoized && memoize !== false) {
|
|
83
|
+
return byDigest
|
|
84
|
+
? memoized
|
|
85
|
+
: {
|
|
86
|
+
metadata: memoized.entry.metadata,
|
|
87
|
+
data: memoized.data,
|
|
88
|
+
integrity: memoized.entry.integrity,
|
|
89
|
+
size: memoized.entry.size
|
|
90
|
+
}
|
|
86
91
|
}
|
|
87
92
|
const entry = !byDigest && index.find.sync(cache, key, opts)
|
|
88
93
|
if (!entry && !byDigest) {
|
|
89
94
|
throw new index.NotFoundError(cache, key)
|
|
90
95
|
}
|
|
91
|
-
const data = read.sync(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
integrity: opts.integrity,
|
|
96
|
-
size: opts.size
|
|
97
|
-
}
|
|
98
|
-
)
|
|
96
|
+
const data = read.sync(cache, byDigest ? key : entry.integrity, {
|
|
97
|
+
integrity: integrity,
|
|
98
|
+
size: size
|
|
99
|
+
})
|
|
99
100
|
const res = byDigest
|
|
100
101
|
? data
|
|
101
102
|
: {
|
|
@@ -104,106 +105,100 @@ function getDataSync (byDigest, cache, key, opts) {
|
|
|
104
105
|
size: entry.size,
|
|
105
106
|
integrity: entry.integrity
|
|
106
107
|
}
|
|
107
|
-
if (
|
|
108
|
+
if (memoize && byDigest) {
|
|
108
109
|
memo.put.byDigest(cache, key, res, opts)
|
|
109
|
-
} else if (
|
|
110
|
+
} else if (memoize) {
|
|
110
111
|
memo.put(cache, entry, res.data, opts)
|
|
111
112
|
}
|
|
112
113
|
return res
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
module.exports.stream = getStream
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
|
|
118
|
+
const getMemoizedStream = (memoized) => {
|
|
119
|
+
const stream = new Minipass()
|
|
120
|
+
stream.on('newListener', function (ev, cb) {
|
|
121
|
+
ev === 'metadata' && cb(memoized.entry.metadata)
|
|
122
|
+
ev === 'integrity' && cb(memoized.entry.integrity)
|
|
123
|
+
ev === 'size' && cb(memoized.entry.size)
|
|
124
|
+
})
|
|
125
|
+
stream.end(memoized.data)
|
|
126
|
+
return stream
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getStream (cache, key, opts = {}) {
|
|
130
|
+
const { memoize, size } = opts
|
|
119
131
|
const memoized = memo.get(cache, key, opts)
|
|
120
|
-
if (memoized &&
|
|
121
|
-
|
|
122
|
-
ev === 'metadata' && cb(memoized.entry.metadata)
|
|
123
|
-
ev === 'integrity' && cb(memoized.entry.integrity)
|
|
124
|
-
ev === 'size' && cb(memoized.entry.size)
|
|
125
|
-
})
|
|
126
|
-
stream.write(memoized.data, () => stream.end())
|
|
127
|
-
return stream
|
|
132
|
+
if (memoized && memoize !== false) {
|
|
133
|
+
return getMemoizedStream(memoized)
|
|
128
134
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
cb(
|
|
143
|
-
|
|
144
|
-
memoData && memo.put(cache, entry, Buffer.concat(memoData, memoLength), opts)
|
|
145
|
-
cb()
|
|
135
|
+
|
|
136
|
+
const stream = new Pipeline()
|
|
137
|
+
index
|
|
138
|
+
.find(cache, key)
|
|
139
|
+
.then((entry) => {
|
|
140
|
+
if (!entry) {
|
|
141
|
+
throw new index.NotFoundError(cache, key)
|
|
142
|
+
}
|
|
143
|
+
stream.emit('metadata', entry.metadata)
|
|
144
|
+
stream.emit('integrity', entry.integrity)
|
|
145
|
+
stream.emit('size', entry.size)
|
|
146
|
+
stream.on('newListener', function (ev, cb) {
|
|
147
|
+
ev === 'metadata' && cb(entry.metadata)
|
|
148
|
+
ev === 'integrity' && cb(entry.integrity)
|
|
149
|
+
ev === 'size' && cb(entry.size)
|
|
146
150
|
})
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
|
|
152
|
+
const src = read.readStream(
|
|
153
|
+
cache,
|
|
154
|
+
entry.integrity,
|
|
155
|
+
{ ...opts, size: typeof size !== 'number' ? entry.size : size }
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
if (memoize) {
|
|
159
|
+
const memoStream = new Collect.PassThrough()
|
|
160
|
+
memoStream.on('collect', data => memo.put(cache, entry, data, opts))
|
|
161
|
+
stream.unshift(memoStream)
|
|
162
|
+
}
|
|
163
|
+
stream.unshift(src)
|
|
157
164
|
})
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
size: opts.size == null ? entry.size : opts.size
|
|
161
|
-
})),
|
|
162
|
-
memoStream,
|
|
163
|
-
stream
|
|
164
|
-
)
|
|
165
|
-
}).catch(err => stream.emit('error', err))
|
|
165
|
+
.catch((err) => stream.emit('error', err))
|
|
166
|
+
|
|
166
167
|
return stream
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
module.exports.stream.byDigest = getStreamDigest
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
|
|
172
|
+
function getStreamDigest (cache, integrity, opts = {}) {
|
|
173
|
+
const { memoize } = opts
|
|
172
174
|
const memoized = memo.get.byDigest(cache, integrity, opts)
|
|
173
|
-
if (memoized &&
|
|
174
|
-
const stream =
|
|
175
|
-
stream.
|
|
175
|
+
if (memoized && memoize !== false) {
|
|
176
|
+
const stream = new Minipass()
|
|
177
|
+
stream.end(memoized)
|
|
176
178
|
return stream
|
|
177
179
|
} else {
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
let memoLength = 0
|
|
182
|
-
const memoStream = through((c, en, cb) => {
|
|
183
|
-
memoData && memoData.push(c)
|
|
184
|
-
memoLength += c.length
|
|
185
|
-
cb(null, c, en)
|
|
186
|
-
}, cb => {
|
|
187
|
-
memoData && memo.put.byDigest(
|
|
188
|
-
cache,
|
|
189
|
-
integrity,
|
|
190
|
-
Buffer.concat(memoData, memoLength),
|
|
191
|
-
opts
|
|
192
|
-
)
|
|
193
|
-
cb()
|
|
194
|
-
})
|
|
195
|
-
stream = pipeline(stream, memoStream)
|
|
180
|
+
const stream = read.readStream(cache, integrity, opts)
|
|
181
|
+
if (!memoize) {
|
|
182
|
+
return stream
|
|
196
183
|
}
|
|
197
|
-
|
|
184
|
+
const memoStream = new Collect.PassThrough()
|
|
185
|
+
memoStream.on('collect', data => memo.put.byDigest(
|
|
186
|
+
cache,
|
|
187
|
+
integrity,
|
|
188
|
+
data,
|
|
189
|
+
opts
|
|
190
|
+
))
|
|
191
|
+
return new Pipeline(stream, memoStream)
|
|
198
192
|
}
|
|
199
193
|
}
|
|
200
194
|
|
|
201
195
|
module.exports.info = info
|
|
202
|
-
|
|
203
|
-
|
|
196
|
+
|
|
197
|
+
function info (cache, key, opts = {}) {
|
|
198
|
+
const { memoize } = opts
|
|
204
199
|
const memoized = memo.get(cache, key, opts)
|
|
205
|
-
if (memoized &&
|
|
206
|
-
return
|
|
200
|
+
if (memoized && memoize !== false) {
|
|
201
|
+
return Promise.resolve(memoized.entry)
|
|
207
202
|
} else {
|
|
208
203
|
return index.find(cache, key)
|
|
209
204
|
}
|
|
@@ -211,37 +206,50 @@ function info (cache, key, opts) {
|
|
|
211
206
|
|
|
212
207
|
module.exports.hasContent = read.hasContent
|
|
213
208
|
|
|
214
|
-
|
|
209
|
+
function cp (cache, key, dest, opts) {
|
|
215
210
|
return copy(false, cache, key, dest, opts)
|
|
216
211
|
}
|
|
217
|
-
|
|
212
|
+
|
|
213
|
+
module.exports.copy = cp
|
|
214
|
+
|
|
215
|
+
function cpDigest (cache, digest, dest, opts) {
|
|
218
216
|
return copy(true, cache, digest, dest, opts)
|
|
219
217
|
}
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
|
|
219
|
+
module.exports.copy.byDigest = cpDigest
|
|
220
|
+
|
|
221
|
+
function copy (byDigest, cache, key, dest, opts = {}) {
|
|
222
222
|
if (read.copy) {
|
|
223
|
-
return (
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
return (byDigest
|
|
224
|
+
? Promise.resolve(null)
|
|
225
|
+
: index.find(cache, key, opts)
|
|
226
|
+
).then((entry) => {
|
|
226
227
|
if (!entry && !byDigest) {
|
|
227
228
|
throw new index.NotFoundError(cache, key)
|
|
228
229
|
}
|
|
229
|
-
return read
|
|
230
|
-
cache, byDigest ? key : entry.integrity, dest, opts
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
return read
|
|
231
|
+
.copy(cache, byDigest ? key : entry.integrity, dest, opts)
|
|
232
|
+
.then(() => {
|
|
233
|
+
return byDigest
|
|
234
|
+
? key
|
|
235
|
+
: {
|
|
236
|
+
metadata: entry.metadata,
|
|
237
|
+
size: entry.size,
|
|
238
|
+
integrity: entry.integrity
|
|
239
|
+
}
|
|
240
|
+
})
|
|
236
241
|
})
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return getData(byDigest, cache, key, opts).then((res) => {
|
|
245
|
+
return writeFile(dest, byDigest ? res : res.data).then(() => {
|
|
246
|
+
return byDigest
|
|
247
|
+
? key
|
|
248
|
+
: {
|
|
241
249
|
metadata: res.metadata,
|
|
242
250
|
size: res.size,
|
|
243
251
|
integrity: res.integrity
|
|
244
|
-
}
|
|
252
|
+
}
|
|
245
253
|
})
|
|
246
|
-
}
|
|
254
|
+
})
|
|
247
255
|
}
|
package/index.js
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const ls = require('./ls.js')
|
|
4
|
+
const get = require('./get.js')
|
|
5
|
+
const put = require('./put.js')
|
|
6
|
+
const rm = require('./rm.js')
|
|
7
|
+
const verify = require('./verify.js')
|
|
8
|
+
const { clearMemoized } = require('./lib/memoization.js')
|
|
9
|
+
const tmp = require('./lib/util/tmp.js')
|
|
10
|
+
|
|
11
|
+
module.exports.ls = ls
|
|
12
|
+
module.exports.ls.stream = ls.stream
|
|
13
|
+
|
|
14
|
+
module.exports.get = get
|
|
15
|
+
module.exports.get.byDigest = get.byDigest
|
|
16
|
+
module.exports.get.sync = get.sync
|
|
17
|
+
module.exports.get.sync.byDigest = get.sync.byDigest
|
|
18
|
+
module.exports.get.stream = get.stream
|
|
19
|
+
module.exports.get.stream.byDigest = get.stream.byDigest
|
|
20
|
+
module.exports.get.copy = get.copy
|
|
21
|
+
module.exports.get.copy.byDigest = get.copy.byDigest
|
|
22
|
+
module.exports.get.info = get.info
|
|
23
|
+
module.exports.get.hasContent = get.hasContent
|
|
24
|
+
module.exports.get.hasContent.sync = get.hasContent.sync
|
|
25
|
+
|
|
26
|
+
module.exports.put = put
|
|
27
|
+
module.exports.put.stream = put.stream
|
|
28
|
+
|
|
29
|
+
module.exports.rm = rm.entry
|
|
30
|
+
module.exports.rm.all = rm.all
|
|
31
|
+
module.exports.rm.entry = module.exports.rm
|
|
32
|
+
module.exports.rm.content = rm.content
|
|
33
|
+
|
|
34
|
+
module.exports.clearMemoized = clearMemoized
|
|
35
|
+
|
|
36
|
+
module.exports.tmp = {}
|
|
37
|
+
module.exports.tmp.mkdir = tmp.mkdir
|
|
38
|
+
module.exports.tmp.withTmp = tmp.withTmp
|
|
39
|
+
|
|
40
|
+
module.exports.verify = verify
|
|
41
|
+
module.exports.verify.lastRun = verify.lastRun
|
|
Binary file
|
package/lib/content/path.js
CHANGED
|
@@ -11,16 +11,19 @@ const ssri = require('ssri')
|
|
|
11
11
|
// ~/.my-cache/content-v2/sha512/ba/da/55deadbeefc0ffee
|
|
12
12
|
//
|
|
13
13
|
module.exports = contentPath
|
|
14
|
+
|
|
14
15
|
function contentPath (cache, integrity) {
|
|
15
16
|
const sri = ssri.parse(integrity, { single: true })
|
|
16
17
|
// contentPath is the *strongest* algo given
|
|
17
|
-
return path.join
|
|
18
|
+
return path.join(
|
|
18
19
|
contentDir(cache),
|
|
19
|
-
sri.algorithm
|
|
20
|
-
|
|
20
|
+
sri.algorithm,
|
|
21
|
+
...hashToSegments(sri.hexDigest())
|
|
22
|
+
)
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
module.exports.
|
|
25
|
+
module.exports.contentDir = contentDir
|
|
26
|
+
|
|
24
27
|
function contentDir (cache) {
|
|
25
28
|
return path.join(cache, `content-v${contentVer}`)
|
|
26
29
|
}
|