Comparing version 4.0.0 to 5.0.0
27
get.js
var index = require('./lib/entry-index') | ||
var finished = require('mississippi').finished | ||
var pipe = require('mississippi').pipe | ||
@@ -6,5 +7,27 @@ var read = require('./lib/content/read') | ||
module.exports.stream = stream | ||
module.exports = function get (cache, key, opts, cb) { | ||
return getData(false, cache, key, opts, cb) | ||
} | ||
module.exports.byDigest = function getByDigest (cache, digest, opts, cb) { | ||
return getData(true, cache, digest, opts, cb) | ||
} | ||
function getData (byDigest, cache, key, opts, cb) { | ||
if (!cb) { | ||
cb = opts | ||
opts = null | ||
} | ||
opts = opts || {} | ||
var src = (byDigest ? getStream.byDigest : getStream)(cache, key, opts) | ||
var data = '' | ||
var meta | ||
src.on('data', function (d) { data += d }) | ||
src.on('metadata', function (m) { meta = m }) | ||
finished(src, function (err) { | ||
cb(err, data, meta) | ||
}) | ||
} | ||
module.exports.stream = getStream | ||
module.exports.stream.byDigest = read.readStream | ||
function stream (cache, key, opts) { | ||
function getStream (cache, key, opts) { | ||
var stream = through() | ||
@@ -11,0 +34,0 @@ index.find(cache, key, function (err, data) { |
@@ -20,5 +20,5 @@ var asyncMap = require('slide/lib/async-map') | ||
var lock = bucket + '.lock' | ||
var cb = function (err) { | ||
var cb = function (err, entry) { | ||
lockfile.unlock(lock, function (er) { | ||
_cb(er || err) | ||
_cb(er || err, entry) | ||
}) | ||
@@ -56,3 +56,5 @@ } | ||
if (err) { return cb(err) } | ||
fixOwner.chownr(bucket, opts.uid, opts.gid, cb) | ||
fixOwner.chownr(bucket, opts.uid, opts.gid, function (err) { | ||
cb(err, entry) | ||
}) | ||
}) | ||
@@ -158,3 +160,3 @@ }) | ||
// relatively readable key. Conflicts handled by buckets. | ||
return key.replace(/[^a-z0-9]/ig, '').toLowerCase().slice(0, 30) | ||
return key.replace(/[^a-z0-9_-]+/ig, '_').toLowerCase().slice(0, 120) | ||
} | ||
@@ -161,0 +163,0 @@ |
{ | ||
"name": "cacache", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "General content-addressable cache system that maintains a filesystem registry of file data.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
45
put.js
var index = require('./lib/entry-index') | ||
var pipe = require('mississippi').pipe | ||
var putContent = require('./lib/content/put-stream') | ||
var through = require('mississippi').through | ||
var to = require('mississippi').to | ||
module.exports = putData | ||
function putData (cache, key, data, opts, cb) { | ||
if (!cb) { | ||
cb = opts | ||
opts = null | ||
} | ||
opts = opts || {} | ||
var src = through() | ||
var meta | ||
var dest = putStream(cache, key, opts) | ||
dest.on('metadata', function (m) { meta = m }) | ||
pipe(src, dest, function (err) { | ||
cb(err, meta) | ||
}) | ||
src.write(data, function () { | ||
src.end() | ||
}) | ||
} | ||
module.exports.stream = putStream | ||
function putStream (cache, key, opts) { | ||
opts = opts || {} | ||
var digest | ||
@@ -11,7 +33,26 @@ var contentStream = putContent(cache, opts).on('digest', function (d) { | ||
}) | ||
return to(function (chunk, enc, cb) { | ||
var errored = false | ||
var stream = to(function (chunk, enc, cb) { | ||
contentStream.write(chunk, enc, cb) | ||
}, function (cb) { | ||
index.insert(cache, key, digest, opts, cb) | ||
contentStream.end(function () { | ||
index.insert(cache, key, digest, opts, function (err, entry) { | ||
if (err) { return cb(err) } | ||
stream.emit('digest', digest) | ||
stream.emit('metadata', entry) | ||
cb() | ||
}) | ||
}) | ||
}) | ||
stream.on('error', function (err) { | ||
if (errored) { return } | ||
errored = true | ||
contentStream.emit('error', err) | ||
}) | ||
contentStream.on('error', function (err) { | ||
if (errored) { return } | ||
errored = true | ||
stream.emit('error', err) | ||
}) | ||
return stream | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31880
707