jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.06k stars 215 forks source link

add a key prefix for localstorage to allow multiple instances of fs #266

Closed pyramation closed 5 years ago

pyramation commented 5 years ago

Wondering if it's possible to add a prefix to the keys when using any localstorage (or locally persistent) storage.

To give some context, I'm looking to have the ability to have multiple fs instances for use cases of checking out other files systems, each having their own sandboxed root '/' folder.

Currently, I can get it to work using InMemory:

export const getFs = () => {
  return new Promise((resolve, reject) => {
    InMemory.Create((e, _fs) => {
      if (e) return reject(e);
      const fs = new FS();
      fs.initialize(_fs);
      resolve(fs);
    });
  });
};

However, if I use LocalStorage, it ends up "using the same filesystem".

Here's a psuedo-code test to give a gist of what I'm trying to accomplish:

const fs1 = await getFs();
const fs2 = await getFs();
writeSomeStuffHere(fs1, '/lib');
expect(lsTree(fs1, '/')).not.toEqual(lsTree(fs2, '/'));

I was thinking it could already be a potential option, and if not, I was curious if it is an option that could be added, e.g., LocalStorage.create({ prefix: 'mystorage' }, (e, lsfs) => { ... })

jvilk commented 5 years ago

It seems possible, but why would you want to do that? Instead, you can use FolderAdapter to split up a single local storage into multiple file systems scoped to certain folders.

jvilk commented 5 years ago

Closing since I believe FolderAdapter solves this use case. Feel free to reopen if you disagree!