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

multiblob

Package Overview
Dependencies
Maintainers
1
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.2.0 to 1.3.0

test/size.js

56

index.js

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

var util = require('./util')
var createHash = util.createHash, toPath = util.toPath
var createHash = util.createHash, toPath = util.toPath, isHash = util.isHash

@@ -48,10 +48,14 @@ function write (filename, cb) {

return {
get: function (hash) {
return read(toPath(dir, hash))
},
function size (hash) {
return function (cb) {
fs.stat(toPath(dir, hash), function (err, stat) {
cb(null, stat ? stat.size : null)
})
}
}
has: function (hashes, cb) {
function createTester (test) {
return function (hashes, cb) {
var n = !Array.isArray(hashes)
cont.para(toArray(hashes).map(has)) (function (_, ary) {
cont.para(toArray(hashes).map(test)) (function (_, ary) {
// This will only error if the hash is not present,

@@ -65,4 +69,42 @@ // so never callback an error.

return cb
}
}
return {
get: function (opts) {
if(isHash(opts))
return read(toPath(dir, opts))
var hash = opts.key || opts.hash
if(!isHash(hash))
return pull.error(new Error(
'multiblob.get: {hash} is mandatory'
))
var stream = defer.source()
fs.stat(toPath(dir, hash), function (err, stat) {
if(opts.size != null && opts.size !== stat.size)
stream.abort(new Error('incorrect file length,'
+ ' requested:' + opts.size + ' file was:' + stat.size
+ ' for file:' + hash
))
else if(opts.max != null && opts.max < stat.size)
stream.abort(new Error('incorrect file length,'
+ ' requested:' + opts.size + ' file was:' + stat.size
+ ' for file:' + hash
))
else
stream.resolve(read(toPath(dir, hash)))
})
return stream
},
size: createTester(size),
has: createTester(has),
add: function (hash, cb) {

@@ -69,0 +111,0 @@ if(!cb) cb = hash, hash = null

2

package.json
{
"name": "multiblob",
"description": "",
"version": "1.2.0",
"version": "1.3.0",
"homepage": "https://github.com/dominictarr/multiblob",

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

@@ -28,3 +28,3 @@ # multiblob

### get (hash) => Source
### get (hash || opts) => Source

@@ -34,6 +34,20 @@ create a source stream that reads from a given blob.

If the argument is a `hash` string, then return the stream.
If the argument is an `opts` object, with the `key: hash` property,
retrive that blob, but error if the size does not exactly match the
`size` property, or is over `max` property (in bytes)
### has(hash, cb)
check if the given hash is in the store.
If `hash` is an array of hashes,
`size` will callback with an array of booleans.
### size(hash, cb)
get the size of this blob. If `hash` is an array of hashes,
`size` will callback with an array of sizes.
If the hash does not exist in the store, `size` will callback `null`.
### ls() => Source

@@ -40,0 +54,0 @@

@@ -27,1 +27,8 @@ var Blake2s = require('blake2s')

function isString (s) {
return 'string' === typeof s
}
exports.isHash = function (data) {
return isString(data) && /^[A-Za-z0-9\/+]{43}=\.blake2s$/.test(data)
}
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