level-blobs
Advanced tools
Comparing version 0.1.1 to 0.1.2
19
index.js
@@ -7,2 +7,12 @@ var Writable = require('readable-stream/writable'); | ||
var EMPTY = new Buffer(0); | ||
var ENCODER = { | ||
encode: function(data) { | ||
return typeof data === 'string' ? data = new Buffer(data) : data; | ||
}, | ||
decode: function(data) { | ||
return Buffer.isBuffer(data) ? data : new Buffer(data); | ||
}, | ||
buffer: true, | ||
type: 'raw' | ||
}; | ||
@@ -55,3 +65,3 @@ var noop = function() {}; | ||
db.get(key, {valueEncoding:'binary'}, function(err, block) { | ||
db.get(key, {valueEncoding:ENCODER}, function(err, block) { | ||
if (err && !err.notFound) return cb(err); | ||
@@ -137,3 +147,4 @@ if (!reservations[key]) reservations[key] = {locks:0, block:block}; | ||
key: key, | ||
value: block | ||
value: block, | ||
valueEncoding: ENCODER | ||
}); | ||
@@ -239,3 +250,3 @@ | ||
lt: name+'\xff\xff', | ||
valueEncoding: 'binary' | ||
valueEncoding: ENCODER | ||
}); | ||
@@ -340,3 +351,3 @@ | ||
if (!latest) return cb(null, 0); | ||
db.get(latest, {valueEncoding:'binary'}, function(err, val) { | ||
db.get(latest, {valueEncoding:ENCODER}, function(err, val) { | ||
if (err && err.notFound) return cb(null, 0); | ||
@@ -343,0 +354,0 @@ if (err) return cb(err); |
{ | ||
"name": "level-blobs", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Save binary blobs in level and stream then back", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/mafintosh/level-blobs.git", |
15422
455