seanmorris / php-wasm

PHP in Browser, powered by WebAssembly.
https://seanmorris.github.io/php-wasm/
Apache License 2.0
606 stars 32 forks source link

Ability to handle files on a fly #20

Closed kenorb closed 1 week ago

kenorb commented 1 year ago

Instead of creating files upfront, I'd like to see the ability to create them on a fly (for the performance reasons).

For example when FS.open() is called and the file doesn't exist, give the parent module ability to create it.

Proposed solution (right before returning ErrnoError(44):

+        if (!node && Module && Module["onFileOpen"]) {
+          node = Module["onFileOpen"](path, this);
+        }
         if (!node) {
           throw new FS.ErrnoError(44);
         }

Then the caller module can define something like:

    onFileOpen: function (path, fs) {
      var node = this["FS_createDataFile"](fs.cwd(), path, "foo", true, true, true);
      return node;
    },

For example, Drupal got over 20k files, why not create only these files which are requested during the run.

seanmorris commented 1 week ago

v0.0.9 (currently in alpha) Allows you to load single files, or unpack entire zips into the filesystem.