Dart Documentationchrome.fileSystemChromeFileSystem

ChromeFileSystem class

class ChromeFileSystem extends ChromeApi {
 static final JsObject _fileSystem = chrome['fileSystem'];

 ChromeFileSystem._();

 bool get available => _fileSystem != null;

 /**
  * Get the display path of an Entry object. The display path is based on the
  * full path of the file or directory on the local file system, but may be
  * made more readable for display purposes.
  */
 Future<String> getDisplayPath(Entry entry) {
   if (_fileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<String>.oneArg();
   _fileSystem.callMethod('getDisplayPath', [jsify(entry), completer.callback]);
   return completer.future;
 }

 /**
  * Get a writable Entry from another Entry. This call will fail with a runtime
  * error if the application does not have the 'write' permission under
  * 'fileSystem'. If entry is a DirectoryEntry, this call will fail if the
  * application does not have the 'directory' permission under 'fileSystem'.
  */
 Future<Entry> getWritableEntry(Entry entry) {
   if (_fileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<Entry>.oneArg(_createEntry);
   _fileSystem.callMethod('getWritableEntry', [jsify(entry), completer.callback]);
   return completer.future;
 }

 /**
  * Gets whether this Entry is writable or not.
  */
 Future<bool> isWritableEntry(Entry entry) {
   if (_fileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<bool>.oneArg();
   _fileSystem.callMethod('isWritableEntry', [jsify(entry), completer.callback]);
   return completer.future;
 }

 /**
  * Ask the user to choose a file or directory.
  * 
  * Returns:
  * [entry] null
  * [fileEntries] null
  */
 Future<ChooseEntryResult> chooseEntry([ChooseEntryOptions options]) {
   if (_fileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<ChooseEntryResult>.twoArgs(ChooseEntryResult._create);
   _fileSystem.callMethod('chooseEntry', [jsify(options), completer.callback]);
   return completer.future;
 }

 /**
  * Returns the file entry with the given id if it can be restored. This call
  * will fail with a runtime error otherwise. This method is new in Chrome 31.
  */
 Future<Entry> restoreEntry(String id) {
   if (_fileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<Entry>.oneArg(_createEntry);
   _fileSystem.callMethod('restoreEntry', [id, completer.callback]);
   return completer.future;
 }

 /**
  * Returns whether the app has permission to restore the entry with the given
  * id. This method is new in Chrome 31.
  */
 Future<bool> isRestorable(String id) {
   if (_fileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<bool>.oneArg();
   _fileSystem.callMethod('isRestorable', [id, completer.callback]);
   return completer.future;
 }

 /**
  * Returns an id that can be passed to restoreEntry to regain access to a
  * given file entry. Only the 500 most recently used entries are retained,
  * where calls to retainEntry and restoreEntry count as use. If the app has
  * the 'retainEntries' permission under 'fileSystem', entries are retained
  * indefinitely. Otherwise, entries are retained only while the app is running
  * and across restarts. This method is new in Chrome 31.
  */
 String retainEntry(Entry entry) {
   if (_fileSystem == null) _throwNotAvailable();

   return _fileSystem.callMethod('retainEntry', [jsify(entry)]);
 }

 void _throwNotAvailable() {
   throw new UnsupportedError("'chrome.fileSystem' is not available");
 }
}

Extends

ChromeApi > ChromeFileSystem

Properties

final bool available #

Returns true if the API is available. The common causes of an API not being avilable are:

  • a permission is missing in the application's manifest.json file
  • the API is defined on a newer version of Chrome then the current runtime
docs inherited from ChromeApi
bool get available => _fileSystem != null;

Methods

Future<ChooseEntryResult> chooseEntry([ChooseEntryOptions options]) #

Ask the user to choose a file or directory.

Returns: entry null fileEntries null

Future<ChooseEntryResult> chooseEntry([ChooseEntryOptions options]) {
 if (_fileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<ChooseEntryResult>.twoArgs(ChooseEntryResult._create);
 _fileSystem.callMethod('chooseEntry', [jsify(options), completer.callback]);
 return completer.future;
}

Future<String> getDisplayPath(Entry entry) #

Get the display path of an Entry object. The display path is based on the full path of the file or directory on the local file system, but may be made more readable for display purposes.

Future<String> getDisplayPath(Entry entry) {
 if (_fileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<String>.oneArg();
 _fileSystem.callMethod('getDisplayPath', [jsify(entry), completer.callback]);
 return completer.future;
}

Future<Entry> getWritableEntry(Entry entry) #

Get a writable Entry from another Entry. This call will fail with a runtime error if the application does not have the 'write' permission under 'fileSystem'. If entry is a DirectoryEntry, this call will fail if the application does not have the 'directory' permission under 'fileSystem'.

Future<Entry> getWritableEntry(Entry entry) {
 if (_fileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<Entry>.oneArg(_createEntry);
 _fileSystem.callMethod('getWritableEntry', [jsify(entry), completer.callback]);
 return completer.future;
}

Future<bool> isRestorable(String id) #

Returns whether the app has permission to restore the entry with the given id. This method is new in Chrome 31.

Future<bool> isRestorable(String id) {
 if (_fileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<bool>.oneArg();
 _fileSystem.callMethod('isRestorable', [id, completer.callback]);
 return completer.future;
}

Future<bool> isWritableEntry(Entry entry) #

Gets whether this Entry is writable or not.

Future<bool> isWritableEntry(Entry entry) {
 if (_fileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<bool>.oneArg();
 _fileSystem.callMethod('isWritableEntry', [jsify(entry), completer.callback]);
 return completer.future;
}

Future<Entry> restoreEntry(String id) #

Returns the file entry with the given id if it can be restored. This call will fail with a runtime error otherwise. This method is new in Chrome 31.

Future<Entry> restoreEntry(String id) {
 if (_fileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<Entry>.oneArg(_createEntry);
 _fileSystem.callMethod('restoreEntry', [id, completer.callback]);
 return completer.future;
}

String retainEntry(Entry entry) #

Returns an id that can be passed to restoreEntry to regain access to a given file entry. Only the 500 most recently used entries are retained, where calls to retainEntry and restoreEntry count as use. If the app has the 'retainEntries' permission under 'fileSystem', entries are retained indefinitely. Otherwise, entries are retained only while the app is running and across restarts. This method is new in Chrome 31.

String retainEntry(Entry entry) {
 if (_fileSystem == null) _throwNotAvailable();

 return _fileSystem.callMethod('retainEntry', [jsify(entry)]);
}