diff --git a/lib/book.js b/lib/book.js index d10c945c..07abcdbc 100644 --- a/lib/book.js +++ b/lib/book.js @@ -22,11 +22,11 @@ var sT = setTimeout, B = sT.Book || (sT.Book = function(text){ b.get = get; b.all = {}; return b; -}), PAGE = 2**16;//2**12; +}), PAGE = 2**12; function page(word){ var b = this, l = b.list, i = spot(B.encode(word), l), p = l[i]; - if('string' == typeof p){ l[i] = p = {size: -1, first: p, substring: sub, toString: to, book: b} } + if('string' == typeof p){ l[i] = p = {size: -1, first: p, substring: sub, toString: to, book: b} } // TODO: test, how do we arrive at this condition again? return p; // TODO: BUG! What if we get the page, it turns out to be too big & split, we must then RE get the page! } @@ -118,7 +118,7 @@ function sub(i,j){ return (this.first||this.word||(from(this)||'')[0]||'').subst function to(){ return this.text = this.text || text(this) } function join(){ return this.join('|') } function text(p){ - if(!p.list){ return p.from || '' } + if(!p.list){ return (p.from||'')+'' } if(!p.from){ return '|'+((p.list && (p.list = p.list.sort()).join('|'))||'')+'|' } return '|'+from(p).concat(p.list).sort().join('|')+'|'; } diff --git a/lib/radisk3.js b/lib/radisk3.js index 8c5cb1ce..d4337746 100644 --- a/lib/radisk3.js +++ b/lib/radisk3.js @@ -1,4 +1,4 @@ -; (function () { // RAD +;(function () { // RAD console.log("Warning: Experimental rewrite of RAD to use Book. It is not API compatible with RAD yet and is very alpha."); var sT = setTimeout, Book = sT.Book, RAD = sT.RAD || (sT.RAD = function (opt) { opt = opt || {}; @@ -164,3 +164,35 @@ }); } }()); + + +;(function () { // temporary fs storage plugin, needs to be refactored to use the actual RAD plugin interface. + var lS; + try { lS = localStorage } catch (e) { }; + if (!lS) { return } + + var sT = setTimeout, RAD = sT.RAD; + RAD.put = function (file, data, cb) { + lS[file] = data; + cb(null, 1); + } + RAD.get = function (file, cb) { + cb(null, lS[file]); + } +}()); + +;(function(){ + return; + var get; + try { get = fetch } catch (e) { }; + if (!get) { return } + + var sT = setTimeout, RAD = sT.RAD; + 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); + } +}()); \ No newline at end of file