Skip to content

Commit 90776fd

Browse files
committedApr 27, 2022
fix: remove fs.copyFile checks
This exists in all of the node versions this module supports
1 parent e870016 commit 90776fd

File tree

3 files changed

+19
-49
lines changed

3 files changed

+19
-49
lines changed
 

‎lib/content/read.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const Pipeline = require('minipass-pipeline')
1010

1111
const lstat = util.promisify(fs.lstat)
1212
const readFile = util.promisify(fs.readFile)
13+
const copyFile = util.promisify(fs.copyFile)
1314

1415
module.exports = read
1516

@@ -90,12 +91,8 @@ function readStream (cache, integrity, opts = {}) {
9091
return stream
9192
}
9293

93-
let copyFile
94-
if (fs.copyFile) {
95-
module.exports.copy = copy
96-
module.exports.copy.sync = copySync
97-
copyFile = util.promisify(fs.copyFile)
98-
}
94+
module.exports.copy = copy
95+
module.exports.copy.sync = copySync
9996

10097
function copy (cache, integrity, dest) {
10198
return withContentSri(cache, integrity, (cpath, sri) => {

‎lib/get.js

+14-35
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
const Collect = require('minipass-collect')
44
const Minipass = require('minipass')
55
const Pipeline = require('minipass-pipeline')
6-
const fs = require('fs')
7-
const util = require('util')
86

97
const index = require('./entry-index')
108
const memo = require('./memoization')
119
const read = require('./content/read')
1210

13-
const writeFile = util.promisify(fs.writeFile)
14-
1511
function getData (cache, key, opts = {}) {
1612
const { integrity, memoize, size } = opts
1713
const memoized = memo.get(cache, key, opts)
@@ -209,42 +205,25 @@ function info (cache, key, opts = {}) {
209205
module.exports.info = info
210206

211207
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+
})
236220
})
237221
}
222+
238223
module.exports.copy = copy
239224

240225
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)
248227
}
249228
module.exports.copy.byDigest = copyByDigest
250229

‎lib/put.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,8 @@ function putStream (cache, key, opts = {}) {
7676
if (memoize && memoData) {
7777
memo.put(cache, entry, memoData, opts)
7878
}
79-
80-
if (integrity) {
81-
pipeline.emit('integrity', integrity)
82-
}
83-
84-
if (size) {
85-
pipeline.emit('size', size)
86-
}
79+
pipeline.emit('integrity', integrity)
80+
pipeline.emit('size', size)
8781
})
8882
}
8983
},

0 commit comments

Comments
 (0)
Please sign in to comment.