diff --git a/lib/levelup.js b/lib/levelup.js index 22b6721e..63939eb6 100644 --- a/lib/levelup.js +++ b/lib/levelup.js @@ -186,7 +186,7 @@ LevelUP.prototype.get = function (key_, options, callback) { options.asBuffer = util.isValueAsBuffer(options) - this.db.get(key, options, function (err, value) { + this.db.get(key, options, function (err, value, extra) { if (err) { if ((/notfound/i).test(err)) { err = new NotFoundError( @@ -202,7 +202,7 @@ LevelUP.prototype.get = function (key_, options, callback) { } catch (e) { return callback(new EncodingError(e)) } - callback(null, value) + callback(null, value, extra) } }) } @@ -235,13 +235,13 @@ LevelUP.prototype.put = function (key_, value_, options, callback) { key = util.encodeKey(key_, options) value = util.encodeValue(value_, options) - this.db.put(key, value, options, function (err) { + this.db.put(key, value, options, function (err, extra) { if (err) { return dispatchError(self, new WriteError(err), callback) } else { - self.emit('put', key_, value_) + self.emit('put', key_, value_, extra) if (callback) - callback() + callback(null, extra) } }) } diff --git a/lib/read-stream.js b/lib/read-stream.js index 003da5da..ccaebe48 100644 --- a/lib/read-stream.js +++ b/lib/read-stream.js @@ -13,11 +13,17 @@ var Readable = require('readable-stream').Readable , defaultOptions = { keys: true, values: true } - , makeKeyValueData = function (key, value) { - return { + , makeKeyValueData = function (key, value, extra) { + var result = { key: util.decodeKey(key, this._options) , value: util.decodeValue(value, this._options) + }; + + if (typeof extra !== 'undefined') { + result.extra = extra; } + + return result; } , makeKeyData = function (key) { return util.decodeKey(key, this._options) @@ -78,7 +84,7 @@ ReadStream.prototype._read = function read () { if (self._destroyed) return - self._iterator.next(function(err, key, value) { + self._iterator.next(function(err, key, value, extra) { if (err || (key === undefined && value === undefined)) { if (!err && !self._destroyed) self.push(null) @@ -86,7 +92,7 @@ ReadStream.prototype._read = function read () { } try { - value = self._makeData(key, value) + value = self._makeData(key, value, extra) } catch (e) { return self._cleanup(new EncodingError(e)) }