Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.
/ levelup Public archive
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/levelup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}
})
}
Expand Down Expand Up @@ -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)
}
})
}
Expand Down
14 changes: 10 additions & 4 deletions lib/read-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -78,15 +84,15 @@ 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)
return self._cleanup(err)
}

try {
value = self._makeData(key, value)
value = self._makeData(key, value, extra)
} catch (e) {
return self._cleanup(new EncodingError(e))
}
Expand Down