|
3 | 3 | const Collect = require('minipass-collect')
|
4 | 4 | const Minipass = require('minipass')
|
5 | 5 | const Pipeline = require('minipass-pipeline')
|
6 |
| -const fs = require('fs') |
7 |
| -const util = require('util') |
8 | 6 |
|
9 | 7 | const index = require('./entry-index')
|
10 | 8 | const memo = require('./memoization')
|
11 | 9 | const read = require('./content/read')
|
12 | 10 |
|
13 |
| -const writeFile = util.promisify(fs.writeFile) |
14 |
| - |
15 | 11 | function getData (cache, key, opts = {}) {
|
16 | 12 | const { integrity, memoize, size } = opts
|
17 | 13 | const memoized = memo.get(cache, key, opts)
|
@@ -209,42 +205,25 @@ function info (cache, key, opts = {}) {
|
209 | 205 | module.exports.info = info
|
210 | 206 |
|
211 | 207 | function copy (cache, key, dest, opts = {}) {
|
212 |
| - if (read.copy) { |
213 |
| - return index.find(cache, key, opts).then((entry) => { |
214 |
| - if (!entry) { |
215 |
| - throw new index.NotFoundError(cache, key) |
216 |
| - } |
217 |
| - return read.copy(cache, entry.integrity, dest, opts) |
218 |
| - .then(() => { |
219 |
| - return { |
220 |
| - metadata: entry.metadata, |
221 |
| - size: entry.size, |
222 |
| - integrity: entry.integrity, |
223 |
| - } |
224 |
| - }) |
225 |
| - }) |
226 |
| - } |
227 |
| - |
228 |
| - return getData(cache, key, opts).then((res) => { |
229 |
| - return writeFile(dest, res.data).then(() => { |
230 |
| - return { |
231 |
| - metadata: res.metadata, |
232 |
| - size: res.size, |
233 |
| - integrity: res.integrity, |
234 |
| - } |
235 |
| - }) |
| 208 | + return index.find(cache, key, opts).then((entry) => { |
| 209 | + if (!entry) { |
| 210 | + throw new index.NotFoundError(cache, key) |
| 211 | + } |
| 212 | + return read.copy(cache, entry.integrity, dest, opts) |
| 213 | + .then(() => { |
| 214 | + return { |
| 215 | + metadata: entry.metadata, |
| 216 | + size: entry.size, |
| 217 | + integrity: entry.integrity, |
| 218 | + } |
| 219 | + }) |
236 | 220 | })
|
237 | 221 | }
|
| 222 | + |
238 | 223 | module.exports.copy = copy
|
239 | 224 |
|
240 | 225 | function copyByDigest (cache, key, dest, opts = {}) {
|
241 |
| - if (read.copy) { |
242 |
| - return read.copy(cache, key, dest, opts).then(() => key) |
243 |
| - } |
244 |
| - |
245 |
| - return getDataByDigest(cache, key, opts).then((res) => { |
246 |
| - return writeFile(dest, res).then(() => key) |
247 |
| - }) |
| 226 | + return read.copy(cache, key, dest, opts).then(() => key) |
248 | 227 | }
|
249 | 228 | module.exports.copy.byDigest = copyByDigest
|
250 | 229 |
|
|
0 commit comments