leaf icon indicating copy to clipboard operation
leaf copied to clipboard

Support more Deno filesystem functionality?

Open xyzshantaram opened this issue 4 years ago • 2 comments

It would be really useful if Leaf supported functions like stat, readDir, walkDir, etc so that library functions expecting a whole filesystem (for example, Opine's send, which uses stat and is used internally by the serveStatic function to serve static files) will work.

I understand if this is out of the scope of Leaf, but since we are meant to use Leaf with the fs text file r/w functions it would be nice to have this too, esp since Leaf is a fake filesystem.

A really cool use-case for Leaf, IMO, is single-file web servers in the vein of redbean but which allow us to use TypeScript and Deno, and this feature would enable that.

xyzshantaram avatar Dec 30 '21 18:12 xyzshantaram

I'm still learning Leaf but write is not an option as leaf is a readonly key/value store.

globalThis["MANDARINE_FILE_SYSTEM"] = {"web/index.html":[byte,...],...}

Regarding readDir/walkDir you can find the tree yourself so maybe write a PR?

function dumpLeaf() {
    console.debug("dumpLeaf", globalThis);
    Object.keys(globalThis["MANDARINE_FILE_SYSTEM"]).forEach(v => console.log(v));
}

gives

web/favicon.ico
web/index.html
...

clemens-tolboom avatar Jan 02 '22 09:01 clemens-tolboom

Ah, ofc, writing won't work, I meant more of the reading functions, yes. I'll try and write a PR later today but I can't promise anything (I'm kinda busy since my college semester starts tomorrow).

Thanks!

xyzshantaram avatar Jan 02 '22 18:01 xyzshantaram