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

fs-blob-store

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-blob-store - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

4

example.js
var blobs = require('./')
var store = blobs('./data')
var store = blobs({path: './data'})

@@ -11,3 +11,3 @@ var w = store.createWriteStream()

console.log('blob written: '+w.hash)
store.createReadStream(w.hash).pipe(process.stdout)
store.createReadStream(w).pipe(process.stdout)
})

@@ -87,8 +87,15 @@ var fs = require('fs')

module.exports = function(dir, algo) {
module.exports = function(opts) {
if (!opts) opts = {}
var algo = opts.algo
if (!algo) algo = 'sha256'
var dir = opts.dir || opts.path
if (!dir) dir = path.join(process.cwd(), 'blobs')
var that = {}
var init = thunky(function(cb) {
var tmp = path.join(os.tmpDir(), 'blob-object-store')
var tmp = path.join(os.tmpDir(), 'fs-blob-store')
mkdirp(tmp, function() {

@@ -101,3 +108,4 @@ mkdirp(dir, function() {

that.createWriteStream = function(cb) {
that.createWriteStream = function(opts, cb) {
// dont use opts
var ws = new Writer(dir, algo, init)

@@ -108,3 +116,4 @@ if (!cb) return ws

if (err) return cb(err)
cb(null, ws.hash, ws.length)
ws.size = ws.length
cb(null, ws)
})

@@ -115,8 +124,8 @@

that.createReadStream = function(hash) {
return fs.createReadStream(toPath(dir, hash))
that.createReadStream = function(opts) {
return fs.createReadStream(toPath(dir, opts.hash))
}
that.exists = function(hash, cb) {
fs.stat(toPath(dir, hash), function(err, stat) {
that.exists = function(opts, cb) {
fs.stat(toPath(dir, opts.hash), function(err, stat) {
if (err && err.code === 'ENOENT') return cb(null, false)

@@ -128,5 +137,5 @@ if (err) return cb(err)

that.remove = function(hash, cb) {
that.remove = function(opts, cb) {
if (!cb) cb = noop
fs.unlink(toPath(dir, hash), function(err) {
fs.unlink(toPath(dir, opts.hash), function(err) {
if (err && err.code === 'ENOENT') return cb(null, false)

@@ -133,0 +142,0 @@ if (err) return cb(err)

{
"name": "fs-blob-store",
"version": "2.0.0",
"version": "3.0.0",
"description": "Streamable content addressable blob object store that is streams2 and implements the blob store interface on top of the fs module",

@@ -14,2 +14,3 @@ "main": "index.js",

"concat-stream": "^1.4.6",
"rimraf": "^2.2.8",
"tape": "^2.13.4"

@@ -16,0 +17,0 @@ },

# fs-blob-store
Streamable content addressable blob object store that is streams2 and implements the blob store interface on top of the fs module
Streamable content addressable blob object store that is streams2 and implements the blob store interface on top of the fs module.
Conforms to the [abstract-blob-store](https://github.com/maxogden/abstract-blob-store) API and passes it's test suite.
``` js

@@ -16,3 +18,3 @@ npm install fs-blob-store

var blobs = require('fs-blob-store')
var store = blobs('./data')
var store = blobs({path: './data'})

@@ -26,3 +28,3 @@ var w = store.createWriteStream()

console.log('blob written: '+w.hash)
store.createReadStream(w.hash).pipe(process.stdout)
store.createReadStream(w).pipe(process.stdout)
})

@@ -33,22 +35,24 @@ ```

#### `var store = blobs(dir)`
#### `var store = blobs(opts)`
Creates a new instance. `dir` will be created if it doesn't exist.
Creates a new instance. Opts should have a `path` property to where the blobs should live on the fs. The directory will be created if it doesn't exist. If not supplied it will default to `path.join(process.cwd(), 'blobs')`
#### `var readStream = store.createReadStream(hash)`
You can also specify a node `crytpo` module hashing algorithm to use using the `algo` key in options. The default is `sha256`.
Open a read stream to a blob
#### `var readStream = store.createReadStream(opts)`
Open a read stream to a blob. `opts` must have a `hash` key with the hash of the blob you want to read.
#### `var writeStream = store.createWriteStream([cb])`
Add a new blob to the store. Use `writeStream.hash` to get the hash after the `finish` event has fired
or add a callback which will be called with `callback(err, hash)`
or add a callback which will be called with `callback(err, metadata)`.
#### `store.exists(hash, cb)`
#### `store.exists(metadata, cb)`
Check if an hash exists in the blob store. Callback is called with `callback(err, exists)`
Check if an blob exists in the blob store. `metadata` must have a `hash` property. Callback is called with `callback(err, exists)`
#### `store.remove(hash, [cb])`
#### `store.remove(metadata, [cb])`
Remove a blob from the store. Callback is called with `callback(err, wasDeleted)`
Remove a blob from the store. `metadata` must have a `hash` property. Callback is called with `callback(err, wasDeleted)`

@@ -55,0 +59,0 @@ ## License

@@ -1,66 +0,40 @@

var tape = require('tape')
var concat = require('concat-stream')
var fs = require('fs')
var os = require('os')
var blobs = require('./')
var path = require('path')
var store = blobs(os.tmpDir())
var test = require('tape')
var rimraf = require('rimraf')
var abstractBlobTests = require('abstract-blob-store/tests')
tape('add file', function(t) {
var w = store.createWriteStream()
w.write('hello')
w.write('world')
w.end(function() {
t.same(w.hash, '936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af', 'hash should match')
t.end()
})
})
var blobs = require('./')
var blobPath = path.join(os.tmpdir(), 'fs-blob-store-tests')
tape('add file + cb', function(t) {
var w = store.createWriteStream(function(err, hash) {
t.same(hash, '936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af', 'hash should match')
t.end()
})
var common = {
setup: function(t, cb) {
rimraf(blobPath, function() {
var store = blobs({path: blobPath})
cb(null, store)
})
},
teardown: function(t, store, blob, cb) {
rimraf(blobPath, cb)
}
}
w.write('hello')
w.write('world')
w.end()
})
abstractBlobTests(test, common)
tape('add file + exists', function(t) {
var w = store.createWriteStream()
w.write('hello')
w.write('world')
w.end(function() {
store.exists(w.hash, function(err, exists) {
t.notOk(err, 'no err')
t.ok(exists, 'should exist')
t.end()
test('remove file', function(t) {
common.setup(t, function(err, store) {
var w = store.createWriteStream()
w.write('hello')
w.write('world')
w.end(function() {
store.remove(w, function(err, deleted) {
t.notOk(err, 'no err')
t.ok(deleted, 'was deleted')
common.teardown(t, null, null, function(err) {
t.end()
})
})
})
})
})
tape('add file + read file', function(t) {
var w = store.createWriteStream()
w.write('hello')
w.write('world')
w.end(function() {
store.createReadStream(w.hash).pipe(concat(function(data) {
t.same(data.toString(), 'helloworld')
t.end()
}))
})
})
tape('remove file', function(t) {
var w = store.createWriteStream()
w.write('hello')
w.write('world')
w.end(function() {
store.remove(w.hash, function(err, deleted) {
t.notOk(err, 'no err')
t.ok(deleted, 'was deleted')
t.end()
})
})
})
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