sethvincent / hyperblobbee

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hyperblobbee

🚧 This is currently experimental and is unstable

Test on Node.js

A simple blob store for Hypercore built on Hyperbee, heavily inspired by andrewosh/hyperblobs.

Each blob is identified by unique (utf-8) key.

const db = new Hyperbee(core)
const blobs = new Hyperblobbee(db)

const key = 'my-first-file'
await blobs.put(key, Buffer.from('hello world', 'utf-8'))
await blobs.get(key) // Buffer.from('hello world', 'utf-8')

If the blob is large, there's a Streams interface (createReadStream and createWriteStream) too.

Installation

npm i hyperblobbee

API

const Hyperblobbee = require('hyperblobbee')

const blobs = new Hyperblobbee(db, opts)

Create a new blob store wrapping a single Hyperbee instance.

Options can include:

{
  blockSize: 65536, // The block size (bytes) that will be used when storing large blobs.
}

await blobs.put(key, blob, opts)

Store a new blob at key. If the blob is large, it will be chunked according to opts.blockSize (default 64KB).

Options can include:

{
  blockSize: 65536, // The block size (bytes) that will be used when storing large blobs.
}

const stream = blobs.createReadStream(key, opts)

Create a Readable stream that will yield the key blob.

Options match the get options.

const stream = blobs.createWriteStream(key, opts)

Create a Writable stream that will save a blob with key.

License

MIT

About


Languages

Language:JavaScript 100.0%