# content-addressable-blob-store

> Streamable content addressable blob object store that is streams2 and implements the blob store interface on top of the fs module

Latest version **5.1.0** (published 2020-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install content-addressable-blob-store
pnpm add content-addressable-blob-store
yarn add content-addressable-blob-store
bun add content-addressable-blob-store
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2020-06-11 |
| First published | 2014-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 59 |
| Author | Mathias Buus |
| Maintainers | bret, mafintosh |
| Keywords | blob, object, store, content, addressable, streams2 |

## Links

- npm: https://www.npmjs.com/package/content-addressable-blob-store
- Repository: https://github.com/mafintosh/content-addressable-blob-store
- Issues: https://github.com/mafintosh/content-addressable-blob-store/issues
- npm.io page: https://npm.io/package/content-addressable-blob-store

## Dependencies (4)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.0
- [thunky](https://npm.io/package/thunky.md) ^1.0.3
- [end-of-stream](https://npm.io/package/end-of-stream.md) ^1.0.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^3.4.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 5.1.0 (latest) — 2020-06-11
- 5.0.1 — 2019-09-27
- 5.0.0 — 2019-08-08
- 4.6.0 — 2017-07-26
- 4.5.1 — 2017-06-11
- 4.5.0 — 2017-06-10
- 4.3.1 — 2017-06-10
- 4.3.0 — 2015-12-28
- 4.2.1 — 2015-07-15
- 4.2.0 — 2015-07-15
- 4.1.2 — 2015-07-15
- 4.1.1 — 2014-09-30
- 4.1.0 — 2014-09-29
- 4.0.4 — 2014-09-06
- 4.0.3 — 2014-08-30

## README

# content-addressable-blob-store

Streamable content addressable [blob](http://en.wikipedia.org/wiki/Binary_large_object) 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
npm install content-addressable-blob-store
```

[![build status](http://img.shields.io/travis/mafintosh/content-addressable-blob-store.svg?style=flat)](http://travis-ci.org/mafintosh/content-addressable-blob-store)
![dat](http://img.shields.io/badge/Development%20sponsored%20by-dat-green.svg?style=flat)

[![blob-store-compatible](https://raw.githubusercontent.com/maxogden/abstract-blob-store/master/badge.png)](https://github.com/maxogden/abstract-blob-store)

## Usage

``` js
var blobs = require('content-addressable-blob-store')
var store = blobs('./data')

var w = store.createWriteStream()

w.write('hello ')
w.write('world\n')

w.end(function () {
  console.log('blob written: '+w.key)
  store.createReadStream(w).pipe(process.stdout)
})
```

## API

#### `var store = blobs(opts)`

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')`

You can also specify a node `crypto` module hashing algorithm to use using the `algo` key in options. The default is `sha256`.
If you pass a string instead of an options map it will be used as the `path` as well.

The `tmpdir` option can be used to specify the directory where files are stored temporarily during writing. The default is `os.tmpdir()`.

#### `var readStream = store.createReadStream(opts)`

Open a read stream to a blob. `opts` must have a `key` key with the hash of the blob you want to read. `opts` can optionally contain a `start` or `end` key if you only want part of the blob.

#### `var writeStream = store.createWriteStream([cb])`

Add a new blob to the store. Use `writeStream.key` to get the hash after the `finish` event has fired
or add a callback which will be called with `callback(err, metadata)`.

#### `store.exists(metadata, cb)`

Check if an blob exists in the blob store. `metadata` must have a `key` property. Callback is called with `callback(err, exists)`


#### `store.remove(metadata, [cb])`

Remove a blob from the store. `metadata` must have a `key` property. Callback is called with `callback(err, wasDeleted)`

#### `store.resolve(metadata, cb)`

Check if an blob exists in the blob store and return its `path` and `stat` object. `metadata` must have a `key` property. Callback is called with `callback(err, path, stat)` where `path` is the path string to the file on disk and `stat` is an instance of [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats).  If the `key` does does not exist in the store, `path` will be `false` and `stat` will be `null`.

## License

MIT

---
_Source: https://npm.io/package/content-addressable-blob-store · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
