Overview | File | Class | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## Class opera.io.filesystem

    Object
       |
       +--opera.io.filesystem

class opera.io.filesystem

Virtual file system implementation

The `FileSystem` class represents a virtual file system. Actual files are connected to it by defining mount points from the actual file system. This way file system access can be limited to a selected set of files rather than allow unsecure operations on the local file system directly.

Path references in the virtual file systems always use '/' as the path separator.

Defined in file-io.js

Field Summary
`File` | `mountPoints` The mount points currently attached to this `FileSystem`.

Constructor Summary
`opera.io.filesystem()` This class has no public constructor.

Method Summary
`void` | `browseForDirectory( <String> name, <String> defaultlocation, <Function> callback, <boolean> persistent )` Open a dialog allowing the user to browse for a directory to mount.
`void` | `browseForFile( <String> name, <String> defaultlocation, <Function> callback, <boolean> persistent, <boolean> multiple, <Array> filter )` Open a dialog allowing the user to browse for a file to mount.
`void` | `browseForSave( <String> name, <String> defaultlocation, <Function> callback, <boolean> persistent )` Open a dialog allowing the user to create a new file, which is then mounted.
`File` | `mountSystemDirectory( <String> location, <String> name )` Mount application or storage system directory.
`void` | `removeMountPoint( <File> mountpoint )` Remove the given mount point.

Field Detail

### mountPoints

    File mountPoints

The mount points currently attached to this `FileSystem`. Readonly. This is a special `File` object that represents the root of the virtual file system and serves to enumerate the existing mount points. Its path is `/` and its name is empty. If you mount a directory as `foo`, the path of the mount point is `/foo`.

Constructor Detail

### opera.io.filesystem

    opera.io.filesystem()

This class has no public constructor.

Method Detail

### browseForDirectory

    void browseForDirectory( <String> name, <String> defaultlocation, <Function> callback, <boolean> persistent )

Open a dialog allowing the user to browse for a directory to mount.

Note that this method is not supported for Opera Unite applications.

Calling this function will open a file chooser dialog showing only directories. When the user selects one, the directory is mounted and the given `callback` is called with a `File` object representing the directory. If the user cancels the dialog, or if mounting fails, the callback is called with a null argument.

Mount points are by default destroyed whenever the application is closed. If you give the `persistent` argument as `true`, the mount point will be remounted the next time the application is started.

The `defaultlocation` argument is used to specify the initial directory of the dialog.

This function will only be called as a result of direct user interaction, such as a click event or similar. If called from a timeout or a programatically dispatched event, it will be ignored by the runtime.

Mount points are mounted as read-write, so you should take care to protect your data by limiting users' access to it.

Parameters:

`name` - The name of the mount point to create.

`defaultlocation` - Location in the file system the dialog should open with. Leave blank for system default.

`callback` - Function to call when the user has selected a directory.

`persistent` - Whether or not this mount point should be remounted if the application restarted. Optional. Defaults to false.

Throws:

- GENERIC_ERR if the type of the name argument is wrong, if it contains invalid characters for a mount point name, or if the given mount point is already in use.

### browseForFile

    void browseForFile( <String> name, <String> defaultlocation, <Function> callback, <boolean> persistent, <boolean> multiple, <Array> filter )

Open a dialog allowing the user to browse for a file to mount.

Note that this method is not supported for Opera Unite applications.

Calling this function will open a file chooser dialog. When the user selects a file, the file is mounted and the given `callback` is called with a corresponding `File` object. If the user cancels the dialog, or if mounting fails, the callback is called with a null argument.

Mount points are by default destroyed whenever the application is closed. If you give the `persistent` argument as `true`, the mount point will be remounted the next time the application is started.

The appearance of the dialog can be manipulated with the various arguments to the method. The `defaultlocation` argument is used to specify the initial directory of the dialog. The `multiple` argument is used to control whether or not the user can select multiple files. The `filter` can be given an array of file types such as 'txt', which limits the types of the files the user can select.

If the method is called with `multiple` set to `true`, a virtual directory will be created and mounted with the given name, containing the selected files. The callback will be called with the File representing the virtual directory. It is not possible to add further files to this mount point, although you can delete files already in it.

This function will only be called as a result of direct user interaction, such as a click event or similar. If called from a timeout or a programatically dispatched event, it will be ignored by the runtime.

Mount points are mounted as read-write, so you should take care to protect your data by limiting users' access to it.

Parameters:

`name` - The name of the mount point to create.

`defaultlocation` - Location in the file system the dialog should open with. Leave blank for system default.

`callback` - Function to call when the user selects a file in the dialog.

`persistent` - Whether or not this mount point should be remounted if the application restarted. Optional. Defaults to false.

`multiple` - Whether or not multiple files can be chosen in the dialog. Optional. Defaults to false.

`filter` - Array of file type extensions to filter the list of selectable file types in the dialog. Defaults to '*'. Not implemented.

Throws:

- GENERIC_ERR if the type of the name argument is wrong, if it contains invalid characters for a mount point name, or if the given mount point is already in use.

### browseForSave

    void browseForSave( <String> name, <String> defaultlocation, <Function> callback, <boolean> persistent )

Open a dialog allowing the user to create a new file, which is then mounted.

Note that this method is not supported for Opera Unite applications.

Currently, the selected File is just returned, but not mounted. Consequently, using `persistent` has no meaning.

Calling this function will open a file chooser dialog whose start location is the location of the given mount point. In this dialog the user may create a new file. A `File` object is created and mounted and the given callback is called with the object. If the user cancels the dialog, or if mounting fails, the callback is called with a null argument.

If the file already exists, a File representing it is sent in the callback. If it doesn't exist, a `File` object is returned with the `exists` property set to false. It will be physically created only after it is opened.

Mount points are by default destroyed whenever the application is closed. If you give the `persistent` argument as `true`, the mount point will be remounted the next time the application is started.

This function will only be called as a result of direct user interaction, such as a click event or similar. If called from a timeout or a programatically dispatched event, it will be ignored by the runtime.

Mount points are mounted as read-write, so you should take care to protect your data by limiting users' access to it.

Parameters:

`name` - The name of the mount point to create.

`defaultlocation` - Location in the file system the dialog should open with. Leave blank for system default.

`callback` - Function to call when the user selects a file in the dialog.

`persistent` - Whether or not this mount point should be remounted if the application restarted. Optional.

Throws:

- GENERIC_ERR if the type of the name argument is wrong, if it contains invalid characters for a mount point name, or if the given mount point is already in use.

### mountSystemDirectory

    File mountSystemDirectory( <String> location, <String> name )

Mount application or storage system directory.

Applications that use the File I/O API have access to three special directories:

application
  The application directory contains the actual files and directories of the current application accessing the API. For widgets, for example, the config.xml and index.html and other files of the widget are found here. This directory is mounted as readonly.
storage
  The storage directory is for storing temporary files and configuration files specific to the application, for example uploaded files. This directory and its contents are persisted until the application is uninstalled.
shared
  The shared directory is for sharing data from the regular file system. The directory is typically selected by the user when installing the application.

These directories of the application are not mounted by default. You need to call this method to mount and use them. Once mounted, they are available through the `mountPoints` property like other mount points. Files and directories under them can be accessed by resolving and using the mountpoint URL protocol as for normal files.

The application directory is always mounted as readonly.

If you do not supply the `name` argument, the `location` argument is used as the name of the mount point. They are then available as the mount points `storage`, `application` and `shared`, with paths `/storage`, `/application` and `/shared` respectively.

Note that the `shared` directory is mounted as read-write unless the underlying file system defines it to be read-only. You should take care to protect your data by limiting access and checking for exploitable code.

Parameters:

`location` - Name of the system directory to mount, either `storage`, `application` or `shared`.

`name` - Name to mount the directory as. If not present, the location is used. Optional.

Returns:

`File` object representing the mounted system directory, or null if the location is invalid or if the system directory is not defined.

### removeMountPoint

    void removeMountPoint( <File> mountpoint )

Remove the given mount point. Removes a mount point from the virtual file system, either by referencing its symbolic name or by passing a `File` object representing the mount point. If the mount point is mounted as persistent, removing it will also remove the persistance.

Parameters:

`mountpoint` - `File` object representing the mount point or a String with the name of the mount point.

Throws:

- GENERIC_ERR If the given File or String doesn't represent a mount point.

Overview | File | Class | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Documentation generated by JSDoc on Fri Jan 29 17:08:19 2010