Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multiblob

Package Overview
Dependencies
Maintainers
21
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiblob - npm Package Compare versions

Comparing version 1.13.4 to 1.13.5

99

index.js

@@ -54,3 +54,4 @@ var cont = require('cont')

var n = 0
var waiting = [], tmp = false
var waiting = []
var tmp = false

@@ -77,7 +78,7 @@ function init (cb) {

function has (hash) {
function has (id) {
return function (cb) {
if(isEmptyHash(hash)) return cb(null, true)
var p = toPath(dir, hash)
if(!p) return cb(new Error('not a valid blob hash:'+hash))
if(isEmptyHash(id)) return cb(null, true)
var p = toPath(dir, id)
if(!p) return cb(new Error('not a valid blob id:'+id))
stat(p, function (err, stat) {

@@ -89,7 +90,7 @@ cb(null, !!stat)

function size (hash) {
function size (id) {
return function (cb) {
if(isEmptyHash(hash)) return cb(null, 0)
var p = toPath(dir, hash)
if(!p) return cb(new Error('not a valid blob hash:'+hash))
if(isEmptyHash(id)) return cb(null, 0)
var p = toPath(dir, id)
if(!p) return cb(new Error('not a valid blob id:'+id))
stat(p, function (err, stat) {

@@ -101,6 +102,6 @@ cb(null, stat ? stat.size : null)

var meta = function (hash, cb) {
if(isEmptyHash(hash)) return cb(null, {id: hash, size: 0, ts: 0})
stat(toPath(dir, hash), function (err, stat) {
cb(err, toMeta(hash, stat))
var meta = function (id, cb) {
if(isEmptyHash(id)) return cb(null, {id: id, size: 0, ts: 0})
stat(toPath(dir, id), function (err, stat) {
cb(err, toMeta(id, stat))
})

@@ -110,13 +111,13 @@ }

function createTester (test) {
return function (hashes, cb) {
var n = !Array.isArray(hashes)
return function (ids, cb) {
var n = !Array.isArray(ids)
//check if any hashes are invalid.
var invalid
if(n ? !isHash(hashes) : !hashes.every(function (h) {
if(n ? !isHash(ids) : !ids.every(function (h) {
if(!isHash(h)) invalid = h
else return true
}))
return cb(new Error('not a valid hash:'+invalid))
return cb(new Error('not a valid id:'+invalid))
cont.para(u.toArray(hashes).map(test)) (function (err, ary) {
cont.para(u.toArray(ids).map(test)) (function (err, ary) {
//will give an error if any hash was invalid.

@@ -136,6 +137,8 @@ if(err) cb(err)

function getSlice(opts) {
if(isEmptyHash(opts.hash)) return pull.empty()
var id = u.getId(opts)
if(isEmptyHash(id)) return pull.empty()
var stream = defer.source()
stat(toPath(dir, opts.hash), function (err, stat) {
stat(toPath(dir, id), function (err, stat) {
if(err)

@@ -147,3 +150,3 @@ stream.abort(explain(err, 'stat failed'))

+ ' requested:' + opts.size + ' file was:' + stat.size
+ ' for file:' + opts.hash
+ ' for file:' + id
))

@@ -154,7 +157,7 @@

+ ' requested:' + opts.size + ' file was:' + stat.size
+ ' for file:' + opts.hash
+ ' for file:' + id
))
else
stream.resolve(u.readFile(toPath(dir, opts.hash), {
stream.resolve(u.readFile(toPath(dir, id), {
start: opts.start,

@@ -172,12 +175,13 @@ end: opts.end

if(isHash(opts)) {
if(isEmptyHash(hash)) return pull.empty()
if(isEmptyHash(opts)) return pull.empty()
return u.readFile(toPath(dir, opts))
}
var hash = opts.key || opts.hash
if(!isHash(hash))
var id = u.getId(opts)
if(!isHash(id))
return pull.error(new Error(
'multiblob.get: {hash} is mandatory'
'multiblob.get: {id} is mandatory'
))
return getSlice({hash: hash, size: opts.size, max: opts.max})
return getSlice({id: id, size: opts.size, max: opts.max})
},

@@ -187,5 +191,6 @@ isEmptyHash: isEmptyHash,

getSlice: function (opts) {
if(!isHash(opts.hash))
var id = u.getId(opts)
if(!isHash(id))
return pull.error(new Error(
'multiblob.getSlice: {hash} is mandatory'
'multiblob.getSlice: {id} is mandatory'
))

@@ -211,4 +216,4 @@

add: function (hash, cb) {
if('function' === typeof hash) cb = hash, hash = null
add: function (id, cb) {
if('function' === typeof id) cb = id, id = null

@@ -219,5 +224,5 @@ if(!cb) cb = function (err) {

if(hash && !isHash(hash)) {
if(id && !isHash(id)) {
//abort input stream and callback once source is aborted.
var err = new Error('not a valid hash:'+hash)
var err = new Error(`not a valid hash: ${id}`)
return function (read) {

@@ -244,9 +249,9 @@ read(err, cb)

var _hash = encode(hasher.digest, alg)
var _id = encode(hasher.digest, alg)
if(hash && hash !== _hash)
return cb(new Error('actual hash:'+ _hash
+ ' did not match expected hash:'+hash), _hash)
if(id && id !== _id)
return cb(new Error('actual hash:'+ _id
+ ' did not match expected id:'+id), _id)
var p = toPath(dir, hash || _hash)
var p = toPath(dir, id || _id)

@@ -256,3 +261,3 @@ mkdirp(path.dirname(p), function () {

if(err) cb(explain(err, 'could not move file'))
else newBlob({id:toHash(p), size: size, ts: Date.now()}), cb(null, _hash)
else newBlob({id:toHash(p), size: size, ts: Date.now()}), cb(null, _id)
})

@@ -284,10 +289,10 @@ })

rm: function (hash, cb) {
if(!isHash(hash)) cb(new Error('not valid hash:'+hash))
else fs.unlink(toPath(dir, hash), cb)
rm: function (id, cb) {
if(!isHash(id)) cb(new Error('not valid id:'+id))
else fs.unlink(toPath(dir, id), cb)
},
resolve: function (hash) {
if(!isHash(hash)) throw new Error('not valid hash:'+hash)
return toPath(dir, hash)
resolve: function (id) {
if(!isHash(id)) throw new Error('not valid id:'+id)
return toPath(dir, id)
}

@@ -297,3 +302,1 @@ }

{
"name": "multiblob",
"description": "",
"version": "1.13.4",
"version": "1.13.5",
"homepage": "https://github.com/dominictarr/multiblob",

@@ -6,0 +6,0 @@ "repository": {

@@ -50,3 +50,3 @@ # multiblob

### blbos.getSlice(opts) => Source
### blobs.getSlice(opts) => Source

@@ -53,0 +53,0 @@ create a source stream that reads a slice of a given blob,

@@ -108,1 +108,3 @@ var Blake2s = require('blake2s')

}
exports.getId = (opts) => opts.id || opts.key || opts.hash
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc