Skip to content
John Vilk edited this page Feb 21, 2016 · 5 revisions

BrowserFS is an API that can be 'backed' by various 'backends'. Each backend can be thought of as a 'file system' type. Backends determine where file data is written to and read from.

The backend API gives a large degree of flexibility to backend implementers. For example, a backend could be read-only and pull data from a webserver using XHR, or could read and write files to a cloud storage provider. The user does not have to deal with this complexity, since the user will use the Node API with each backend.

Why add a backend to BrowserFS?

If you write a backend for BrowserFS, you get the following for free:

  • Test Suite Support: BrowserFS contains a comprehensive test suite for each command type that can be run on any backend. The tests are configured to test only the commands that the backend under test supports (e.g. if your file system does not support permissions, the permission tests will detect this and automatically pass).
  • Node API Compatibility: BrowserFS handles translating the Node fs API, which has some optional arguments and default values for arguments, into a more concrete form where everything is explicitly specified. It also translates some Node functions as compositions of "core" Node fs functions, which reduces the number of methods you need to implement and test.
  • Cross filesystem support: BrowserFS' MountableFileSystem will automatically handle operations that may span multiple filesystems. For example, if a user renames a file from /mnt/dropbox/Foo.bar to /mnt/localStorage/Foo.bar, BrowserFS will read the file from the Dropbox filesystem, write to the localStorage filesystem, and then delete it from the Dropbox filesystem. File systems do not need to know about each other.
  • WebWorker Support: BrowserFS will automatically proxy file operations across the WebWorker boundary with no individual filesystem support required.

Writing a Backend

There are two steps to writing a backend:

  1. Write a subclass of BrowserFS.FileSystem.
  2. Write a subclass of BrowserFS.File, or BrowserFS.PreloadFile.

When we say 'subclass', we mean as a TypeScript subclass. See an existing backend in src/backend for an example.

Clone this wiki locally