node-libs-browser icon indicating copy to clipboard operation
node-libs-browser copied to clipboard

Question: fs implementation?

Open amilajack opened this issue 8 years ago • 2 comments

What is holding back adding an fs polyfill? I've seen many implementations for browser fs polyfills for node:

  • https://github.com/jvilk/BrowserFS
  • https://github.com/matthewp/fs
  • https://github.com/mafintosh/browserify-fs

Seems possible. Any reasons why this hasnt been done yet? I can PR for this.

amilajack avatar Oct 20 '17 23:10 amilajack

I don't think there's a one-size-fits-all browser fs polyfill. a readFile call in the browser may have to do a request to a server like in BrowserFS, if the file is a template or image resource. If the file is a user configuration file, using a client-side store like browserify-fs makes more sense. that makes it difficult to pick a single polyfill.

goto-bus-stop avatar Oct 27 '17 10:10 goto-bus-stop

I have my own fs polyfill, just for reference, it's here:

https://github.com/sumanjs/suman-browser-polyfills/blob/master/modules/fs.js

I generated it by looping through all the fs methods and just allowing for both a synchronous return and a callback. It seems to work ok, was quick and dirty.

Here is how I generated it: https://github.com/sumanjs/suman-browser-polyfills/blob/master/lib/src/fs.js

ORESoftware avatar Oct 30 '17 21:10 ORESoftware