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.07k stars 220 forks source link

Store directories in localStorage #31

Closed perimosocordiae closed 10 years ago

perimosocordiae commented 11 years ago

We're already storing a header of stat information for files, so it's natural to store a few bytes for directories as well. This allows us to persist empty directories, and it also paves the way for eventual symlink support.

jvilk commented 11 years ago

This is low priority, but here's my plan...

Since we scan basic file metadata during initialization, we can store the directory tree in a compressed format under a single fixed key.

We can condense each directory and its metadata into a single binary string. And then we can store them in a JSON object that is encoded as a binary string, so we don't have to repeat parent directories.

As a reminder, a binary string is a string that packs 2 bytes of data into each character, and has a 1 character header that specifies whether or not the length of the string is even or odd; if it's odd, it also contains the first byte of data (see BrowserFS.StringUtil.BINSTR). If we do not pack data into binary strings, localStorage shrinks from 5MB of storage to 2.5MB of storage -- including the size of keys -- since JavaScript strings are UTF-16.

jvilk commented 10 years ago

All key-value file systems now properly store directory metadata.