Socket
Socket
Sign inDemoInstall

cacache

Package Overview
Dependencies
53
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

lib/content/path.js

55

get.js

@@ -1,42 +0,27 @@

var fs = require('fs')
var path = require('path')
var index = require('./lib/entry-index')
var read = require('./lib/content/read')
module.exports.path = filePath
function filePath (cache, address) {
return path.join(cache, 'content', address)
module.exports.directory = directory
module.exports.directory.byDigest = read.asDirectory
function directory (cache, key, destination, opts, cb) {
index.find(cache, key, function (err, data) {
if (err) { return cb(err) }
if (!data) { return cb(index.notFoundError(cache, key)) }
read.asDirectory(cache, data.digest, destination, opts, cb)
})
}
module.exports.readStream = readStream
function readStream (cache, address) {
return _read(cache, address, fs.createReadStream)
}
module.exports.readSync = readSync
function readSync (cache, address) {
return _read(cache, address, fs.readFileSync)
}
module.exports.read = read
function read (cache, address, cb) {
fs.readFile(filePath(cache, address), function (err, data) {
if (err && err.code === 'ENOENT') {
cb(null, null)
} else if (err) {
cb(err)
} else {
cb(null, data)
}
module.exports.tarball = tarball
module.exports.tarball.byDigest = read.asTarball
function tarball (cache, key, destination, opts, cb) {
index.find(cache, key, function (err, data) {
if (err) { return cb(err) }
if (!data) { return cb(index.notFoundError(cache, key)) }
read.asTarball(cache, data.digest, destination, opts, cb)
})
}
function _read (cache, address, reader) {
try {
return reader(filePath(cache, address))
} catch (e) {
if (e.code === 'ENOENT') {
return null
} else {
throw e
}
}
module.exports.info = info
function info (cache, key, cb) {
index.find(cache, key, cb)
}
module.exports = {
clear: require('./clear'),
chownr: require('./lib/util/fix-owner').chownr,
ls: require('./ls'),
get: require('./get'),
put: require('./put')
put: require('./put'),
rm: require('./rm')
}
{
"name": "cacache",
"version": "1.0.0",
"version": "2.0.0",
"description": "General content-addressable cache system that maintains a filesystem registry of file data.",
"main": "index.js",
"files": [
"*.js",
"lib"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"preversion": "npm t",
"postversion": "npm publish && git push --follow-tags",
"pretest": "standard",
"test": "nyc -- tap test/*.js"
},

@@ -17,4 +24,9 @@ "keywords": [

"dependencies": {
"chownr": "^1.0.1",
"dezalgo": "^1.0.3",
"fs-write-stream-atomic": "^1.0.8",
"from2": "^2.3.0",
"fs-extra": "^1.0.0",
"graceful-fs": "^4.1.10",
"inflight": "^1.0.6",
"lockfile": "^1.0.2",
"mkdirp": "^0.5.1",

@@ -25,8 +37,21 @@ "mv": "^2.1.1",

"rimraf": "^2.5.4",
"slide": "^1.1.6",
"split": "^1.0.0",
"tar-fs": "^1.14.0",
"through2": "^2.0.1"
},
"devDependencies": {
"nyc": "^9.0.1",
"standard": "^8.5.0",
"tacks": "^1.2.2",
"tap": "^8.0.1"
},
"config": {
"nyc": {
"exclude": [
"node_modules/**",
"test/**"
]
}
}
}

@@ -1,16 +0,11 @@

var crypto = require('crypto')
var dezalgo = require('dezalgo')
var fs = require('fs')
var get = require('./get')
var mkdirp = require('mkdirp')
var mv = require('mv')
var from = require('from2')
var fs = require('graceful-fs')
var index = require('./lib/entry-index')
var inflight = require('inflight')
var path = require('path')
var pumpify = require('pumpify')
var through = require('through2')
var randomstring = require('randomstring')
var rimraf = require('rimraf')
var writeStreamAtomic = require('fs-write-stream-atomic')
var putContentStream = require('./lib/content/put-stream')
module.exports.file = putFile
function putFile (cache, filePath, opts, cb) {
function putFile (cache, key, filePath, opts, cb) {
if (!cb) {

@@ -21,2 +16,4 @@ cb = opts

cb = dezalgo(cb)
opts = Object.create(opts || {})
opts.filename = opts.filename || path.basename(filePath)
try {

@@ -27,7 +24,25 @@ var stream = fs.createReadStream(filePath)

}
return putStream(cache, stream, opts, cb)
return putStream(cache, key, stream, opts, cb)
}
module.exports.data = putData
function putData (cache, key, filename, data, opts, cb) {
if (!cb) {
cb = opts
opts = null
}
cb = dezalgo(cb)
opts = Object.create(opts || {})
opts.filename = filename
var stream = from(function (size, next) {
if (data.length <= 0) return next(null, null)
var chunk = data.slice(0, size)
data = data.slice(size)
next(null, chunk)
})
return putStream(cache, key, stream, opts, cb)
}
module.exports.stream = putStream
function putStream (cache, inputStream, opts, cb) {
function putStream (cache, key, inputStream, opts, cb) {
if (!cb) {

@@ -37,50 +52,26 @@ cb = opts

}
opts = opts || {}
var startTime = +(new Date())
var logger = opts.logger || noop
var tmpFile = path.join(cache, 'tmp', (opts.prefix || '') + randomstring.generate())
mkdirp(path.dirname(tmpFile), function (err) {
cb = inflight('cacache.put.stream: ' + key, cb)
if (!cb) { return }
return putContentStream(cache, inputStream, opts, function (err, digest) {
if (err) { cb(err) }
index.insert(cache, key, digest, opts, cb)
})
}
module.exports.metadata = putMetadata
function putMetadata (cache, key, metadata, opts, cb) {
if (!cb) {
cb = opts
opts = null
}
opts = Object.create(opts || {})
opts.metadata = metadata
opts.override = true
console.log('what the fuck tho')
index.find(cache, key, function (err, info) {
console.log('ok i read the thing', err, info)
if (err) { return cb(err) }
var outStream = writeStreamAtomic(tmpFile)
var hash = crypto.createHash(opts.algorithm || 'sha256')
var hashStream = through(function (chunk, enc, cb) {
hash.update(chunk, enc)
cb(null, chunk)
})
pumpify(
inputStream, hashStream, outStream
).on('error', function () {
rimraf(tmpFile, function (err) {
if (err) { cb(err) }
})
})
outStream.on('close', moveToDestination)
function moveToDestination () {
logger('verbose', 'Temporary file written. Moving to main cache.')
var digest = hash.digest('hex')
var destination = get.path(cache, digest)
mv(tmpFile, destination, {
mkdirp: true, clobber: !!opts.clobber
}, function (err) {
if (err) {
if (err.code === 'EEXIST') {
logger('verbose', digest, 'already has an entry in the cache. Skipping move')
} else if (err.code === 'EBUSY') {
logger('verbose', digest, 'exists and is already being accessed. Skipping move.')
} else {
return cb(err)
}
}
rimraf(tmpFile, function (err) {
if (err) { return cb(err) }
var timeDiff = +(new Date()) - startTime
logger('verbose', 'processed', digest, 'in', timeDiff + 'ms')
cb(null, digest)
})
})
}
if (!info) { return cb(index.notFoundError(cache, key)) }
index.insert(cache, key, info.digest, opts, cb)
})
}
function noop () {}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc