|
@@ -3,7 +3,9 @@
|
|
|
function Radisk(opt){
|
|
|
|
|
|
opt = opt || {};
|
|
|
+ opt.log = opt.log || console.log;
|
|
|
opt.file = String(opt.file || 'radata');
|
|
|
+ opt.pack = opt.pack || (opt.memory? (opt.memory * 1000 * 1000) : 1399000000) * 0.3; // max_old_space_size defaults to 1400 MB.
|
|
|
opt.until = opt.until || opt.wait || 9;
|
|
|
opt.batch = opt.batch || 10 * 1000;
|
|
|
opt.chunk = opt.chunk || (1024 * 1024 * 10); // 10MB
|
|
@@ -14,16 +16,16 @@
|
|
|
var map = Gun.obj.map;
|
|
|
|
|
|
if(!opt.store){
|
|
|
- return Gun.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
|
|
|
+ return opt.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
|
|
|
}
|
|
|
if(!opt.store.put){
|
|
|
- return Gun.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");
|
|
|
+ return opt.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");
|
|
|
}
|
|
|
if(!opt.store.get){
|
|
|
- return Gun.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");
|
|
|
+ return opt.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");
|
|
|
}
|
|
|
if(!opt.store.list){
|
|
|
- Gun.log("WARNING: `store.list` interface might be needed!");
|
|
|
+ //opt.log("WARNING: `store.list` interface might be needed!");
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -73,7 +75,7 @@
|
|
|
r.batch.ed = 0;
|
|
|
r.save(batch, function(err, ok){
|
|
|
if(++i > 1){ return }
|
|
|
- if(err){ Gun.log('err', err) }
|
|
|
+ if(err){ opt.log('err', err) }
|
|
|
map(batch.acks, function(cb){ cb(err, ok) });
|
|
|
thrash.at = null;
|
|
|
thrash.ing = false;
|
|
@@ -141,6 +143,7 @@
|
|
|
f.file = file;
|
|
|
f.each = function(val, key, k, pre){
|
|
|
if(u !== val){ f.count++ }
|
|
|
+ if(opt.pack <= (val||'').length){ return cb("Record too big!"), true }
|
|
|
var enc = Radisk.encode(pre.length) +'#'+ Radisk.encode(k) + (u === val? '' : '='+ Radisk.encode(val)) +'\n';
|
|
|
if((opt.chunk < f.text.length + enc.length) && (1 < f.count) && !force){
|
|
|
f.text = '';
|
|
@@ -206,7 +209,7 @@
|
|
|
g.file = file;
|
|
|
}
|
|
|
g.it = function(err, disk){
|
|
|
- if(g.err = err){ Gun.log('err', err) }
|
|
|
+ if(g.err = err){ opt.log('err', err) }
|
|
|
if(disk){ RAD = g.disk = disk }
|
|
|
disk = Q[g.file]; delete Q[g.file];
|
|
|
map(disk, g.ack);
|
|
@@ -243,6 +246,16 @@
|
|
|
//return cb(err, u);//map(q, p.ack);
|
|
|
return map(q, p.ack);
|
|
|
}
|
|
|
+ if(typeof data !== 'string'){
|
|
|
+ try{
|
|
|
+ if(opt.pack <= data.length){
|
|
|
+ p.err = "Chunk too big!";
|
|
|
+ } else {
|
|
|
+ data = data.toString();
|
|
|
+ }
|
|
|
+ }catch(e){ p.err = e }
|
|
|
+ if(p.err){ return map(q, p.ack) }
|
|
|
+ }
|
|
|
var tmp = p.split(data), pre = [], i, k, v;
|
|
|
while(tmp){
|
|
|
k = v = u;
|
|
@@ -309,7 +322,7 @@
|
|
|
}
|
|
|
r.list.init = function(err, disk){
|
|
|
if(err){
|
|
|
- Gun.log('list', err);
|
|
|
+ opt.log('list', err);
|
|
|
setTimeout(function(){ r.parse(f, r.list.init) }, 1000);
|
|
|
return;
|
|
|
}
|