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 moves or renames a file or directory; DOMRequest returns boolean true or false to indicate success
DOMRequest moveTo(DOMString or File or Directory entry, DOMString newName, optional Directory newParentDirectory);
// 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 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 or File file);
// The DOMMultiRequest returns File or Directory objects
DOMMultiRequest readEntries();
// The DOMMultiRequest returns File or Directory objects
DOMMultiRequest readEntriesRecursively();
}
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 position;
// 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
}
partial interface URL {
/// Gets a persistent URL for a File, if it's part of a local filesystem; otherwise returns null
DOMString? getPersistentURL(File file);
}
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
13 years ago
Last modified on Sep 24, 2012, 1:10:06 AM
Note:
See TracWiki
for help on using the wiki.