fix book mismatch between parse & parseless

This commit is contained in:
Mark Nadal 2023-02-17 18:26:25 -08:00
parent 6f6d8b533d
commit 81a29cdd60
2 changed files with 10 additions and 6 deletions

View File

@ -40,9 +40,11 @@ function get(word){
// get does an exact match, so we would have found it already, unless parseless page:
var page = b.page(word), l, has, a, i;
if(!page || !page.from){ return } // no parseless data
if(l = from(page)){ has = l[i = spot(B.encode(word), l)] }
if(l = from(page)){ subt.f=1; has = l[i = spot(B.encode(word), l)]; subt.f=0; } // because parseless data is encoded we need to make sure the word is encoded also, but because parseless data incrementally parses we need to set a flag on subt shim to indicate which parseless or not state we're in.
// parseless may return -1 from actual value, so we may need to test both.
if(has && word == has.word){ return (b.all[word] = has).is }
if('string' != typeof has){ has = l[i+=1] }
if(has && word == has.word){ return (b.all[word] = has).is }
if('string' != typeof has){ return }
a = slot(has) // Escape!
if(word != a[0]){
has = l[i+=1]; // edge case bug?
@ -110,7 +112,7 @@ function split(p, b){
function slot(t){ return (t=t||'').substring(1, t.length-1).split(t[0]) } B.slot = slot;
function size(t){ return (t||'').length||1 } // bits/numbers less size? Bug or feature?
function subt(i,j){ return this.word }
function subt(i,j){ return subt.f? B.encode(this.word) : this.word }
//function tot(){ return this.text = this.text || "'"+(this.word)+"'"+(this.is)+"'" }
function tot(){ var tmp;
//if((tmp = this.page) && tmp.saving){ delete tmp.book.all[this.word]; } // TODO: BUG! Book can't know about RAD, this was from RAD, so this MIGHT be correct but we need to refactor. Make sure to add tests that will re-trigger this.

View File

@ -35,6 +35,9 @@
if(!disk){
// do something to show whatever we have in-memory is going to be the disk.
}
if(p === disk){
} else
if(disk){
disk = Book(p.from = disk);
disk.PAGE = Infinity; // THIS BOOK IS ONLY TEMPORARY!
@ -50,7 +53,7 @@
p = b.list[p.i] = disk;*/
p.from = disk.from;
p.list = disk.list;
p.size = disk.size;
p.size = disk.size; //(disk.size < p.size? p.size : disk.size);
p.text = disk.text;
} else {
//p.from = disk || p.from; // TODO: NEED TO MERGE! AND HANDLE ERR!
@ -128,7 +131,7 @@
return t;
}
b.split = function (next, page) {
log("SPLIT!!!!", b.list.length);
//log("SPLIT!!!!", b.list.length);
put(' ', '' + b.list, function (err, ok) {
if (err) { console.log("ERR!"); return }
// ??
@ -224,7 +227,6 @@
RAD.put = function(file, data, cb){ cb(401) }
RAD.get = async function(file, cb){
var t = (await (await fetch('http://localhost:8765/gun/'+file)).text());
console.log("???file?", file, t);
if('404' == t){ cb(); return }
cb(null, t);
}