The Filesystem API provides access to a device's filesystem.
The filesystem is represented as an abstract collection of disjointed filesystem virtual root locations, each corresponding to a specific location in the device filesystem. The filesystem API exposes the hierarchies below these root locations as autonomous virtual filesystems.
Each virtual root has a string name. Each file or directory within the virtual filesystem is addressed using a fully-qualified path of the form: <root name>/<path> where <rootname> is the name of the virtual root and <path> is the path to the file or directory relative to that root.
The following virtual roots must be supported:
The file URI path is also supported. To access paths out of virtual root, for example "file:///tmp" can be used as location parameter.
The implementation must support the use of the following characters in file names:
The implementation may support additional characters in file names, depending on platform support.
The implementation may forbid the use of additional characters in file names, depending on the platform. The use of the path (component) separator "/" and null character "x00" should not be allowed in file names.
Some other file name and path characteristics are platform-dependent, for example, maximum path length, file name length, case sensitivity, additional character support, etc. Therefore, it is recommended to avoid any dependency on aspects that cannot be supported across multiple platforms.
The encoding used for the file path should be UTF-16 (default for ECMAScript String).
Remark: In order to access files, a proper privilege has to be defined additionally:
Remark: Methods, which names end with NonBlocking are asynchronous and are executed in background in the order in which they were called. Corresponding methods without NonBlocking at the end are synchronous and will block further instructions execution, until they are finished.
For more information on the Filesystem features, see File System Guide.
Since: 1.0
String, which points to file or directory.
typedef DOMString Path;
Since: 5.0
In methods available since Tizen 5.0, checking or accessing files or directories may be granted only through a valid path.
Paths may contain one of the supported virtual roots. The valid path pattern is explained on the top of the page.
Specifies the file mode when it is opened.
enum FileMode { "a", "r", "rw", "rwo", "w" };
The file modes defined by this enumerator are:
Remark: rwo mode is supported since Tizen 5.0. It will not be recognized by deprecated functions.
Specifies the type of storage.
enum FileSystemStorageType { "INTERNAL", "EXTERNAL" };
Specifies the state of the storage.
enum FileSystemStorageState { "MOUNTED", "REMOVED", "UNMOUNTABLE" };
This is a Blob object defined in W3C File API. See: The Blob Interface.
typedef Blob Blob;
Specifies starting point for seek operation.
enum BaseSeekPosition { "BEGIN", "CURRENT", "END" };
The FileSystemManagerObject interface defines what is instantiated by the Tizen object.
[NoInterfaceObject] interface FileSystemManagerObject { readonly attribute FileSystemManager filesystem; };
Tizen implements FileSystemManagerObject;
There is a tizen.filesystem object that allows accessing the functionality of the Filesystem API.
The FileSystemManager interface provides access to the Filesystem API.
[NoInterfaceObject] interface FileSystemManager { readonly attribute long maxNameLength; readonly attribute long maxPathLength; FileHandle openFile(Path path, FileMode openMode, optional boolean makeParents) raises(WebAPIException); void createDirectory(Path path, optional boolean makeParents, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void deleteFile(Path path, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void deleteDirectory(Path path, optional boolean recursive, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void copyFile(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void copyDirectory(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void moveFile(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void moveDirectory(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void rename(Path path, DOMString newName, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void listDirectory(Path path, ListDirectorySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional FileFilter? filter) raises(WebAPIException); DOMString toURI(Path path) raises(WebAPIException); boolean isFile(Path path) raises(WebAPIException); boolean isDirectory(Path path) raises(WebAPIException); boolean pathExists(Path path) raises(WebAPIException); DOMString getDirName(DOMString path); void resolve(DOMString location, FileSuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileMode? mode) raises(WebAPIException); void getStorage(DOMString label, FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void listStorages(FileSystemStorageArraySuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); long addStorageStateChangeListener(FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void removeStorageStateChangeListener(long watchId) raises(WebAPIException); };
This manager interface exposes the Filesystem base API and provides functionalities, such as determining root and default locations, resolving a given location into a file handle and registering filesystem listeners for filesystem events.
readonly long maxNameLength
The maximum file or directory name length for the current platform.
Code example:
console.log("The maximum name length is " + tizen.filesystem.maxNameLength);
Output example:
The maximum name length is 255
readonly long maxPathLength
The maximum path length limit for the current platform.
console.log("The maximum path length is " + tizen.filesystem.maxPathLength);
The maximum path length is 4096
openFile
Opens a file or creates a file pointed by path.
FileHandle openFile(Path path, FileMode openMode, optional boolean makeParents);
If the operation succeeds, a file handle to the newly created or opened file is returned, otherwise an exception is thrown.
Following file open modes are supported:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Privilege: http://tizen.org/privilege/filesystem.write
Remark: Write permission is needed, when file is opened in modes: a, rw, rwo and w. Read permission is needed, when file is opened in modes: r, rw and rwo.
Parameters:
documents/path/to/dir/file.ext
Return value:
Exceptions:
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); console.log("File opened for writing"); fileHandleWrite.writeString("Lorem ipsum dolor sit amet..."); console.log("String has been written to the file"); fileHandleWrite.close(); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); console.log("File opened for reading"); var fileContent = fileHandleRead.readString(); console.log("File content: " + fileContent); fileHandleRead.close();
File opened for writing String has been written to the file File opened for reading File content: Lorem ipsum dolor sit amet...
createDirectory
Creates directory pointed by path.
void createDirectory(Path path, optional boolean makeParents, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Successful directory creation invokes successCallback function, if specified. In case of failure errorCallback function is invoked, if specified.
The ErrorCallback is launched with these error types:
function errorCallback(error) { console.log("An error occurred, during directory creation: " + error.message); } function successCallback(path) { console.log("The directory has been created, path to created directory: " + path); /* Directory can now be accessed. */ } try { tizen.filesystem.createDirectory( "documents/foo_dir/bar_dir", true, successCallback, errorCallback); } catch (error) { console.log("Directory cannot be created: " + error.message); }
The directory has been created, path to created directory: documents/foo_dir/bar_dir
deleteFile
Deletes file pointed by path.
void deleteFile(Path path, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Successful file deletion invokes successCallback function, if specified. In case of failure errorCallback function is invoked, if specified.
function errorCallback(error) { console.log("An error occurred, during file deletion: " + error.message); } function successCallback(path) { console.log("The file has been deleted, path to the parent of deleted file: " + path); } try { tizen.filesystem.deleteFile("documents/foo", successCallback, errorCallback); } catch (error) { console.log("File cannot be deleted: " + error.message); }
The file has been deleted, path to the parent of deleted file: documents
deleteDirectory
Deletes directory or directory tree under the current directory pointed by path.
void deleteDirectory(Path path, optional boolean recursive, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Successful directory deletion invokes successCallback function, if specified. In case of failure errorCallback function is invoked, if specified.
function errorCallback(error) { console.log("An error occurred, during directory deletion: " + error.message); } function successCallback(path) { console.log("The directory has been deleted, path to the parent of deleted directory: " + path); } try { tizen.filesystem.deleteDirectory("documents/foo_dir", true, successCallback, errorCallback); } catch (error) { console.log("Directory cannot be deleted: " + error.message); }
The directory has been deleted, path to the parent of deleted directory: documents
copyFile
Copies file from location pointed by sourcePath to destinationPath.
void copyFile(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Successful file copying invokes successCallback function, if specified. In case of failure errorCallback function is invoked, if specified.
false
function errorCallback(error) { console.log("An error occurred, during copy operation: " + error.message); } function successCallback(path) { console.log("The file has been copied, path to copied file: " + path); /* File copy can now be accessed. */ } try { tizen.filesystem.copyFile("documents/foo", "documents/bar", true, successCallback, errorCallback); } catch (error) { console.log("Copy operation cannot be performed: " + error.message); }
The file has been copied, path to copied file: documents/bar
copyDirectory
Recursively copies directory pointed by sourcePath to destinationPath.
void copyDirectory(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
The method merges content of the directory pointed by sourcePath with content of the directory pointed by destinationPath, if exists. If the directory pointed by destinationPath does not exist, it is created.
Successful directory copying invokes successCallback function, if specified. In case of failure errorCallback function is invoked, if specified.
function errorCallback(error) { console.log("An error occurred, during copy operation: " + error.message); } function successCallback(path) { console.log("The directory has been copied, path to copied directory: " + path); /* Directory copy can now be accessed. */ } try { tizen.filesystem.copyDirectory( "documents/foo_dir", "documents/bar_dir", true, successCallback, errorCallback); } catch (error) { console.log("Copy operation cannot be performed: " + error.message); }
The directory has been copied, path to copied directory: documents/bar_dir
function errorCallback(error) { console.log("An error occurred: " + error.message); } function createFooDirCallback() { tizen.filesystem.createDirectory( "documents/foo_dir/dir_2", true, createFileCallback, errorCallback); } function listCallback(files, path) { console.log("Found inside " + path + " directory:"); for (var i = 0; i < files.length; i++) { console.log(files[i]); } } function successCallback(path) { console.log("The directory has been created and copied, path to directory: " + path); /* Directory 'documents/bar_dir' content is as below: */ /* documents/bar_dir/dir_1 */ /* documents/bar_dir/dir_2 */ /* documents/bar_dir/dir_1/file */ tizen.filesystem.listDirectory("documents/bar_dir", listCallback, errorCallback); tizen.filesystem.listDirectory("documents/bar_dir/dir_1", listCallback, errorCallback); } function createFileCallback() { tizen.filesystem.openFile("documents/foo_dir/dir_1/file", "w").close(); try { tizen.filesystem.copyDirectory( "documents/foo_dir", "documents/bar_dir", true, successCallback, errorCallback); } catch (error) { console.log("Copy operation cannot be performed: " + error.message); } } tizen.filesystem.createDirectory( "documents/foo_dir/dir_1", true, createFooDirCallback, errorCallback);
The directory has been created and copied, path to directory: documents/bar_dir Found inside documents/bar_dir directory: dir_1 dir_2 Found inside documents/bar_dir/dir_1 directory: file
moveFile
Moves file pointed by sourcePath to destinationPath.
void moveFile(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Successful file moving invokes successCallback function, if specified. In case of failure errorCallback function is invoked, if specified.
function errorCallback(error) { console.log("An error occurred, during move operation: " + error.message); } function successCallback(path) { console.log("The file has been moved, path to moved file: " + path); /* Moved file can now be accessed. */ } try { tizen.filesystem.moveFile( "documents/foo", "documents/foo_dir/", false, successCallback, errorCallback); } catch (error) { console.log("Move operation cannot be performed: " + error.message); }
The file has been moved, path to moved file: documents/foo_dir/foo
moveDirectory
Recursively moves directory pointed by sourcePath to destinationPath.
void moveDirectory(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
The method merges content of the directory pointed by sourcePath with content of the directory with the same name in destinationPath, if exists.
Successful directory moving invokes successCallback function, if specified. In case of failure errorCallback function is invoked, if specified.
function errorCallback(error) { console.log("An error occurred, during move operation: " + error.message); } function successCallback(path) { console.log("The directory has been moved, path to moved directory: " + path); /* Moved directory can now be accessed. */ } try { tizen.filesystem.moveDirectory( "documents/foo_dir", "documents/bar_dir/", false, successCallback, errorCallback); } catch (error) { console.log("Move operation cannot be performed: " + error.message); }
The directory has been moved, path to moved directory: documents/bar_dir/foo_dir
rename
Renames file or directory located in path to name newName.
void rename(Path path, DOMString newName, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Successful renaming invokes successCallback function, if specified. In case of failure errorCallback function is invoked, if specified.
function errorCallback(error) { console.log("An error occurred, during rename operation: " + error.message); } function successCallback(path) { console.log("The file has been renamed, path to renamed file or directory: " + path); } try { tizen.filesystem.rename("documents/foo", "bar", successCallback, errorCallback); } catch (error) { console.log("Rename operation cannot be performed: " + error.message); }
The file has been renamed, path to renamed file or directory: documents/bar
listDirectory
Lists directory content located in path.
void listDirectory(Path path, ListDirectorySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional FileFilter? filter);
Successful listing of directory content invokes successCallback function, if specified. In case of failure errorCallback function is invoked, if specified.
If the filter is passed and contains valid values, only those directories or files in the directory that match the filter criteria specified in the FileFilter interface are returned in successCallback method. If the filter is null or undefined the implementation must return the full list of files in the directory.
If the directory does not contain any files or directories, or the filter criteria do not match with any files or directories, the successCallback is invoked with an empty array.
function errorCallback(error) { console.log("An error occurred, during directory listing: " + error.message); } function successCallback(files, path) { console.log("Found directories in " + path + " directory:"); for (var i = 0; i < files.length; i++) { console.log(files[i]); } } try { var start = new Date("Jan 01 2018 00:00:00"); tizen.filesystem.listDirectory("documents/", successCallback, errorCallback, {name: "foo_%", isDirectory: true, startModified: start}); } catch (error) { console.log("Directory listing cannot be performed: " + error.message); }
Found directories in documents/ directory: foo_dir_c foo_dir_b foo_dir_d foo_dir_a
toURI
Converts path to file URI.
DOMString toURI(Path path);
Remark: The function does not check if path exists in filesystem.
var path1 = tizen.filesystem.toURI("documents/directory/file.ext"); var path2 = tizen.filesystem.toURI("/opt/usr/home/owner/content/Documents/directory/file.ext"); var path3 = tizen.filesystem.toURI("file:///opt/usr/home/owner/content/Documents/directory/file.ext"); /* All above paths point to the same file. */ console.log(path1); console.log(path2); console.log(path3); var mmcPath = tizen.filesystem.toURI("removable_sda1/Documents/directory/file"); console.log(mmcPath);
file:///opt/usr/home/owner/content/Documents/directory/file.ext file:///opt/usr/home/owner/content/Documents/directory/file.ext file:///opt/usr/home/owner/content/Documents/directory/file.ext file:///opt/media/USBDriveA1/Documents/directory/file
isFile
Checks if given path points to a file.
boolean isFile(Path path);
console.log("documents/foo_file is " + (tizen.filesystem.isFile("documents/foo_file") ? "file" : "directory"));
documents/foo_file is file
isDirectory
Checks if given path points to a directory.
boolean isDirectory(Path path);
console.log("documents/foo_dir is " + (tizen.filesystem.isDirectory("documents/foo_dir") ? "directory" : "file"));
documents/foo_dir is directory
pathExists
Checks if given path exists.
boolean pathExists(Path path);
console.log("documents/foo " + (tizen.filesystem.pathExists("documents/foo") ? "exists" : "does not exist"));
documents/foo does not exist
getDirName
Returns path to directory for given path.
DOMString getDirName(DOMString path);
Strips trailing '/', then breaks path into two components by last path separator, returns first component.
Remark: This function does not check if path is valid or exists in filesystem.
console.log(tizen.filesystem.getDirName("/home/owner/media/Documents"));
"/home/owner/media"
resolve
Resolves a location to a file handle after validating it.
Deprecated. Since 5.0
void resolve(DOMString location, FileSuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileMode? mode);
A location can contain a virtual path like "documents/some_file.txt" or a file URI like "file:///my_strange_path/some_file.png". A location is not allowed to contain the "." or ".." directory entries inside its value.
The list of root locations that must be supported by a compliant implementation are:
The mode parameter specifies whether the resulting File object has read-only access (r access), read and write access (rw access), append access (a access), or write access (w access) to the root location containing directory tree. Permission for the requested access is obtained from the security framework. Once the resulting File object has access, access is inherited by any other File objects that are derived from this instance without any further reference to the security framework, as noted in descriptions of certain methods of File.
Remark: camera location is supported since Tizen 2.3. If a device does not support camera, NotSupportedError will be thrown.
tizen.filesystem.resolve("images", function(dir) { console.log("Images are stored in " + dir.path); }, function(e) { console.log("Error: " + e.message); }, "r");
getStorage
Gets information about a storage based on its label. For example: "MyThumbDrive", "InternalFlash".
void getStorage(DOMString label, FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror);
The onsuccess method receives the data structure as an input argument containing additional information about the drive.
function onStorage(storage) { /* Do something. */ } function onStorageError(e) { console.log("Storage not found: " + e.message); } tizen.filesystem.getStorage("music", onStorage, onStorageError);
listStorages
Lists the available storages (both internal and external) on a device. The onsuccess method receives a list of the data structures as input argument containing additional information about each drive found. It can get storages that would have a label named as "internal0", virtual roots (images, documents, ...), "removable1", "removable2". "removable1" label is used to resolve sdcard and "removable2" label is used to resolve USB host, if supported. The vfat filesystem used to sdcard filesystem widely is not case-sensitive. If you want to handle the file on sdcard, you need to consider case-sensitive filenames are regarded as same name.
void listStorages(FileSystemStorageArraySuccessCallback onsuccess, optional ErrorCallback? onerror);
Labels can differ depending on platform implementation.
function alertForCorruptedRemovableDrives(storages) { for (var i = 0; i < storages.length; i++) { if (storages[i].type != "EXTERNAL") continue; if (storages[i].state == "UNMOUNTABLE") console.log("External drive " + storages[i].label + " is corrupted."); } } tizen.filesystem.listStorages(alertForCorruptedRemovableDrives);
addStorageStateChangeListener
Adds a listener to subscribe to notifications when a change in storage state occurs.
long addStorageStateChangeListener(FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror);
The most common usage for this method is to watch for any additions and removals of external storages.
When executed, it returns a subscription identifier that identifies the watch operation. After returning the identifier, the watch operation is started asynchronously. The onsuccess method will be invoked every time a storage state changes. If the attempt fails, the onerror if present will be invoked with the relevant error type.
The watch operation must continue until the removeStorageStateChangeListener() method is called with the corresponding subscription identifier.
var watchID; function onStorageStateChanged(storage) { if (storage.state == "MOUNTED") console.log("Storage " + storage.label + " was added!"); } watchID = tizen.filesystem.addStorageStateChangeListener(onStorageStateChanged);
removeStorageStateChangeListener
Removes a listener to unsubscribe from a storage watch operation.
void removeStorageStateChangeListener(long watchId);
If the watchId argument is valid and corresponds to a subscription already in place, the watch process will be stopped and no further callbacks will be invoked. Otherwise, the method call has no effect.
var watchID; function onStorageStateChanged(storage) { if (storage.state == "MOUNTED") console.log("Storage " + storage.label + " was added!"); tizen.filesystem.removeStorageStateChangeListener(watchID); } watchID = tizen.filesystem.addStorageStateChangeListener(onStorageStateChanged);
The FileSystemStorage interface gives additional information about a storage, such as if the device is mounted, if it is a removable drive or not, or the device's name.
[NoInterfaceObject] interface FileSystemStorage { readonly attribute DOMString label; readonly attribute FileSystemStorageType type; readonly attribute FileSystemStorageState state; };
To retrieve the mount point, the resolve() method should be used using the label as argument.
readonly DOMString label
The storage name.
This attribute is used as an input for methods such as getStorage() and also used as location parameter for File.resolve() and FileSystemManager.resolve().
readonly FileSystemStorageType type
The storage type as internal or external.
readonly FileSystemStorageState state
The storage state as mounted or not.
Object representing file, used for read/write operations.
[NoInterfaceObject] interface FileHandle { readonly attribute Path path; long long seek(long long offset, optional BaseSeekPosition whence) raises(WebAPIException); void seekNonBlocking(long long offset, optional SeekSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional BaseSeekPosition whence) raises(WebAPIException); DOMString readString(optional long long? count, optional DOMString inputEncoding) raises(WebAPIException); void readStringNonBlocking(optional ReadStringSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional long long count, optional DOMString inputEncoding) raises(WebAPIException); long long writeString(DOMString inputString, optional DOMString outputEncoding) raises(WebAPIException); void writeStringNonBlocking(DOMString inputString, optional WriteStringSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional DOMString outputEncoding) raises(WebAPIException); Blob readBlob(optional long long size) raises(WebAPIException); void readBlobNonBlocking(optional ReadBlobSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional long long? size) raises(WebAPIException); void writeBlob(Blob blob) raises(WebAPIException); void writeBlobNonBlocking(Blob blob, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); Uint8Array readData(optional long long size) raises(WebAPIException); void readDataNonBlocking(optional ReadDataSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional long long? size) raises(WebAPIException); void writeData(Uint8Array data) raises(WebAPIException); void writeDataNonBlocking(Uint8Array data, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void flush() raises(WebAPIException); void flushNonBlocking(optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void sync() raises(WebAPIException); void syncNonBlocking(optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void close() raises(WebAPIException); void closeNonBlocking(optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); };
Each read or write operation moves position in file forwards to the end of read/written data (there is an underlying file position's indicator).
Remark: Due to multibyte UTF-8 encoding, if current file's pointer does not point to beginning of multibyte sequence (see: UTF-16, emoji), using seek() combined with UTF-8 readString() will result in string starting from valid character. Incomplete byte sequence at the beginning may be omitted. Be aware about using seek and write methods together. It can result in writing in the middle of multibyte sequence, which can lead to file with corrupted content.
readonly Path path
Path, as passed to openFile.
seek
Sets position indicator in file stream to offset.
long long seek(long long offset, optional BaseSeekPosition whence);
Note, that current position indicator value, can be obtained by calling seek(0, "CURRENT").
var dataToWrite = new Uint8Array([11, 21, 31, 44, 55, 66, 71, 81, 91]); /* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeData(dataToWrite); fileHandleWrite.close(); console.log("Data has been written"); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); var firstThreeBytes = fileHandleRead.readData(3); console.log("First three bytes: " + firstThreeBytes); var position = fileHandleRead.seek(-3, "END"); /* Moving to position three bytes to the end of file. */ var lastThreeBytes = fileHandleRead.readData(3); console.log("Last three bytes: " + lastThreeBytes); fileHandleRead.seek(3, "BEGIN"); /* Moving to position at third byte. */ var bytesBetween = fileHandleRead.readData(position - 3); console.log("Bytes between: " + bytesBetween); fileHandleRead.close();
Data has been written First three bytes: 11,21,31 Last three bytes: 71,81,91 Bytes between: 44,55,66
seekNonBlocking
void seekNonBlocking(long long offset, optional SeekSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional BaseSeekPosition whence);
Successful seek operation invokes onsuccess function, if specified. In case of failure onerror function is invoked, if specified.
Note, that current position indicator value, can be obtained in SeekSuccessCallback by calling seekNonBlocking(0, "CURRENT"). seekNonBlocking is executed in background and does not block further instructions.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeStringNonBlocking("Lorem ipsum dolor sit amet...", function(bytesCount) { console.log("Number of bytes written: " + bytesCount); }, function(error) { console.log(error); }); /* Moving to position 3 bytes to the end of file to alter three dots ("..."). */ fileHandleWrite.seekNonBlocking(-3, function(new_position) { console.log("Moved to position: " + new_position); }, function(error) { console.log(error); }, "END"); fileHandleWrite.writeStringNonBlocking(", consectetur adipiscing elit...", function(bytesCount) { console.log("Number of bytes written: " + bytesCount); }, function(error) { console.log(error); }); /* Moving to position 3 bytes to the end of file to alter three dots ("..."). */ fileHandleWrite.seekNonBlocking(-3, function(new_position) { console.log("Moved to position: " + new_position); }, function(error) { console.log(error); }, "END"); fileHandleWrite.writeStringNonBlocking(", sed do eiusmod...", function(bytesCount) { console.log("Number of bytes written: " + bytesCount); }, function(error) { console.log(error); }); fileHandleWrite.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); }); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); /* ReadStringSuccessCallback should be executed. */ fileHandleRead.readStringNonBlocking( function(output) { console.log("File content: " + output); }, function(error) { console.log(error); }); fileHandleRead.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); });
Number of bytes written: 29 Moved to position: 26 Number of bytes written: 32 Moved to position: 55 Number of bytes written: 19 File handle closed File content: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod... File handle closed
readString
Reads file content as string.
DOMString readString(optional long long? count, optional DOMString inputEncoding);
Sets file handle position indicator at the end of read data. Reads given number of characters.
Remark: Resulting string can have length larger than count, due to possible UTF-16 surrogate pairs in it. String length in JavaScript is counted in UTF-16 encoding, so for example string containing one emoji (surrogate of two UTF-16) character will have length of two.
readStringNonBlocking
void readStringNonBlocking(optional ReadStringSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional long long count, optional DOMString inputEncoding);
Reads given number of characters. Sets file handle position indicator at the end of read data. readStringNonBlocking is executed in background and does not block further instructions.
Successful read operation invokes onsuccess function, if specified. In case of failure onerror function is invoked, if specified.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); console.log("File opened for writing"); fileHandleWrite.writeStringNonBlocking("Lorem ipsum dolor sit amet...", function(bytesCount) { console.log("Number of bytes written: " + bytesCount); }, function(error) { console.log(error); }); fileHandleWrite.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); }); /* Opening file for read - below code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); /* ReadStringSuccessCallback should be executed. */ fileHandleRead.readStringNonBlocking( function(output) { console.log("File content: " + output); }, function(error) { console.log(error); }); fileHandleRead.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); });
File opened for writing Number of bytes written: 29 File handle closed File content: Lorem ipsum dolor sit amet... File handle closed
writeString
Writes inputString content to a file.
long long writeString(DOMString inputString, optional DOMString outputEncoding);
Sets file handle position indicator at the end of written data.
writeStringNonBlocking
void writeStringNonBlocking(DOMString inputString, optional WriteStringSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional DOMString outputEncoding);
Sets file handle position indicator at the end of written data. writeStringNonBlocking is executed in background and does not block further instructions.
Successful write operation invokes successCallback function, if specified. In case of failure onerror function is invoked, if specified.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeStringNonBlocking("Lorem ipsum dolor sit amet...", function(bytesCount) { console.log("Number of bytes written: " + bytesCount); }, function(error) { console.log(error); }); fileHandleWrite.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); }); /* Opening file for read - below code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); /* ReadStringSuccessCallback should be executed. */ fileHandleRead.readStringNonBlocking( function(output) { console.log("File content: " + output); }, function(error) { console.log(error); }); fileHandleRead.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); });
Number of bytes written: 29 File handle closed File content: Lorem ipsum dolor sit amet... File handle closed
readBlob
Reads file content as Blob.
Blob readBlob(optional long long size);
Sets file handle position indicator at the end of read data.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); var b = new Blob(["Lorem ipsum dolor sit amet..."], {type: "text/plain"}); fileHandleWrite.writeBlob(b); fileHandleWrite.close(); console.log("Blob content has been written to file"); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); var fileContentInBlob = fileHandleRead.readBlob(); fileHandleRead.close(); const reader = new FileReader(); /* Event fires after the blob has been read/loaded. */ reader.onloadend = function(content) { const text = content.srcElement.result; console.log("File content: " + text); }; /* Starts reading the blob as text. */ reader.readAsText(fileContentInBlob);
Blob content has been written to file File content: Lorem ipsum dolor sit amet...
readBlobNonBlocking
void readBlobNonBlocking(optional ReadBlobSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional long long? size);
Sets file handle position indicator at the end of read data. readBlobNonBlocking is executed in background and does not block further instructions.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); var b = new Blob(["Lorem ipsum dolor sit amet..."], {type: "text/plain"}); fileHandleWrite.writeBlobNonBlocking(b, function() { console.log("Blob content has been written to file"); }, function(error) { console.log(error); }); fileHandleWrite.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); }); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); /* Creation of a reader capable of extracting Blob content. */ const reader = new FileReader(); /* Event fires after the blob has been read/loaded. */ reader.onloadend = function(content) { const text = content.srcElement.result; console.log("File content: " + text); }; function readBlobCallback(fileContentInBlob) { reader.readAsText(fileContentInBlob); } /* readBlobCallback should be executed. */ fileHandleRead.readBlobNonBlocking(readBlobCallback, function(error) { console.log(error); }); fileHandleRead.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); });
Blob content has been written to file File handle closed File handle closed File content: Lorem ipsum dolor sit amet...
writeBlob
Writes Blob to file.
void writeBlob(Blob blob);
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); var b = new Blob(["Lorem ipsum dolor sit amet..."], {type: "text/plain"}); fileHandleWrite.writeBlob(b); fileHandleWrite.close(); console.log("Blob content has been written to file"); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); var fileContentInBlob = fileHandleRead.readBlob(); fileHandleRead.close(); console.log("File content has been read from file"); const reader = new FileReader(); /* Event fires after the blob has been read/loaded. */ reader.onloadend = function(content) { const text = content.srcElement.result; console.log("File content: " + text); }; /* Starts reading the blob as text. */ reader.readAsText(fileContentInBlob);
Blob content has been written to file File content has been read from file File content: Lorem ipsum dolor sit amet...
writeBlobNonBlocking
void writeBlobNonBlocking(Blob blob, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
Sets file handle position indicator at the end of written data. writeBlobNonBlocking is executed in background and does not block further instructions.
Successful write operation invokes onsuccess function, if specified. In case of failure onerror function is invoked, if specified.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); var b = new Blob(["Lorem ipsum dolor sit amet..."], {type: "text/plain"}); fileHandleWrite.writeBlobNonBlocking(b, function() { console.log("Blob content has been written to file"); }, function(error) { console.log(error); }); fileHandleWrite.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); }); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); /* Creation of a reader capable of extracting Blob content. */ const reader = new FileReader(); /* Event fires after the blob has been read/loaded. */ reader.onloadend = function(content) { const text = content.srcElement.result; console.log("File content: " + text); }; function readBlobCallback(fileContentInBlob) { reader.readAsText(fileContentInBlob); } /* readBlobCallback should be executed. */ fileHandleRead.readBlobNonBlocking(readBlobCallback); fileHandleRead.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); });
readData
Reads file content as binary data.
Uint8Array readData(optional long long size);
Can be used in combination with atob() or btoa() functions. Sets file handle position indicator at the end of read data.
var dataToWrite = new Uint8Array([11, 21, 31, 71, 81, 91]); /* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeData(dataToWrite); fileHandleWrite.close(); console.log("Data has been written"); /* Opening file for read - below code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); var fileContentInUint8Array = fileHandleRead.readData(); fileHandleRead.close(); console.log("Data read from file: " + fileContentInUint8Array);
Data has been written Data read from file: 11,21,31,71,81,91
readDataNonBlocking
void readDataNonBlocking(optional ReadDataSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional long long? size);
Can be used in combination with atob() or btoa() functions. Sets file handle position indicator at the end of read data. readDataNonBlocking is executed in background and does not block further instructions.
var dataToWrite = new Uint8Array([11, 21, 31, 71, 81, 91]); /* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeDataNonBlocking(dataToWrite, function(dataRead) { console.log("Write done"); }, function(error) { console.log(error); }); fileHandleWrite.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); }); /* Opening file for read - below code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); fileHandleRead.readDataNonBlocking( function(dataRead) { console.log("Data read from file: " + dataRead); }, function(error) { console.log(error); }); fileHandleRead.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); });
Write done File handle closed Data read from file: 11,21,31,71,81,91 File handle closed
writeData
Writes binary data to file.
void writeData(Uint8Array data);
Can be used in combination with atob() or btoa() functions. Sets file handle position indicator at the end of written data.
writeDataNonBlocking
void writeDataNonBlocking(Uint8Array data, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
Can be used in combination with atob() or btoa() functions. Sets file handle position indicator at the end of written data. writeDataNonBlocking is executed in background and does not block further instructions.
flush
Flushes data.
void flush();
For file handles with permission to write, flush writes any changes made to file content to underlying buffer.
Flush does not ensure that data is written on storage device, it only synchronizes RAM with file descriptor. To ensure storage synchronization use sync, close or their asynchronous equivalent methods, which guarantee such synchronization.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); fileHandleWrite.writeString("Lorem ipsum dolor sit amet..."); console.log("Data has been written to file"); /* Calling flush() ensures that content has been written to file descriptor and can be read by any */ /* process. */ fileHandleWrite.flush(); console.log("Data has been flushed to system file buffer and now can be read"); var fileContent = fileHandleRead.readString(); console.log("Read data: " + fileContent); fileHandleWrite.close(); fileHandleRead.close();
Data has been written to file Data has been flushed to system file buffer and now can be read Read data: Lorem ipsum dolor sit amet...
flushNonBlocking
void flushNonBlocking(optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
Successful flushing invokes onsuccess function, if specified. In case of failure onerror function is invoked, if specified.
This method is asynchronous. Its execution will occur in background and after all previously commissioned background jobs will finish.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeStringNonBlocking("Lorem ipsum dolor sit amet...", function(bytesCount) { console.log("Number of bytes written: " + bytesCount); }, function(error) { console.log(error); }); /* Calling flushNonBlocking() ensures that content will be written to file descriptor */ /* and can be read by any process. */ fileHandleWrite.flushNonBlocking( function() { console.log("Data has been flushed to system file buffer and now can be read"); }, function(error) { console.log(error); }); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); fileHandleRead.readStringNonBlocking( function(output) { console.log("File content: " + output); }, function(error) { console.log(error); }); fileHandleWrite.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); }); fileHandleRead.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); });
Number of bytes written: 29 Data has been flushed to system file buffer and now can be read File content: Lorem ipsum dolor sit amet... File handle closed File handle closed
sync
Synchronizes data to storage device.
void sync();
The sync function is intended to force a physical write of data from the buffer cache and to assure that after a system crash or other failure that all data up to the time of the sync() call is recorded on the disk.
var dataToWrite = new Uint8Array([11, 21, 31, 71, 81, 91]); /* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeData(dataToWrite); /* Calling sync() forces a physical write of data, so it is safe */ /* even after system crash or power shut down. */ fileHandleWrite.sync(); console.log("Data has been synced"); /* close() method provides the same functionality as sync() and ends access to file. */ fileHandleWrite.close();
Data has been synced
**syncNonBlocking ** Synchronizes data to storage device.
void syncNonBlocking(optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
The syncNonBlocking function is intended to force a physical write of data from the buffer cache and to assure that after a system crash or other failure that all data up to the time of the syncNonBlocking() execution is recorded on the disk.
Successful syncing invokes onsuccess function, if specified. In case of failure onerror function is invoked, if specified.
var dataToWrite = new Uint8Array([11, 21, 31, 71, 81, 91]); /* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeDataNonBlocking(dataToWrite, function(dataRead) { console.log("Write done"); }, function(error) { console.log(error); }); /* Calling syncNonBlocking() will force a physical write of data, so it will be safe */ /* even after system crash or power shut down. */ fileHandleWrite.syncNonBlocking( function() { console.log("Data has been synced"); }, function(error) { console.log(error); }); /* close() method provides the same functionality as sync() and ends access to file. */ fileHandleWrite.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); });
Write done Data has been synced File handle closed
close
Closes file handle.
void close();
Closes the given file stream. Closing file guarantees writing changes made to FileHandle to the storage device. Further operations on this file handle are not allowed.
Remark: This method is synchronous. If any asynchronous method was called before close, close will block further instructions until all background jobs finish execution. Note, that if file handle functions are put into any callbacks and this callback was not yet called, synchronous close will wait only for already ordered background jobs to finish, preventing successful execution of any further operations on closed file handle.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeString("Lorem ipsum dolor sit amet..."); fileHandleWrite.close(); console.log("String has been written to the file"); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); var positionOfFileEnd = fileHandleRead.seek(0, "END"); console.log("Seek operation done. Position of file end: " + positionOfFileEnd); fileHandleRead.close(); console.log("File is now closed");
String has been written to the file Seek operation done. Position of file end: 29 File is now closed
closeNonBlocking
void closeNonBlocking(optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
Successful closing invokes onsuccess function, if specified. In case of failure onerror function is invoked, if specified.
/* Opening file for write - file is created if not exists, */ /* otherwise existing file is truncated. */ var fileHandleWrite = tizen.filesystem.openFile("documents/file", "w"); fileHandleWrite.writeStringNonBlocking("Lorem ipsum dolor sit amet...", function(bytesCount) { console.log("Number of bytes written: " + bytesCount); }, function(error) { console.log(error); }); fileHandleWrite.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); }); /* Opening file for read - this code assumes that there is */ /* a file named "file" in documents directory. */ var fileHandleRead = tizen.filesystem.openFile("documents/file", "r"); var positionOfFileEnd = fileHandleRead.seekNonBlocking(0, function(new_position) { console.log("Moved to position: " + new_position); }, function(error) { console.log(error); }, "END"); fileHandleRead.closeNonBlocking( function() { console.log("File handle closed"); }, function(error) { console.log(error); });
Number of bytes written: 29 File handle closed Moved to position: 29 File handle closed
The File interface represents the file abstraction in use.
[NoInterfaceObject] interface File { readonly attribute File? parent; readonly attribute boolean readOnly; readonly attribute boolean isFile; readonly attribute boolean isDirectory; readonly attribute Date? created; readonly attribute Date? modified; readonly attribute DOMString path; readonly attribute DOMString name; readonly attribute DOMString fullPath; readonly attribute unsigned long long fileSize; readonly attribute long length; DOMString toURI() raises(WebAPIException); void listFiles(FileArraySuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileFilter? filter) raises(WebAPIException); void openStream(FileMode mode, FileStreamSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding) raises(WebAPIException); void readAsText(FileStringSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding) raises(WebAPIException); void copyTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void moveTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); File createDirectory(DOMString dirPath) raises(WebAPIException); File createFile(DOMString relativeFilePath) raises(WebAPIException); File resolve(DOMString filePath) raises(WebAPIException); void deleteDirectory(DOMString directoryPath, boolean recursive, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void deleteFile(DOMString filePath, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); };
The file object permissions for the file object location and tree rooted at that location depend upon the mode defined in the resolve method. When a File object creates a child File object, the new File object inherits its access rights from the parent object without any reference to the security framework, as noted in certain methods of File.
A file handle represents either a file or a directory:
A file can be opened for both read and write operations, using a FileStream handle. A list of files and sub-directories can be obtained from a directory and a resolve method exists to resolve files or sub-directories more conveniently than processing directory listings.
A file handle representing a file can be opened for I/O operations, such as reading and writing.
A file handle representing a directory can be used for listing all files and directories rooted as the file handle location.
function onsuccess(files) { for (var i = 0; i < files.length; i++) { /* Alerts each name of dir's content. */ console.log(files[i].name); } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); } /* List directory content. */ dir.listFiles(onsuccess, onerror);
readonly File parent [nullable]
The parent directory handle.
This attribute is set to null if there is no parent directory. This also implies that this directory represents a root location.
/* List directory content. */ dir.listFiles(onsuccess, onerror); function onsuccess(files) { for (var i = 0; i < files.length; i++) { /* Prints the file parent, must contain the */ /* same value for all the files in the loop. */ console.log("All the files should have the same parent " + files[i].parent); } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); }
readonly boolean readOnly
The file/directory access state in the filesystem.
This attribute is set to:
This attribute represents the actual state of a file or directory in the filesystem. Its value is not affected by the mode used in FileSystemManager.resolve() that was used to create the File object from which this File object was obtained.
/* Lists directory content. */ dir.listFiles(onsuccess, onerror); function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (files[i].readOnly) console.log("Cannot write to file " + files[i].name); else console.log("Can write to file " + files[i].name); } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); }
readonly boolean isFile
The flag indicating whether it is a file.
This attribute can have the following values:
readonly boolean isDirectory
The flag indicating whether it is a directory.
readonly Date created [nullable]
The timestamp when a file is first created in the filesystem.
This timestamp is equivalent to the timestamp when a call to createFile() succeeds.
If the platform does not support this attribute, it will be null.
It is unspecified and platform-dependent if the creation timestamp changes when a file is moved.
readonly Date modified [nullable]
The timestamp when the most recent modification is made to a file, usually when the last write operation succeeds.
Opening a file for reading does not change the modification timestamp.
It is unspecified and platform-dependent if the modified timestamp changes when a file is moved.
console.log(file.modified); /* Displays the modification timestamp. */
readonly DOMString path
The path of a file after excluding its file name.
It begins with the name of the root containing the file, followed by the path, including the directory containing the file, but excluding the file name.
Except in some special cases of the File representing the root itself, the last character is always "/".
For example, if a file is located at music/ramones/volume1/RockawayBeach.mp3, the path is music/ramones/volume1/.
For example, if a directory is located at music/ramones/volume1, the path is music/ramones/.
For the virtual roots, the path is same as the name of the virtual root. For example, if the root is music, then the path is music. If the root is documents, then the path is documents.
console.log(file.path); /* Must be music/ if the file is music/foo.mp3. */
readonly DOMString name
The file name after excluding the root name and any path components.
This is the name of this file, excluding the root name and any other path components.
For example, if a file is located at music/ramones/volume1/RockawayBeach.mp3, the name is "RockawayBeach.mp3".
For example, if a directory is located at music/ramones/volume1, the name is be "volume1".
For the special case of the root itself, the name is an empty string.
/* Must be foo.mp3 if the file path is music/foo.mp3. */ console.log(file.name);
readonly DOMString fullPath
The full path of a file.
It begins with the name of the root containing the file, and including the name of the file or directory itself.
For instance, if the RockawayBeach.mp3 file is located at music/ramones/volume1/, then the fullPath is music/ramones/volume1/RockawayBeach.mp3.
For a directory, if the volume1 directory is located at music/ramones/, then the fullPath is music/ramones/volume1.
For the special case of the root itself, if the root is music, then the fullPath is music.
The fullPath is always equal to path + name.
/* Must be music/track1.mp3 if the file is music/track1.mp3. */ console.log(file.fullPath);
readonly unsigned long long fileSize
The size of this file, in bytes.
If an attempt to read this attribute for a directory is made, undefined is returned. To retrieve the number of files and directories contained in the directory, use the length attribute.
/* Displays the file size. */ console.log(file.fileSize);
readonly long length
The number of files and directories contained in a file handle.
If an attempt to read this attribute for a file is made, undefined is returned. To retrieve the size of a file, use the fileSize attribute.
/* "3" if the directory contains two files and one sub-directory. */ console.log(file.length);
Returns a URI for a file to identify an entry (such as using it as the src attribute on an HTML img element). The URI has no specific expiration, it should be valid at least as long as the file exists.
DOMString toURI();
If that URI corresponds to any of the public virtual roots (that is images, videos, music, documents and downloads) the URI must be globally unique and could be used by any widget.
If that URI corresponds to a file located in any a widget's private areas (such as wgt-package, wgt-private, wgt-private-tmp), the generated URI must be unique for that file and for the widget making the request (such as including some derived from the widget ID in the URI). These URIs must not be accessible to other widgets, apart from the one invoking this method.
tizen.filesystem.resolve("music/ramones/RockawayBeach.mp3", function(file) { var audio = new Audio(file.toURI()); audio.play(); console.log(file.toURI()); });
listFiles
Lists all files in a directory.
void listFiles(FileArraySuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileFilter? filter);
The list of files is passed as a File[] in onsuccess() and contains directories and files. However, the directories "." and ".." must not be returned. Each File object that is part of the array must inherit all the access rights (that is, one of the values in FileMode) from the File object in which this method is invoked.
If the filter is passed and contains valid values, only those directories and files in the directory that match the filter criteria specified in the FileFilter interface must be returned in the onsuccess() method. If no filter is passed, the filter is null or undefined, or the filter contains invalid values, the implementation must return the full list of files in the directory.
If the directory does not contain any files or directories, or the filter criteria do not match any files or directories, the onsuccess() is invoked with an empty array.
function onsuccess(files) { console.log("There are " + files.length + " in the selected folder"); } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "r");
openStream
Opens the file in the given mode supporting a specified encoding.
void openStream(FileMode mode, FileStreamSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding);
This operation is performed asynchronously. If the file is opened successfully, the onsuccess() method is invoked with a FileStream that can be used for reading and writing the file, depending on the mode. The returned FileStream instance includes a file pointer, which represents the current position in the file. The file pointer, by default, is at the start of the file, except in the case of opening a file in append ("a") mode, in which case the file pointer points to the end of the file.
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { console.log("File Name is " + files[i].name); /* Displays file name. */ } var testFile = documentsDir.createFile("test.txt"); if (testFile != null) { testFile.openStream("w", function(fs) { fs.write("HelloWorld"); fs.close(); }, function(e) { console.log("Error " + e.message); }, "UTF-8"); } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "rw");
readAsText
Reads the content of a file as a DOMString.
void readAsText(FileStringSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding);
If the operation is successfully executed, the onsuccess() method is invoked and a DOMString is passed as input parameter that represents the file content in the format determined by the encoding parameter.
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { console.log("File Name is " + files[i].name); /* Displays file name. */ if (files[i].isDirectory == false) { files[i].readAsText( function(str) { console.log("The file content " + str); }, function(e) { console.log("Error " + e.message); }, "UTF-8"); } } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "rw");
copyTo
Copies (and overwrites if possible and specified) a file or a directory from a specified location to another specified location.
void copyTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
The copy of the file or directory identified by the originFilePath parameter must be created in the path passed in the destinationFilePath parameter.
The file or directory to copy must be under the Directory from which the method is invoked, otherwise the operation must not be performed.
If the copy is performed successfully, the onsuccess() method is invoked.
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (files[i].isDirectory == false) { documentsDir.copyTo(files[i].fullPath, "images/backup/" + files[i].name, false, function() { console.log("File copied"); }); } } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "rw");
moveTo
Moves (and overwrites if possible and specified) a file or a directory from a specified location to another. This operation is different from instantiating copyTo() and then deleting the original file, as on certain platforms, this operation does not require extra disk space.
void moveTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
The file or directory identified by the originFilePath parameter is moved to the path passed in the destinationFilePath parameter.
The file to move must be under the directory from which the method is invoked, else the operation can not be performed.
If the file or directory is moved successfully, the onsuccess() method is invoked.
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (files[i].isDirectory == false) { documentsDir.moveTo( files[i].fullPath, "images/newFolder/" + files[i].name, false, function() { console.log("File moved"); }); } } } function onerror(error) { console.log( "The error " + error.message + " occurred during listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "rw");
Creates a new directory.
File createDirectory(DOMString dirPath);
A new directory will be created relative to the current directory that this operation is performed on. The implementation will attempt to create all necessary sub-directories specified in the dirPath, as well. The use of "." or ".." in path components is not supported.
This operation can only be performed on file handles that represent directories (that is, isDirectory == true).
If the directory is successfully created, it will be returned.
In case the directory cannot be created, an error must be thrown with the appropriate error type.
var dir; /* Directory object obtained from filesystem API. */ var newDir = dir.createDirectory("newDir"); var anotherNewDir = dir.createDirectory("newDir1/subNewDir1");
createFile
Creates a empty new file in a specified location that is relative to the directory indicated by current File object's path attribute.
File createFile(DOMString relativeFilePath);
The use of "." or ".." in path components is not supported. This operation can only be performed on file handlers that represent a directory (that is, isDirectory == true).
If the file is successfully created, a file handle must be returned by this method.
In case the file cannot be created, an error must be thrown with the appropriate error type.
var newFile = dir.createFile("newFilePath");
Resolves an existing file or directory relative to the current directory this operation is performed on and returns a file handle for it.
File resolve(DOMString filePath);
The filePath is not allowed to contain the "." or ".." directory entries inside its value.
The encoding of file paths is UTF-8.
var file; /* Resolves helloWorld.doc file that is located in the */ /* documents root location. */ tizen.filesystem.resolve("documents", function(dir) { file = dir.resolve("helloWorld.doc"); }, function(e) { console.log("Error " + e.message); }, "rw");
Deletes a specified directory and directory tree if specified.
void deleteDirectory(DOMString directoryPath, boolean recursive, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
This method attempts to asynchronously delete a directory or directory tree under the current directory.
If the recursive parameter is set to true, all the directories and files under the specified directory must be deleted. If the recursive parameter is set to false, the directory is only deleted if it is empty, otherwise an IOError error type will be passed in onerror().
If the deletion is performed successfully, the onsuccess() is invoked.
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (files[i].isDirectory) { documentsDir.deleteDirectory(files[i].fullPath, false, function() { console.log("Directory Deleted"); }, function(e) { console.log("Error " + e.message); }); } } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "rw");
Deletes a specified file. This function attempts to asynchronously delete a file under the current directory.
void deleteFile(DOMString filePath, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (!files[i].isDirectory) { documentsDir.deleteFile(files[i].fullPath, function() { console.log("File Deleted"); }, function(e) { console.log("Error " + e.message); }); } } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "rw");
The dictionary that defines attributes to filter the items returned by the listDirectory() method (or deprecated listFiles()).
dictionary FileFilter { DOMString name; boolean isFile; boolean isDirectory; Date startModified; Date endModified; Date startCreated; Date endCreated; };
When this dictionary is passed to a method, the result-set of the method will only contain file item entries that match the attribute values of the filter.
A file item only matches the FileFilter object if all of the defined filter's attribute values match all of the file item's attributes (only matching values other than undefined or null). This is similar to a SQL's "AND" operation.
An attribute of the file entry matches the FileFilter attribute value in accordance with the following rules:
DOMString name
The File name attribute filter.
Files that have a name that corresponds with this attribute (either exactly or with the specified wildcards) match this filtering criteria.
boolean isFile
If true match only files. If false do not match files. May be undefined.
boolean isDirectory
If true match only directories, If false do not match directories. May be undefined.
Date startModified
The File modified attribute filter.
Files with modified date later than this attribute or equal to it match the filtering criteria.
Date endModified
Files with modified date earlier than this attribute or equal to it match the filtering criteria.
Date startCreated
The File created attribute filter.
Files with created date later than this attribute or equal to it match the filtering criteria.
Date endCreated
Files with created date earlier than this attribute or equal to it match the filtering criteria.
The FileStream interface represents a handle to a File opened for read and/or write operations. Read and write operations are performed relative to a position attribute, which is a pointer that represents the current position in the file.
[NoInterfaceObject] interface FileStream { readonly attribute boolean eof; attribute long position; readonly attribute long bytesAvailable; void close(); DOMString read(long charCount) raises(WebAPIException); octet[] readBytes(long byteCount) raises(WebAPIException); DOMString readBase64(long byteCount) raises(WebAPIException); void write(DOMString stringData) raises(WebAPIException); void writeBytes(octet[] byteData) raises(WebAPIException); void writeBase64(DOMString base64Data) raises(WebAPIException); };
A series of read/write methods are available that permit both binary and text to be processed.
Once a file stream is closed, any operation attempt made on this stream results in a standard JavaScript error.
The read/write operations in this interface do not throw any security exceptions as the access rights are expected to be granted through the initial resolve() method or through the openStream() method of the File interface. Therefore, all actions performed on a successfully resolved File and FileStream are expected to succeed. This avoids successive asynchronous calls and may potentially increase application for a user.
readonly boolean eof
The flag indicating whether the current file pointer is at the end of the file.
If set to true, this attribute indicates that the file pointer is at the end of the file.
If set to false, this attribute indicates that the file pointer is not at the end of the file and so it is anywhere within the file.
if (stream.eof) { /* File has been read completely. */ }
long position
The flag indicating the stream position for reads/writes.
The stream position is an offset of bytes from the start of the file stream. When invoking an operation that reads or writes from the stream, the operation will take place from the byte defined by this position attribute. If the read or write operation is successful, the position of the stream is advanced by the number of bytes read or written. If the read/write operation is not successful, the position of the stream is unchanged.
console.log(stream.position); /* Displays current stream position. */ /* Alters current stream position to the begin of the file, */ /* like seek() in C. */ stream.position = 0;
readonly long bytesAvailable
The number of bytes that are available for reading from the stream.
The number of bytes available for reading is the maximum amount of bytes that can be read in the next read operation. It corresponds to the number of bytes available after the file pointer denoted by the position attribute.
-1 if EOF is true.
console.log(stream.bytesAvailable); /* Displays the available bytes to be read. */
Closes this FileStream.
Flushes any pending buffered writes and closes the File. Always succeeds. Note that pending writes might not succeed.
stream.close(); /* Closes this stream, no subsequent access to stream allowed. */
read
Reads the specified number of characters from the position of the file pointer in a FileStream and returns the characters as a string. The resulting string length might be shorter than charCount if EOF is true.
DOMString read(long charCount);
var text = stream.read(file.fileSize); stream.close();
readBytes
Reads the specified number of bytes from a FileStream.
octet[] readBytes(long byteCount);
/* Reads up to 256 bytes from the stream. */ var raw = stream.readBytes(256); for (var i = 0; i < raw.length; i++) { /* raw[i] contains the i-th byte of the current data chunk. */ }
readBase64
Reads the specified number of bytes from this FileStream, encoding the result in base64.
DOMString readBase64(long byteCount);
/* Reads up to 256 bytes from the stream. */ var base64 = stream.readBase64(256);
write
Writes the specified DOMString to a FileStream.
void write(DOMString stringData);
var text = "Hello world"; stream.write(text);
writeBytes
Writes the specified bytes to this FileStream.
void writeBytes(octet[] byteData);
var bytes = input.readBytes(256); /* Writes the bytes read from input to output. */ output.writeBytes(bytes);
writeBase64
Writes the result to this FileStream after converting the specified base64 DOMString to bytes.
void writeBase64(DOMString base64Data);
var base64 = input.readBase64(256); /* Writes the base64 data read from input to output. */ output.writeBase64(base64);
The FileSuccessCallback interface defines file system success callback with a File object as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface FileSuccessCallback { void onsuccess(File file); };
It is used in asynchronous operations, such as FileSystemManager.resolve(), copying, moving and deleting files.
onsuccess
Called when the asynchronous call completes successfully.
void onsuccess(File file);
The FileSystemStorageArraySuccessCallback callback interface specifies a success callback with an array of FileSystemStorage objects as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface FileSystemStorageArraySuccessCallback { void onsuccess(FileSystemStorage[] storages); };
It is used in asynchronous operations, such as FileSystemManager.listStorages().
void onsuccess(FileSystemStorage[] storages);
The FileSystemStorageSuccessCallback callback interface specifies a success callback with a FileSystemStorage object as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface FileSystemStorageSuccessCallback { void onsuccess(FileSystemStorage storage); };
It is used in asynchronous operations, such as FileSystemManager.getStorage() and FileSystemManager.addStorageStateChangeListener().
void onsuccess(FileSystemStorage storage);
The PathSuccessCallback callback interface specifies a success callback with a Path value as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface PathSuccessCallback { void onsuccess(Path path); };
It is used in asynchronous operations of the FileSystemManager interface.
void onsuccess(Path path);
The SeekSuccessCallback callback interface specifies a success callback with a long long value as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface SeekSuccessCallback { void onsuccess(long long position); };
It is used in asynchronous operation FileHandle.seekNonBlocking().
void onsuccess(long long position);
The ReadStringSuccessCallback callback interface specifies a success callback with a DOMString value as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface ReadStringSuccessCallback { void onsuccess(DOMString string); };
It is used in asynchronous operation FileHandle.readStringNonBlocking().
void onsuccess(DOMString string);
The WriteStringSuccessCallback callback interface specifies a success callback with a long long value as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface WriteStringSuccessCallback { void onsuccess(long long bytesCount); };
It is used in asynchronous operation FileHandle.writeStringNonBlocking().
void onsuccess(long long bytesCount);
The ReadBlobSuccessCallback callback interface specifies a success callback with a Blob object as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface ReadBlobSuccessCallback { void onsuccess(Blob blob); };
It is used in asynchronous operation FileHandle.readBlobNonBlocking().
void onsuccess(Blob blob);
The ReadDataSuccessCallback callback interface specifies a success callback with a Uint8Array value as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface ReadDataSuccessCallback { void onsuccess(Uint8Array data); };
It is used in asynchronous operation FileHandle.readDataNonBlocking().
void onsuccess(Uint8Array data);
The FileStringSuccessCallback callback interface specifies a success callback with a DOMString object as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface FileStringSuccessCallback { void onsuccess(DOMString fileStr); };
It is used in asynchronous operation File.readAsText().
void onsuccess(DOMString fileStr);
The FileStreamSuccessCallback interface specifies a success callback with a FileStream object as input argument.
[Callback=FunctionOnly, NoInterfaceObject] interface FileStreamSuccessCallback { void onsuccess(FileStream filestream); };
It is used in asynchronous operation File.openStream().
Called when the File.openStream asynchronous call completes successfully.
void onsuccess(FileStream filestream);
The ListDirectorySuccessCallback interface defines success callback for listing methods.
[Callback=FunctionOnly, NoInterfaceObject] interface ListDirectorySuccessCallback { void onsuccess(DOMString[] names, Path path); };
This callback interface specifies a success callback with a function taking an array of strings as input argument. It is used in asynchronous operation FileSystemManager.listDirectory().
void onsuccess(DOMString[] names, Path path);
The FileArraySuccessCallback interface defines file system specific success callback for listing methods.
[Callback=FunctionOnly, NoInterfaceObject] interface FileArraySuccessCallback { void onsuccess(File[] files); };
This callback interface specifies a success callback with a function taking an array of File objects as input argument. It is used in asynchronous methods, such as File.listFiles().
void onsuccess(File[] files);
module Filesystem { typedef DOMString Path; typedef Blob Blob; enum FileMode { "a", "r", "rw", "rwo", "w" }; enum FileSystemStorageType { "INTERNAL", "EXTERNAL" }; enum FileSystemStorageState { "MOUNTED", "REMOVED", "UNMOUNTABLE" }; enum BaseSeekPosition { "BEGIN", "CURRENT", "END" }; dictionary FileFilter { DOMString name; boolean isFile; boolean isDirectory; Date startModified; Date endModified; Date startCreated; Date endCreated; }; Tizen implements FileSystemManagerObject; [NoInterfaceObject] interface FileSystemManagerObject { readonly attribute FileSystemManager filesystem; }; [NoInterfaceObject] interface FileSystemManager { readonly attribute long maxNameLength; readonly attribute long maxPathLength; FileHandle openFile(Path path, FileMode openMode, optional boolean makeParents) raises(WebAPIException); void createDirectory(Path path, optional boolean makeParents, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void deleteFile(Path path, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void deleteDirectory(Path path, optional boolean recursive, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void copyFile(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void copyDirectory(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void moveFile(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void moveDirectory(Path sourcePath, Path destinationPath, optional boolean overwrite, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void rename(Path path, DOMString newName, optional PathSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void listDirectory(Path path, ListDirectorySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional FileFilter? filter) raises(WebAPIException); DOMString toURI(Path path) raises(WebAPIException); boolean isFile(Path path) raises(WebAPIException); boolean isDirectory(Path path) raises(WebAPIException); boolean pathExists(Path path) raises(WebAPIException); DOMString getDirName(DOMString path); void getStorage(DOMString label, FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void listStorages(FileSystemStorageArraySuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); long addStorageStateChangeListener(FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void removeStorageStateChangeListener(long watchId) raises(WebAPIException); }; [NoInterfaceObject] interface FileSystemStorage { readonly attribute DOMString label; readonly attribute FileSystemStorageType type; readonly attribute FileSystemStorageState state; }; [NoInterfaceObject] interface FileHandle { readonly attribute Path path; long long seek(long long offset, optional BaseSeekPosition whence) raises(WebAPIException); void seekNonBlocking(long long offset, optional SeekSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional BaseSeekPosition whence) raises(WebAPIException); DOMString readString(optional long long? count, optional DOMString inputEncoding) raises(WebAPIException); void readStringNonBlocking(optional ReadStringSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional long long count, optional DOMString inputEncoding) raises(WebAPIException); long long writeString(DOMString inputString, optional DOMString outputEncoding) raises(WebAPIException); void writeStringNonBlocking(DOMString inputString, optional WriteStringSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional DOMString outputEncoding) raises(WebAPIException); Blob readBlob(optional long long size) raises(WebAPIException); void readBlobNonBlocking(optional ReadBlobSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional long long? size) raises(WebAPIException); void writeBlob(Blob blob) raises(WebAPIException); void writeBlobNonBlocking(Blob blob, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); Uint8Array readData(optional long long size) raises(WebAPIException); void readDataNonBlocking(optional ReadDataSuccessCallback? onsuccess, optional ErrorCallback? onerror, optional long long? size) raises(WebAPIException); void writeData(Uint8Array data) raises(WebAPIException); void writeDataNonBlocking(Uint8Array data, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void flush() raises(WebAPIException); void flushNonBlocking(optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void sync() raises(WebAPIException); void syncNonBlocking(optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void close() raises(WebAPIException); void closeNonBlocking(optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); }; [Callback=FunctionOnly, NoInterfaceObject] interface FileSystemStorageArraySuccessCallback { void onsuccess(FileSystemStorage[] storages); }; [Callback=FunctionOnly, NoInterfaceObject] interface FileSystemStorageSuccessCallback { void onsuccess(FileSystemStorage storage); }; [Callback=FunctionOnly, NoInterfaceObject] interface PathSuccessCallback { void onsuccess(Path path); }; [Callback=FunctionOnly, NoInterfaceObject] interface SeekSuccessCallback { void onsuccess(long long position); }; [Callback=FunctionOnly, NoInterfaceObject] interface ReadStringSuccessCallback { void onsuccess(DOMString string); }; [Callback=FunctionOnly, NoInterfaceObject] interface WriteStringSuccessCallback { void onsuccess(long long bytesCount); }; [Callback=FunctionOnly, NoInterfaceObject] interface ReadBlobSuccessCallback { void onsuccess(Blob blob); }; [Callback=FunctionOnly, NoInterfaceObject] interface ReadDataSuccessCallback { void onsuccess(Uint8Array data); }; [Callback=FunctionOnly, NoInterfaceObject] interface ListDirectorySuccessCallback { void onsuccess(DOMString[] names, Path path); }; };