wiki:MinimalFileStorage

Version 1 (modified by mjs@apple.com, 10 years ago) (diff)

--

This is a proposal for a minimal filesystem API, designed for only the use case of sandboxed local storage.

Getting the root directory:

partial interface Navigator {
  Directory getSandboxedFilesystem();
};

The Directory interface:

interface Directory {
    readonly DOMString name;

    // The request will return the newly created FileHandle
    DOMRequest create(DOMString name, Blob blob);

    // The request will return the newly created Directory
    DOMRequest makeDirectory(DOMString name);

    // The request will return a File or Directory
    DOMRequest get(DOMString name);

    // Deletes a file or directory; DOMRequest returns boolean true or false to indicate success
    DOMRequest remove(DOMString name);

   // Atomically renames a file or directory; DOMRequest returns boolean true or false to indicate success
    DOMRequest remove(DOMString oldName, DOMString newName);

    // The request will return a FileHandle; error if called on a Directory
    DOMRequest openForWriting(DOMString name);

    // The request will return a FileHandle; File must be a descendant of this directory
    DOMRequest openForWriting(File file);

    // The DOMMultiRequest returns File or Directory objects
    DOMMultiRequest enumerateShallow();

    // The DOMMultiRequest returns File or Directory objects
    DOMMultiRequest enumerateDeep();

}

The FileHandle interface, representing a file open in read-write mode (for the read-only case, FileReader already exists, so why reinvent the wheel?)

    interface FileHandle {
        readonly attribute File file;

        attribute long long offset;

        FileRequest readAsArrayBuffer(long size);
        FileRequest readAsText(long size, optional DOMString encoding);
        FileRequest write(DOMString or ArrayBuffer or ArrayBufferView or Blob value);
        FileRequest append(DOMString or ArrayBuffer or ArrayBufferView or Blob value);
        FileRequest truncate(optional long long size);
    }

Result interfaces

interface DOMRequest {
  readonly attribute DOMString readyState; // "pending" or "done"

  readonly attribute any result;
  readonly attribute DOMError error;

  attribute EventHandler onsuccess;
  attribute EventHandler onerror;
};

interface FileRequest : DOMRequest {
  readonly attribute FileHandle fileHandle;

  attribute EventHandler onprogress;
};

interface DOMMultiRequest : DOMRequest {
  void stop();

  attribute EventHandler onfinish;
};