Filesystem

The Filesystem API allow to read/write access files residing on the device.

Usage
Filesystem.writeText({
    path: 'anydir/text.txt',
    data: "This is a test",
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(result) {
    console.log('Wrote file', result);
}).catch(function(e) {
    console.error('Unable to write file', e);
});

...

Filesystem.readFile({
    path: 'anydir/text.txt',
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(contents) {
    console.log(contents);
}).catch(function(e) {
    console.error('Error ', e);
});

...

Filesystem.appendFile({
    path: 'anydir/text.txt',
    data: "MORE TESTS",
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(result) {
    console.log('Append to file', result);
}).catch(function(e) {
    console.error('Unable to append file', e);
});

...

Filesystem.deleteFile({
    path: 'anydir/text.txt',
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function() {
    console.log('File deleted');
}).catch(function(e) {
    console.error('Unable to delete file', e);
});

...

Filesystem.mkdir({
    path: 'anydir',
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function() {
    console.log('Directory created');
}).catch(function(e) {
    console.error('Unable to make directory', e);
});

...

Filesystem.rmdir({
    path: 'anydir',
    directory: FawiFilesystem.Directories.LOCAL_STORAGE,
    recursive: false,
}).then(function() {
    console.log('Directory created');
}).catch(function(e) {
    console.error('Unable to remove directory', e);
});

...

Filesystem.readdir({
    path: 'anydir',
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(contents) {
    console.log(contents);
}).catch(function(e) {
    console.error('Error ', e);
});

...

Filesystem.stat({
    path: 'anydir',
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(stats) {
    console.log(stats);
}).catch(function(e) {
    console.error('Error ', e);
});

...

Filesystem.getUri({
    path: 'anydir/file.txt',
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(uri) {
    console.log(uri);
}).catch(function(e) {
    console.error('Error ', e);
});

...

Filesystem.rename({
    from: 'text.txt',
    to: 'text2.txt',
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function() {
    console.log('File renamed');
}).catch(function(e) {
    console.error('Unable to rename file', e);
});

...

Filesystem.copy({
    from: 'text.txt',
    to: 'text2.txt',
    directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function() {
    console.log('File copied');
}).catch(function(e) {
    console.error('Unable to copy file', e);
});
window.Filesystem.mkdir({
    path: "anydir",
    directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
    .then(function () {
        console.log("Directory created");
    })
    .catch(function (e) {
        console.error("Unable to make directory", e);
    });
    
...

window.Filesystem.readdir({
    path: "anydir",
    directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
    .then(function (contents) {
        console.log(contents);
    })
    .catch(function (e) {
        console.error("Error ", e);
    });
window.Filesystem.mkdir({
    path: "anydir",
    directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
    .then(function () {
        console.log("Directory created");
    })
    .catch(function (e) {
        console.error("Unable to make directory", e);
    });
                  
...

window.Filesystem.readdir({
    path: "anydir",
    directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
    .then(function (contents) {
        console.log(contents);
    })
    .catch(function (e) {
        console.error("Error ", e);
    });
(<any>window).Filesystem.mkdir({
    path: "anydir",
    directory: (window).FawiFilesystem.Directories.LOCAL_STORAGE,
})
    .then(() => {
        console.log("Directory created");
    })
    .catch(function (e) {
        console.error("Unable to make directory", e);
    });

...

(<any>window).Filesystem.readdir({
    path: "anydir",
    directory: (window).FawiFilesystem.Directories.LOCAL_STORAGE,
})
    .then(function (contents) {
        console.log(contents);
    })
    .catch(function (e) {
        console.error("Error ", e);
    });
window.Filesystem.mkdir({
    path: "anydir",
    directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
    .then(function () {
        console.log("Directory created");
    })
    .catch(function (e) {
        console.error("Unable to make directory", e);
    });
                
...

window.Filesystem.readdir({
    path: "anydir",
    directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
    .then(function (contents) {
        console.log(contents);
    })
    .catch(function (e) {
        console.error("Error ", e);
    });

Table of Contents

Classes


Filesystem

appendFile

    appendFile(options: FileAppendOptions): Promise<any>

Append to a file on disk in the specified location on device.


PARAMETERS
options: FileAppendOptions options for the file append.

RETURN
returns: Promise <any>
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

copy

    copy(options: CopyOptions): Promise<any>

Copy a file or directory.


PARAMETERS
options: CopyOptions the options for the copy operation.

RETURN
returns: Promise <any>
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

deleteFile

    deleteFile(options: FileDeleteOptions): Promise<any>

Delete a file from disk.


PARAMETERS
options: FileDeleteOptions options for the file delete.

RETURN
returns: Promise <any>
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

getUri

    getUri(options: GetUriOptions): Promise<GetUriResult>

Return full File URI for a path and directory.


PARAMETERS
options: GetUriOptions the options for the stat operation.

RETURN
returns: Promise <GetUriResult> - a promise that resolves with the file stat result.
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

mkdir

    mkdir(options: MkdirOptions): Promise<any>

Create a directory.


PARAMETERS
options: MkdirOptions options for the mkdir.

RETURN
returns: Promise <any>
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

readFile

    readFile(options: FileReadOptions): Promise<FileReadResult>

Read a file from disk.


PARAMETERS
options: FileReadOptions options for the file read.

RETURN
returns: Promise <FileReadResult> - a promise that resolves with the read file data result.
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

readdir

    readdir(options: ReaddirOptions): Promise<ReaddirResult>

Return a list of files from the directory (not recursive).


PARAMETERS
options: ReaddirOptions the options for the rename operation.

RETURN
returns: Promise <ReaddirResult> - a promise that resolves with the rename result.
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

rename

    rename(options: RenameOptions): Promise<any>

Rename a file or directory.


PARAMETERS
options: RenameOptions the options for the readdir operation.

RETURN
returns: Promise <any>
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

rmdir

    rmdir(options: ReaddirOptions): Promise<any>

Remove a directory.


PARAMETERS
options: ReaddirOptions the options for the directory remove.

RETURN
returns: Promise <any>
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

stat

    stat(options: StatOptions): Promise<StatResult>

Return data about a file.


PARAMETERS
options: StatOptions the options for the stat operation.

RETURN
returns: Promise <StatResult> - a promise that resolves with the file stat result.
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

writeFile

    writeFile(options: FileWriteOptions): Promise<FileWriteResult>

Write a file to disk in the specified location on device.


PARAMETERS
options: FileWriteOptions options for the file write.

RETURN
returns: Promise <FileWriteResult> - a promise that resolves with the file write result.
PERMISSIONS

This method requires STORAGE Permission set on Fawi Office - publish settings.

Interfaces

FileAppendOptions
interface FileAppendOptions {
    // The data to write
    data : string;
    // The FilesystemDirectory to store the file in
    directory ?: FilesystemDirectory;
    // The encoding to write the file in. If not provided, data is written as base64 encoded data.
    encoding ?: FilesystemDirectory;
    // The filename to write
    path : string;
}
CopyOptions
interface CopyOptions {
    // The FilesystemDirectory containing the existing file or directory
    directory ?: FilesystemDirectory;
    // The existing file or directory
    from : string;
    // The destination file or directory
    to : string;
    // The FilesystemDirectory containing the destination file or directory. If not supplied will use the 'directory' parameter as the destination
    toDirectory ?: FilesystemDirectory;
}
FileDeleteOptions
interface FileDeleteOptions {
    // The FilesystemDirectory to delete the file from
    directory ?: FilesystemDirectory;
    // The filename to delete
    path : string;
}
GetUriOptions
interface GetUriOptions {
    // The FilesystemDirectory to get the file under
    directory: FilesystemDirectory;
    // The path of the file to get the URI for
    path: string;
}
GetUriResult
interface GetUriResult {
    uri : string;
}
MkdirOptions
interface MkdirOptions {
    // The FilesystemDirectory to make the new directory in
    directory ?: FilesystemDirectory;
   // The path of the new directory
    path : string;
    // Whether to create any missing parent directories as well. Defaults to false
    recursive ?: boolean;
}
FileReadOptions
interface FileReadOptions {
    // The FilesystemDirectory to read the file from
    directory ?: ;
    // The encoding to read the file in, if not provided, data is read as binary and returned as base64 encoded data.
    encoding ?: ;
    // The filename to read
    path : string;
}
FileReadResult
interface FileReadResult {
    data : string;
}
ReaddirOptions
interface ReaddirOptions {
    // The FilesystemDirectory to list files from
    directory ?: FilesystemDirectory;
    // The path of the directory to read
    path : string;
}
ReaddirResult
interface ReaddirResult {
    files : string[];
}
RenameOptions
interface RenameOptions {
    // The FilesystemDirectory containing the existing file or directory
    directory ?: FilesystemDirectory;
    // The existing file or directory
    from : string;
    // The destination file or directory
    to : string;
    // The FilesystemDirectory containing the destination file or directory. If not supplied will use the 'directory' parameter as the destination
    toDirectory ?: FilesystemDirectory;
}
RmdirOptions
interface RmdirOptions {
    // The FilesystemDirectory to remove the directory from
    directory ?: FilesystemDirectory;
    // The path of the directory to remove
    path : string;
    // Whether to recursively remove the contents of the directory Defaults to false
    recursive ?: boolean;
}
StatOptions
interface StatOptions {
    // The FilesystemDirectory to get the file under
    directory ?: FilesystemDirectory;
    // The path of the file to get data about
    path : string;
}
StatResult
interface StatResult {
    ctime : number;
    mtime : number;
    size : number;
    type : string;
    uri : string;
}
FileWriteOptions
interface FileWriteOptions {
    // The data to write
    data : string;
    // The FilesystemDirectory to store the file in
    directory ?: ;
    // The encoding to write the file in. If not provided, data is written as base64 encoded data.
    encoding ?: ;
    // The filename to write
    path : string;
    // Whether to create any missing parent directories. Defaults to false
    recursive ?: boolean;
}
FileWriteResult
interface FileWriteResult {
    uri : string;
}
FilesystemDirectory
enum FilesystemDirectory {
    // The Cache directory
    Cache: "CACHE"
    // The Data directory
    Data: "DATA"
    // The Documents directory
    Documents: "DOCUMENTS"
    // The external directory
    External: "EXTERNAL"
    // The external storage directory
    ExternalStorage: "EXTERNAL_STORAGE"
}

Enumeration

Directories

enum Directories {
    Application: "APPLICATION"
    Cache: "CACHE"
    Data: "DATA"
    Documents: "DOCUMENTS"
    External: "EXTERNAL"
    ExternalStorage: "EXTERNALSTORAGE"
}