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 rename(DOMString oldName, DOMString newName); // The request will return a FileHandle; error if called on a Directory // If File is passed, it must be a descendant of this directory DOMRequest openForWriting(DOMString name or File file); // The request will return a FileHandle; error if called on a Directory // If File is passed, it must be a descendant of this directory DOMRequest openForAppending(DOMString name or 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; // Result for all of these is the FileHandle DOMRequest readAsArrayBuffer(long size); DOMRequest readAsText(long size, optional DOMString encoding); DOMRequest write(DOMString or ArrayBuffer or ArrayBufferView or Blob value); DOMRequest truncate(optional long long size); DOMRequest flush(); // fsync void close(); // Currently outstanding operations run to completion, but no more may be issued }
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 DOMMultiRequest : DOMRequest { void stop(); // Call if all results have been delivered attribute EventHandler onfinish; };
Last modified
12 years ago
Last modified on Sep 22, 2012, 6:03:25 PM
Note:
See TracWiki
for help on using the wiki.