Comparing version 1.10.0 to 1.10.1
65
index.js
@@ -13,3 +13,3 @@ var cont = require('cont') | ||
var Notify = require('pull-notify') | ||
var Live = require('pull-live') | ||
var Write = require('pull-write-file') | ||
@@ -71,2 +71,3 @@ var Read = require('pull-file') | ||
function toPath (dir, string) { | ||
if(!string || !isHash(string)) return false | ||
var d = decode(string) | ||
@@ -115,3 +116,6 @@ var h = d.hash.toString('hex') | ||
return function (cb) { | ||
stat(toPath(dir, hash), function (err, stat) { | ||
var p = toPath(dir, hash) | ||
console.log('HAS', p, dir, hash, isHash, toPath) | ||
if(!p) return cb(new Error('not a valid blob hash:'+hash)) | ||
stat(p, function (err, stat) { | ||
cb(null, !!stat) | ||
@@ -124,3 +128,5 @@ }) | ||
return function (cb) { | ||
stat(toPath(dir, hash), function (err, stat) { | ||
var p = toPath(dir, hash) | ||
if(!p) return cb(new Error('not a valid blob hash:'+hash)) | ||
stat(p, function (err, stat) { | ||
cb(null, stat ? stat.size : null) | ||
@@ -140,3 +146,13 @@ }) | ||
var n = !Array.isArray(hashes) | ||
cont.para(toArray(hashes).map(test)) (function (_, ary) { | ||
//check if any hashes are invalid. | ||
var invalid | ||
if(n ? !isHash(hashes) : !hashes.every(function (h) { | ||
if(!isHash(h)) invalid = h | ||
else return true | ||
})) | ||
return cb(new Error('not a valid hash:'+invalid)) | ||
cont.para(toArray(hashes).map(test)) (function (err, ary) { | ||
//will give an error if any hash was invalid. | ||
if(err) cb(err) | ||
// This will only error if the hash is not present, | ||
@@ -146,4 +162,4 @@ // so never callback an error. | ||
// add a comment like this one to explain why. | ||
if(n) cb(null, ary[0]) | ||
else cb(null, ary) | ||
else if(n) cb(null, ary[0]) | ||
else cb(null, ary) | ||
}) | ||
@@ -200,2 +216,10 @@ return cb | ||
if(hash && !isHash(hash)) { | ||
//abort input stream and callback once source is aborted. | ||
var err = new Error('not a valid hash:'+hash) | ||
return function (read) { | ||
read(err, cb) | ||
} | ||
} | ||
var deferred = defer.sink() | ||
@@ -237,12 +261,6 @@ init(function () { | ||
}, | ||
ls: function (opts) { | ||
opts = opts || {} | ||
var isOld = opts.old !== false | ||
var isLive = opts.live === true || opts.old === false | ||
if(!isLive && !isOld) | ||
throw new Error('ls with neither old or new is empty') | ||
ls: Live(function old (opts) { | ||
var long = (opts.size || opts.long || opts.meta) | ||
var old = pull( | ||
return pull( | ||
glob(path.join(dir, '*', '*', '*')), | ||
@@ -255,18 +273,16 @@ long ? paramap(function (filename, cb) { | ||
) | ||
if(!isLive) return old | ||
var live = long | ||
}, function live (opts) { | ||
var long = (opts.size || opts.long || opts.meta) | ||
return long | ||
? newBlob.listen() | ||
: pull(newBlob.listen(), pull.map(function (e) { return e.id })) | ||
}), | ||
if(!isOld) return live | ||
//old & live | ||
return cat([old, pull.once({sync: true}), live]) | ||
}, | ||
rm: function (hash, cb) { | ||
fs.unlink(toPath(dir, hash), cb) | ||
if(!isHash(hash)) cb(new Error('not valid hash:'+hash)) | ||
else fs.unlink(toPath(dir, hash), cb) | ||
}, | ||
resolve: function (hash) { | ||
if(!isHash(hash)) throw new Error('not valid hash:'+hash) | ||
return toPath(dir, hash) | ||
@@ -277,2 +293,1 @@ } | ||
{ | ||
"name": "multiblob", | ||
"description": "", | ||
"version": "1.10.0", | ||
"version": "1.10.1", | ||
"homepage": "https://github.com/dominictarr/multiblob", | ||
@@ -19,2 +19,3 @@ "repository": { | ||
"pull-glob": "~1.0.6", | ||
"pull-live": "^1.0.0", | ||
"pull-notify": "0.0.2", | ||
@@ -21,0 +22,0 @@ "pull-paramap": "^1.1.4", |
@@ -46,3 +46,4 @@ | ||
t.equal(hash, hash1) | ||
blobs.has(hash, function (_, has) { | ||
blobs.has(hash, function (err, has) { | ||
if(err) throw err | ||
t.ok(has) | ||
@@ -88,3 +89,4 @@ t.end() | ||
tape('has can take array', function (t) { | ||
blobs.has([hash1, hash2], function (_, ary) { | ||
blobs.has([hash1, hash2], function (err, ary) { | ||
if(err) throw err | ||
t.deepEqual(ary, [true, false]) | ||
@@ -142,3 +144,3 @@ t.end() | ||
}) | ||
return | ||
//sometimes there are apis that need direct access | ||
@@ -160,2 +162,11 @@ //i.e. in electron. | ||
tape('error if a a request is not a valid hash', function (t) { | ||
blobs.has('NOT A HASH', function (err) { | ||
console.log(err) | ||
t.ok(err) | ||
t.end() | ||
}) | ||
}) | ||
} | ||
@@ -170,1 +181,2 @@ | ||
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
25831
726
15
+ Addedpull-live@^1.0.0
+ Addedpull-live@1.0.1(transitive)