UserData
This library's API roughly matches the API of the FileIO library. Provides basic functions for interacting with the local user-persisted-and-sandboxed file system. Generally each platform provides a directory or some data store that is persisted just for the current user or app session. For Windows, this is the app's directory under %APPDATA%. For OSX and linux, this is the app's .-prefixed directory under ~/. For JavaScript, this library will create a virtual file system that is persisted over the localStorage object. All operations are virtualized and sandboxed over this directory, treating it as an empty file system.
- namespace UserData
- function currentDirectory()
- function directoryCreate(path, makeParents)
- function directoryDelete(path)
- function directoryExists(path)
- function directoryList(path, includeFullPath)
- function directoryMove(pathFrom, pathTo)
- function fileCopy(pathFrom, pathTo, allowOverwrite)
- function fileDelete(path)
- function fileExists(path)
- function fileMove(pathFrom, pathTo, allowOverwrite)
- function fileReadBytes(path)
- function fileReadLines(path)
- function fileReadText(path)
- function fileWriteBytes(path, bytes)
- function fileWriteText(path, content, encoding)
- function getPathInfo(path)
- function pathExists(path)
- function pathJoin(parts)
function currentDirectory()[link]
Returns the root of the virtualized sandboxed file system. This is actually a hard coded string and returns a '/' every time.
function directoryCreate(path, makeParents)[link]
Creates a new directory
Arguments
Name | Type | Optional | Description |
---|---|---|---|
path | string | an absolute or relative path to create |
|
makeParents | boolean | Optional | true if parent directories should be created if already not present |
function directoryDelete(path)[link]
Deletes a directory
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path of a directory to delete |
function directoryExists(path)[link]
Checks to see if a directory exists.
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path |
Return Value
Type | Description |
---|---|
boolean | True if the path exists and is a directory (not a file). |
function directoryList(path, includeFullPath)[link]
Returns a list of files and subdirectories in a given directory
Arguments
Name | Type | Optional | Description |
---|---|---|---|
path | string | an absolute or relative path |
|
includeFullPath | boolean | Optional | true if absolute file paths should be returned. Otherwise, file names only are returned. |
Return Value
Type | Description |
---|---|
List of strings | list of files |
function directoryMove(pathFrom, pathTo)[link]
Moves a directory and its contents to a new location.
Arguments
Name | Type | Description |
---|---|---|
pathFrom | string | an absolute or relative path of a directory to move |
pathTo | string | an absolute or relative path of a location to move a directory to |
function fileCopy(pathFrom, pathTo, allowOverwrite)[link]
Copies a file to a new location. Optionally allows overwriting files.
Arguments
Name | Type | Optional | Description |
---|---|---|---|
pathFrom | string | an absolute or relative path of the original file location |
|
pathTo | string | an absolute or relative path of the new file location |
|
allowOverwrite | boolean | Optional | true if overwriting existing files is okay |
function fileDelete(path)[link]
Deletes a file from disk
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path |
function fileExists(path)[link]
Checks to see if a file exists.
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path |
Return Value
Type | Description |
---|---|
boolean | True if the path exists and is a file (not a directory). |
function fileMove(pathFrom, pathTo, allowOverwrite)[link]
Moves a file from one location to a new one. Optionally allows overwriting files.
Arguments
Name | Type | Optional | Description |
---|---|---|---|
pathFrom | string | an absolute or relative path of the original file location |
|
pathTo | string | an absolute or relative path of the new file location |
|
allowOverwrite | boolean | Optional | true if overwriting existing files is okay |
function fileReadBytes(path)[link]
Returns a list of bytes in the file. These are unsigned numbers from 0 to 255.
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path |
Return Value
Type | Description |
---|---|
List of integers | List of bytes |
function fileReadLines(path)[link]
Returns a list of lines in the file as a list of strings
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path |
Return Value
Type | Description |
---|---|
List of strings | List of lines in the file |
function fileReadText(path)[link]
Returns the file contents as a string
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path |
Return Value
Type | Description |
---|---|
string | file contents as a string |
function fileWriteBytes(path, bytes)[link]
Writes binary content to a file. Input must be a list of byte values that are either signed or unsigned.
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path |
bytes | List of integers | List of bytes |
function fileWriteText(path, content, encoding)[link]
Writes text to a file
Arguments
Name | Type | Optional | Description |
---|---|---|---|
path | string | an absolute or relative path |
|
content | string | content to write to a file as a string |
|
encoding | FileIO.TextEncoding | Optional | encoding to use |
function getPathInfo(path)[link]
Returns a file descriptor.
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path |
Return Value
Type | Description |
---|---|
FileIOCommon.FileDescriptor | File properties |
function pathExists(path)[link]
Checks to see if a path exists (either a file or a directory).
Arguments
Name | Type | Description |
---|---|---|
path | string | an absolute or relative path |
Return Value
Type | Description |
---|---|
boolean | True if the path exists. |
function pathJoin(parts)[link]
Joins a list of strings with the platform's default path delimiter.
Arguments
Name | Type | Description |
---|---|---|
parts | List of strings | strings to join |