From 81a29cdd601aedbd4833159456245353fc5a1bde Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 17 Feb 2023 18:26:25 -0800 Subject: [PATCH] fix book mismatch between parse & parseless --- lib/book.js | 8 +++++--- lib/radisk3.js | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/book.js b/lib/book.js index 8b67cc6f..482b1d95 100644 --- a/lib/book.js +++ b/lib/book.js @@ -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. diff --git a/lib/radisk3.js b/lib/radisk3.js index 111983f1..8f6e07e6 100644 --- a/lib/radisk3.js +++ b/lib/radisk3.js @@ -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); }