js-cfb issue #2

node v8.17.0
endpointsharetweet
This test creates 4000 entries. Half the entries are 500 byte and will be stored in the mini FAT. The other half are 5000 bytes and will be stored in the main fat. The unsafe:true option to cfb_add skips all safety checks, so it should only be used in write-only workflows. If you want to read after doing an unsafe write, do a GC pass with cfb_gc first.
var CFB = require('cfb'); var cfb = CFB.utils.cfb_new(); var cnt = 2000 console.log("alloc", new Date()); var bufs = []; for(var i = 0; i < cnt; ++i) bufs[i] = [Buffer.alloc(500, i), Buffer.alloc(5000, i)]; console.log("start", new Date()); for(var i = 0; i < cnt; ++i) { if(!(i%1000)) console.log(i, new Date()); CFB.utils.cfb_add(cfb, "/short/" + i.toString(16), bufs[i][0], {unsafe:true}); CFB.utils.cfb_add(cfb, "/long/" + i.toString(16), bufs[i][1], {unsafe:true}); } console.log("prewrite", new Date()); CFB.utils.cfb_gc(cfb); var buf = CFB.write(cfb, {type:"buffer"}); console.log("done", new Date()); var cfb2 = CFB.read(buf, {type:"buffer"}); console.log("read", new Date()); for(var i = 0; i < cnt; i += 100) { var file = CFB.find(cfb2, "/short/" + i.toString(16)); if(0 != Buffer.compare(file.content, bufs[i][0])) throw new Error("short " + i); file = CFB.find(cfb2, "/long/" + i.toString(16)); if(0 != Buffer.compare(file.content, bufs[i][1])) throw new Error("short " + i); }
Loading…

no comments

    sign in to comment