| | 1 | |
| | 2 | This is a proposal for a minimal filesystem API, designed for only the use case of sandboxed local storage. |
| | 3 | |
| | 4 | Getting the root directory: |
| | 5 | |
| | 6 | {{{ |
| | 7 | partial interface Navigator { |
| | 8 | Directory getSandboxedFilesystem(); |
| | 9 | }; |
| | 10 | }}} |
| | 11 | |
| | 12 | The Directory interface: |
| | 13 | |
| | 14 | {{{ |
| | 15 | interface Directory { |
| | 16 | readonly DOMString name; |
| | 17 | |
| | 18 | // The request will return the newly created FileHandle |
| | 19 | DOMRequest create(DOMString name, Blob blob); |
| | 20 | |
| | 21 | // The request will return the newly created Directory |
| | 22 | DOMRequest makeDirectory(DOMString name); |
| | 23 | |
| | 24 | // The request will return a File or Directory |
| | 25 | DOMRequest get(DOMString name); |
| | 26 | |
| | 27 | // Deletes a file or directory; DOMRequest returns boolean true or false to indicate success |
| | 28 | DOMRequest remove(DOMString name); |
| | 29 | |
| | 30 | // Atomically renames a file or directory; DOMRequest returns boolean true or false to indicate success |
| | 31 | DOMRequest rename(DOMString oldName, DOMString newName); |
| | 32 | |
| | 33 | // The request will return a FileHandle; error if called on a Directory |
| | 34 | // If File is passed, it must be a descendant of this directory |
| | 35 | DOMRequest openForWriting(DOMString name or File file); |
| | 36 | |
| | 37 | // The request will return a FileHandle; error if called on a Directory |
| | 38 | // If File is passed, it must be a descendant of this directory |
| | 39 | DOMRequest openForAppending(DOMString name or File file); |
| | 40 | |
| | 41 | // The DOMMultiRequest returns File or Directory objects |
| | 42 | DOMMultiRequest enumerateShallow(); |
| | 43 | |
| | 44 | // The DOMMultiRequest returns File or Directory objects |
| | 45 | DOMMultiRequest enumerateDeep(); |
| | 46 | |
| | 47 | } |
| | 48 | }}} |
| | 49 | |
| | 50 | The FileHandle interface, representing a file open in read-write mode (for the read-only case, FileReader already exists, so why reinvent the wheel?) |
| | 51 | |
| | 52 | {{{ |
| | 53 | interface FileHandle { |
| | 54 | readonly attribute File file; |
| | 55 | |
| | 56 | attribute long long offset; |
| | 57 | |
| | 58 | // Result for all of these is the FileHandle |
| | 59 | DOMRequest readAsArrayBuffer(long size); |
| | 60 | DOMRequest readAsText(long size, optional DOMString encoding); |
| | 61 | DOMRequest write(DOMString or ArrayBuffer or ArrayBufferView or Blob value); |
| | 62 | DOMRequest truncate(optional long long size); |
| | 63 | |
| | 64 | DOMRequest flush(); // fsync |
| | 65 | |
| | 66 | void close(); // Currently outstanding operations run to completion, but no more may be issued |
| | 67 | } |
| | 68 | }}} |
| | 69 | |
| | 70 | |
| | 71 | Result interfaces: |
| | 72 | |
| | 73 | {{{ |
| | 74 | interface DOMRequest { |
| | 75 | readonly attribute DOMString readyState; // "pending" or "done" |
| | 76 | |
| | 77 | readonly attribute any result; |
| | 78 | readonly attribute DOMError error; |
| | 79 | |
| | 80 | attribute EventHandler onsuccess; |
| | 81 | attribute EventHandler onerror; |
| | 82 | }; |
| | 83 | |
| | 84 | interface DOMMultiRequest : DOMRequest { |
| | 85 | void stop(); |
| | 86 | |
| | 87 | // Call if all results have been delivered |
| | 88 | attribute EventHandler onfinish; |
| | 89 | }; |
| | 90 | }}} |