Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LevelDB radisk adapter #1012

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 2d0e4a3f-ac19-430c-bf1b-46c68651ce21
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_size = 2
indent_style = space

[*.{php,html}]
indent_size = 4

[Makefile*]
indent_style = tab
69 changes: 69 additions & 0 deletions lib/rlevel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var Gun = ('undefined' !== typeof window) ? window.Gun : require('../gun');
var debug = false;

// Adds opts.level, where the value is an initialized levelup (or compatible) instance
Gun.on('create', function(root) {
this.to.next(root);
var opt = root.opt;

if (debug) debug.emit('create');

// Check if the given 'level' argument implements all the components we need
// Intentionally doesn't check for levelup explicitly, to allow different handlers implementing the same api
if (
(!opt.level) ||
('object' !== typeof opt.level) ||
('function' !== typeof opt.level.get) ||
('function' !== typeof opt.level.put)
) {
return;
}

// Register our store
opt.store = opt.store || factory(opt);
});

function factory(opt) {
if (debug) debug.emit('factory');

var level = opt.level;
var store = {};

store.put = function(key, data, cb) {
if (debug) debug.emit('put', key, data);
level.put(key, data, function(err) {
if (debug && err) debug.emit('error', err);
cb(err, 'level');
});
};

store.get = function(key, cb) {
if (debug) debug.emit('get', key);
level.get(key, function(err, data) {
if (err && (err.name === 'NotFoundError')) err = undefined;
if (debug && err) debug.emit('error', err);
cb(err, data);
});
};

store.list = function(cb, match, params, cbs){
if (debug) debug.emit('list');
level
.createKeyStream()
.on('data', function(key) {
console.log("KEY", key);
cb(key);
})
.on('end', function() {
cb();
});
};

return store;
}

// Export debug interface
if ('undefined' === typeof window) {
var EventEmitter = require('events').EventEmitter;
module.exports = debug = new EventEmitter();
}
154 changes: 153 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
"@types/ws": "^7.2.1",
"aws-sdk": "^2.528.0",
"ip": "^1.1.5",
"leveldown": "^5.6.0",
"levelup": "^4.4.0",
"mocha": "^6.2.0",
"panic-manager": "^1.2.0",
"panic-server": "^1.1.1",
Expand Down
Loading