Module: siteKiosk.io.fileSystem

This module provides access to the file system. Most functions in this module are asynchronous, so make sure you provide an appropriate callback where needed. Also most functions abstract from fiddling with file handles in order to provide convenient means for standard file system operations such as reading a file's text content.

Additionally, files can be opened as a stream. SiteKiosk returns a File Object that provides several methods for more advanced usage.

Note that it is recommended to use the storage path of SiteKiosk.

Example

Some of the file system operations. For more examples refer to the Android IO sample app.

var storagePath = siteKiosk.io.fileSystem.getStoragePath();

//check if there is such a directory and create it if it's not present
var textDirectory = storagePath+"/texts";

if (!siteKiosk.io.fileSystem.exists(textDirectory)) {
      siteKiosk.io.fileSystem.createDirectory(textDirectory, function (errorMessage) {
             //error handling goes here
      });
}

var path = storagePath+"/sample.txt",
                 content = "I am a string!",
                 append = true;
siteKiosk.io.fileSystem.writeTextFile(path,content, append, function (errorMessage) {
    //error handling goes here
}

Classes

File

Methods

<static> copy(from, to, completed)

Copies a file or directory.
Parameters:
Name Type Description
from string The path to the file or directory that should be copied
to string The target path
completed siteKiosk.io.fileSystem~copyCallback Callback will be called when operation finished

<static> createDirectory(path, completed)

Creates a directory.
Parameters:
Name Type Description
path string The path to the directory that should be created
completed siteKiosk.io.fileSystem~createCallback Callback will be called when operation finished

<static> exists() → {boolean}

Checks if the path exists in the file system.
Returns:
Whether the path exists in the file system
Type
boolean

<static> getProperties(path) → {siteKiosk.io.fileSystem~fileProperties}

Retrieves the file properties of a given path.
Parameters:
Name Type Description
path string The path to the file
Returns:
Property object
Type
siteKiosk.io.fileSystem~fileProperties

<static> getStoragePath() → {string}

Gets the path to the directory where user data can be stored.
Returns:
The path to the directory where user data can be stored
Type
string

<static> list(path, completed)

Lists a directory.
Parameters:
Name Type Description
path string The path to the file or directory that should be scanned
completed siteKiosk.io.fileSystem~listCallback Callback will be called when operation finished

<static> open(path, write, completed)

Opens a file as a stream for later use.
Parameters:
Name Type Description
path string The path to the file to be read
write boolean True, if the file should be opened for writing (appending)
completed siteKiosk.io.fileSystem~openCallback Callback will be called when operation finished

<static> readTextFile(path, completed)

Reads text from a file.
Parameters:
Name Type Description
path string The path to the file to be read
completed siteKiosk.io.fileSystem~readTextFileCallback Callback will be called when operation finished

<static> remove(path, completed)

Removes a file or directory.
Parameters:
Name Type Description
path string The path to the file or directory that should be removed
completed siteKiosk.io.fileSystem~removeCallback Callback will be called when operation finished

<static> rename(from, to, completed)

Renames a file or directory. Can also be used to move a file.
Parameters:
Name Type Description
from string The path to the file or directory that should be renamed
to string The target path
completed siteKiosk.io.fileSystem~renameCallback Callback will be called when operation finished

<static> writeTextFile(path, text, append, completed)

Writes text into a file.
Parameters:
Name Type Description
path string The path to the file that should be written
text string The text to be written to the file
append boolean True, if the text should be appended to the end of the file. Otherwise the existing content is erased
completed siteKiosk.io.fileSystem~writeTextFileCallback Callback will be called when operation finished

Type Definitions

copyCallback(errorMessage)

A callback which will be called when the operation to copy a file has been completed.
Parameters:
Name Type Argument Description
errorMessage string <nullable>
An error message or null if the operation has been completed successfully

createCallback(errorMessage)

A callback which will be called when the operation to create a file has been completed.
Parameters:
Name Type Argument Description
errorMessage string <nullable>
An error message or null if the operation has been completed successfully

fileProperties

Type:
  • Object
Properties:
Name Type Description
isDirectory boolean If this file represents a directory on the underlying file system
isHidden boolean Whether or not this file is a hidden file as defined by the operating system
lastModified Date The time when this file was last modified
size number The length of this file in bytes

listCallback(errorMessage, list)

A callback which will be called when the operation to get a list of files has been completed.
Parameters:
Name Type Argument Description
errorMessage string <nullable>
An error message or null if the operation has been completed successfully
list ?Array.<string> <nullable>
An array of strings with file names or null

openCallback(errorMessage, file)

A callback which will be called when the operation to open a file stream has been completed.
Parameters:
Name Type Argument Description
errorMessage string <nullable>
An error message or null if the operation has been completed successfully
file siteKiosk.io.fileSystem~File <nullable>
A file object or null

readTextFileCallback(errorMessage, text)

A callback which will be called when the operation to read a text file to the file system has been completed.
Parameters:
Name Type Description
errorMessage string An error message or an empty string if the operation has been completed successfully
text string The text of the file or an empty string id the operation has not been completed successfully

removeCallback(errorMessage)

A callback which will be called when the operation to remove a file from the file system has been completed.
Parameters:
Name Type Argument Description
errorMessage string <nullable>
An error message or null if the operation has been completed successfully

renameCallback(errorMessage)

A callback which will be called when the operation to rename a file on file system has been completed.
Parameters:
Name Type Argument Description
errorMessage string <nullable>
An error message or null if the operation has been completed successfully

writeTextFileCallback(errorMessage)

A callback which will be called when the operation to write a text file to the file system has been completed.
Parameters:
Name Type Description
errorMessage string An error message or an empty string if the operation has been completed successfully