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 216 forks source link

Update backends to be simpler #338

Closed james-pre closed 1 year ago

james-pre commented 1 year ago

I'm thinking about working on rewriting backends to be much simpler, and changing the internal FS to be more centralized.

For example:

interface Backend {
  //Allocates an INode with an only an ino property. Maybe instead return an ino?
  allocINode(callback): INode;
  readINode(ino: number, callback): INode;

  //Inode's have an ino property, so one is not needed as a parameter.
  writeINode(inode: INode, callback): void;

  // Same issue as allocINode 
  allocBlock(callback): DataBlock;
  readBlock(id: number, callback): DataBlock;
  writeBlock(block: DataBlock, callback): void;
}

DataBlock could be a class with an id and data property.

Having this would allow for significantly easier maintenance, in addition to streamlining the FS functions.

For dealing with synchronous and asynchronous code, backend functions must return data synchronously. They must also call a callback when any asynchronous code is done running. This allows asynchronous code to be called pseudo-synchronously (e.g. with the cache). While still allowing the asynchronous operations to be properly checked for.

Asynchronous backends (e.g. IndexedDB) must implement a cache internally though (which could easily be done with an AsyncBackend base class).

I think this could be a huge step forward (especially since it makes writing internal FS functions easier).

james-pre commented 1 year ago

After further consideration (e.g. with HTML5 FS) it may not work. A improved async system could really work though.

james-pre commented 1 year ago

On second thought (I know I just closed it), it could serve as a really nice replacement for the current system using transactions.

james-pre commented 1 year ago

This will be revisited in a separate issue.