cacache
Advanced tools
Comparing version 9.2.9 to 9.3.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="9.3.0"></a> | ||
# [9.3.0](https://github.com/zkat/cacache/compare/v9.2.9...v9.3.0) (2017-10-07) | ||
### Features | ||
* **copy:** added cacache.get.copy api for fast copies (#107) ([067b5f6](https://github.com/zkat/cacache/commit/067b5f6)) | ||
<a name="9.2.9"></a> | ||
@@ -7,0 +17,0 @@ ## [9.2.9](https://github.com/zkat/cacache/compare/v9.2.8...v9.2.9) (2017-06-17) |
36
get.js
@@ -5,2 +5,3 @@ 'use strict' | ||
const fs = require('fs') | ||
const index = require('./lib/entry-index') | ||
@@ -156,1 +157,36 @@ const memo = require('./lib/memoization') | ||
module.exports.hasContent = read.hasContent | ||
module.exports.copy = function cp (cache, key, dest, opts) { | ||
return copy(false, cache, key, dest, opts) | ||
} | ||
module.exports.copy.byDigest = function cpDigest (cache, digest, dest, opts) { | ||
return copy(true, cache, digest, dest, opts) | ||
} | ||
function copy (byDigest, cache, key, dest, opts) { | ||
opts = opts || {} | ||
if (read.copy) { | ||
return ( | ||
byDigest ? BB.resolve(null) : index.find(cache, key, opts) | ||
).then(entry => { | ||
if (!entry && !byDigest) { | ||
throw new index.NotFoundError(cache, key) | ||
} | ||
return read.copy( | ||
cache, byDigest ? key : entry.integrity, dest, opts | ||
).then(() => byDigest ? key : { | ||
metadata: entry.metadata, | ||
size: entry.size, | ||
integrity: entry.integrity | ||
}) | ||
}) | ||
} else { | ||
return getData(byDigest, cache, key, opts).then(res => { | ||
return fs.writeFileAsync(dest, byDigest ? res : res.data) | ||
.then(() => byDigest ? key : { | ||
metadata: res.metadata, | ||
size: res.size, | ||
integrity: res.integrity | ||
}) | ||
}) | ||
} | ||
} |
@@ -55,2 +55,14 @@ 'use strict' | ||
if (fs.copyFile) { | ||
module.exports.copy = copy | ||
} | ||
function copy (cache, integrity, dest, opts) { | ||
opts = opts || {} | ||
return pickContentSri(cache, integrity).then(content => { | ||
const sri = content.sri | ||
const cpath = contentPath(cache, sri) | ||
return fs.copyFileAsync(cpath, dest).then(() => content.size) | ||
}) | ||
} | ||
module.exports.hasContent = hasContent | ||
@@ -57,0 +69,0 @@ function hasContent (cache, integrity) { |
@@ -23,2 +23,4 @@ 'use strict' | ||
x.get.stream.byDigest = (cache, hash, opts) => get.stream.byDigest(cache, hash, opts) | ||
x.get.copy = (cache, key, dest, opts) => get.copy(cache, key, dest, opts) | ||
x.get.copy.byDigest = (cache, hash, dest, opts) => get.copy.byDigest(cache, hash, dest, opts) | ||
x.get.info = (cache, key) => get.info(cache, key) | ||
@@ -25,0 +27,0 @@ x.get.hasContent = (cache, hash) => get.hasContent(cache, hash) |
@@ -23,2 +23,4 @@ 'use strict' | ||
x.saca.flujo.porHacheo = (cache, hacheo, ops) => get.stream.byDigest(cache, hacheo, ops) | ||
x.sava.copia = (cache, clave, destino, opts) => get.copy(cache, clave, destino, opts) | ||
x.sava.copia.porHacheo = (cache, hacheo, destino, opts) => get.copy.byDigest(cache, hacheo, destino, opts) | ||
x.saca.info = (cache, clave) => get.info(cache, clave) | ||
@@ -25,0 +27,0 @@ x.saca.tieneDatos = (cache, hacheo) => get.hasContent(cache, hacheo) |
{ | ||
"name": "cacache", | ||
"version": "9.2.9", | ||
"version": "9.3.0", | ||
"cache-version": { | ||
@@ -77,11 +77,11 @@ "content": "2", | ||
"benchmark": "^2.1.4", | ||
"chalk": "^1.1.3", | ||
"chalk": "^2.0.1", | ||
"cross-env": "^5.0.1", | ||
"nyc": "^11.0.2", | ||
"require-inject": "^1.4.0", | ||
"safe-buffer": "^5.1.0", | ||
"nyc": "^11.1.0", | ||
"require-inject": "^1.4.2", | ||
"safe-buffer": "^5.1.1", | ||
"standard": "^10.0.2", | ||
"standard-version": "^4.2.0", | ||
"tacks": "^1.2.2", | ||
"tap": "^10.3.4", | ||
"tap": "^10.7.0", | ||
"weallbehave": "^1.2.0", | ||
@@ -88,0 +88,0 @@ "weallcontribute": "^1.0.8" |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
100026
29
1271
3