|
@@ -3,7 +3,9 @@
|
|
function Radisk(opt){
|
|
function Radisk(opt){
|
|
|
|
|
|
opt = opt || {};
|
|
opt = opt || {};
|
|
|
|
+ opt.log = opt.log || console.log;
|
|
opt.file = String(opt.file || 'radata');
|
|
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.until = opt.until || opt.wait || 9;
|
|
opt.batch = opt.batch || 10 * 1000;
|
|
opt.batch = opt.batch || 10 * 1000;
|
|
opt.chunk = opt.chunk || (1024 * 1024 * 10); // 10MB
|
|
opt.chunk = opt.chunk || (1024 * 1024 * 10); // 10MB
|
|
@@ -14,16 +16,16 @@
|
|
var map = Gun.obj.map;
|
|
var map = Gun.obj.map;
|
|
|
|
|
|
if(!opt.store){
|
|
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){
|
|
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){
|
|
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){
|
|
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.batch.ed = 0;
|
|
r.save(batch, function(err, ok){
|
|
r.save(batch, function(err, ok){
|
|
if(++i > 1){ return }
|
|
if(++i > 1){ return }
|
|
- if(err){ Gun.log('err', err) }
|
|
|
|
|
|
+ if(err){ opt.log('err', err) }
|
|
map(batch.acks, function(cb){ cb(err, ok) });
|
|
map(batch.acks, function(cb){ cb(err, ok) });
|
|
thrash.at = null;
|
|
thrash.at = null;
|
|
thrash.ing = false;
|
|
thrash.ing = false;
|
|
@@ -141,6 +143,7 @@
|
|
f.file = file;
|
|
f.file = file;
|
|
f.each = function(val, key, k, pre){
|
|
f.each = function(val, key, k, pre){
|
|
if(u !== val){ f.count++ }
|
|
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';
|
|
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){
|
|
if((opt.chunk < f.text.length + enc.length) && (1 < f.count) && !force){
|
|
f.text = '';
|
|
f.text = '';
|
|
@@ -206,7 +209,7 @@
|
|
g.file = file;
|
|
g.file = file;
|
|
}
|
|
}
|
|
g.it = function(err, disk){
|
|
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 }
|
|
if(disk){ RAD = g.disk = disk }
|
|
disk = Q[g.file]; delete Q[g.file];
|
|
disk = Q[g.file]; delete Q[g.file];
|
|
map(disk, g.ack);
|
|
map(disk, g.ack);
|
|
@@ -243,6 +246,16 @@
|
|
//return cb(err, u);//map(q, p.ack);
|
|
//return cb(err, u);//map(q, p.ack);
|
|
return 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;
|
|
var tmp = p.split(data), pre = [], i, k, v;
|
|
while(tmp){
|
|
while(tmp){
|
|
k = v = u;
|
|
k = v = u;
|
|
@@ -309,7 +322,7 @@
|
|
}
|
|
}
|
|
r.list.init = function(err, disk){
|
|
r.list.init = function(err, disk){
|
|
if(err){
|
|
if(err){
|
|
- Gun.log('list', err);
|
|
|
|
|
|
+ opt.log('list', err);
|
|
setTimeout(function(){ r.parse(f, r.list.init) }, 1000);
|
|
setTimeout(function(){ r.parse(f, r.list.init) }, 1000);
|
|
return;
|
|
return;
|
|
}
|
|
}
|