level-blobs
Version:
Save binary blobs in level and stream then back
90 lines (61 loc) • 2.19 kB
Markdown
Save binary blobs in level and stream then back.
Similar to [level-store](https://github.com/juliangruber/level-store) but streams2 and with support for random access writes and reads
npm install level-blobs
[](http://travis-ci.org/mafintosh/level-blobs)

[](https://ci.testling.com/mafintosh/level-blobs)
``` js
var blobs = require('level-blobs');
var level = require('level');
var db = level('/tmp/my-blobs-db');
var bl = blobs(db);
// create a write stream
var ws = blobs.createWriteStream('my-file.txt');
ws.on('finish', function() {
// lets read the blob and pipe it to stdout
var rs = blobs.createReadStream('my-file.txt');
rs.pipe(process.stdout);
});
ws.write('hello ');
ws.write('world');
ws.end();
```
Create a new blobs instance. Options default to
``` js
{
blockSize: 65536, // byte size for each block of data stored
batch: 100 // batch at max 100 blocks when writing
}
```
Create a read stream for `name`. Options default to
``` js
{
start: 0 // start reading from this byte offset
end: Infinity // end at end-of-file or this offset (inclusive)
}
```
Create a write stream to `name`. Options default to
``` js
{
start: 0 // start writing at this offset
// if append === true start defaults to end-of-file
append: false // set to true if you want to append to the file
// if not true the file will be truncated before writing
}
```
Create a read stream and buffer the stream into a single buffer that is passed to the callback.
Options are passed to `createReadStream`.
Write `data` to `name` and call the callback when done.
Options are passed to `createWriteStream`.
Remove `name` from the blob store
MIT