old: callbackfn(callback_when_ok,callback_when_ng);=>newPromise((ok,ng)=>{if("something is failed")ng(newError("something is failed"));elsecallbackfn(ok,ng?);})
test code
//------------------------------------------------------------------------------// test body://------------------------------------------------------------------------------constfs=newWebFileSystem();fs.open();setHandler(`<button id='fs-clear'>fs clear(erase all)</button>`,async(evt)=>{fs.clear();});setHandler(`<button id='read-write' >read/write</button>`,async(evt)=>{lettext_path="/folder1/folder2 withspace/read_ write.txt";// white space in file or folder.// writetry{constfolder=awaitfs.createDirectory(text_path.substring(0,text_path.lastIndexOf("/")));constfileWriter=awaitfs.openFile(text_path,"a+",folder);for(leti=0;i<10;++i){constblob=newBlob([newDate().toLocaleString()+"-"+Date.now()+"\n"],{type: "text/plain"});awaitfileWriter.writeAsync(blob);}console.log("write done");}catch(err){console.error(err);}// readtry{constfolder=undefined;//await fs.getDirectory(text_path.substring(0, text_path.lastIndexOf("/")));constfileBlob=awaitfs.openFile(text_path,"r",folder);constreader=newFileReader();reader.onloadend=(evt)=>console.log(evt.target.result);reader.readAsText(fileBlob);}catch(err){console.error(err);}// downloadtry{fs.download(text_path);//fs.deleteEntry(text_path);}catch(err){console.error(err);}});setHandler(`<hr/><input id='test-path' />`);setHandler(`<button id='get-entries' >get entries</button>`,async()=>{letpath=document.querySelector("#test-path").value;constentries=awaitfs.getFileEntriesRecursively(path ? path : "/");console.log(entries);});setHandler(`<button id='download' >download</button>`,async(evt)=>{letpath=document.querySelector("#test-path").value;if(!path)path="/childProcess.execSync.png";awaitfs.download(path);awaitfs.deleteEntry(path);});// add local file to FS.setHandler("<hr/>");setHandler(`<input type="file" id="myfile" multiple />`,async(e)=>{awaitfs.createDirectory("/upload");for(constfofe.target.files){fs.save(f,"/upload");}},"change");