WebAPI/DeviceStorageAPI2: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(Blanked the page)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
This is a very simple filesystem API based on the [[WebAPI/DeviceStorageAPI|DeviceStorage API]]


== API ==
=== FileSystem ===
partial interface Navigator {
  DeviceStorage getSandboxedFilesystem(DOMString filesystemName);
};
interface DeviceStorage {
  // Name will be generated by the implementation and returned as result of request
  DOMRequest add(Blob blob, DOMString name);
  // Returns the result as a File object
  DOMRequest get(DOMString name);
  // Returns the result as a FileHandle object which enables writing
  DOMRequest getEditable(DOMString name);
  // Deletes a file
  DOMRequest delete(DOMString name);
 
  // The .result property on each success call is set to a File object
  DeviceStorageCursor enumerate(optional DOMString directory)
  // The .result property on each success call is set to a FileHandle object
  DeviceStorageCursor enumeratEditable(optional DOMString directory)
  // The .result property on each success call is either a
  // { file: File } or { directory: "name" } object
  DeviceStorageCursor enumerateShallow(optional DOMString directory)
  // The .result property on each success call is either a
  // { file: FileHandle } or { directory: "name" } object
  DeviceStorageCursor enumerateShallowEditable(optional DOMString directory)
};
interface DeviceStorageCursor : DOMRequest {
  void continue();
};
=== FileHandle ===
interface FileHandle {
  LockedFile open([optional] DOMString mode); // defaults to "readonly"
  FileRequest getFile(); // .result is set to resulting File object
};
interface LockedFile {
  readonly attribute FileHandle fileHandle;
  readonly attribute DOMString mode;
  readonly attribute boolean active;
  attribute long long? location; // Set to null on call to append
  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);
  FileRequest getMetadata(MetadataParams params);
  FileRequest flush(); // fsync
  void close(); // Prevents any further requests from being placed against this lock
  void abort(); // Immediately releases lock and stops any pending or running operations.
};
dictionary MetadataParameters {
  boolean size;
  boolean lastModified;
};
interface FileRequest : DOMRequest {
  readonly attribute LockedFile lockedFile;
  attribute EventHandler onprogress;
};
=== DOMRequest ===
Same as IDBRequest, but with the IndexedDB-specific parts removed.
interface DOMRequest {
  readonly attribute DOMString readyState; // "pending" or "done"
  readonly attribute any result;
  readonly attribute DOMError error;
  attribute EventHandler onsuccess;
  attribute EventHandler onerror;
};
=== Read-only FileSystem ===
'''If''' there's a desire to expose a read-only filesystem in other APIs, it'd look something like this. However this might not at all be needed. This is just the full DeviceStorage API with the all functions related to writing removed.
interface ReadOnlyDeviceStorage {
  // Returns the result as a File object
  DOMRequest get(DOMString name);
 
  // The .result property on each success call is set to a File object
  DeviceStorageCursor enumerate(optional DOMString directory)
  // The .result property on each success call is either a
  // { file: File } or { directory: "name" } object
  DeviceStorageCursor enumerateShallow(optional DOMString directory)
};

Latest revision as of 07:43, 30 September 2013