Class: Filesystem

core.Filesystem

Base class for filesystem implementations.

new core.Filesystem ()

Extends

Classes

FileData

Methods

copy (sourcePath, destPath)Promise

Copies a file. Implementations should override this for remote filesystems.

Name Type Description
sourcePath string

The source path.

destPath string

The destination path.

Returns:
Type Description
Promise The Promise object.

dirname (path)string

Returns the directory part of the given path.

Name Type Description
path string

The path.

Returns:
Type Description
string The directory part of the path.

encodeName (name)string

Encodes the given file name to be used within paths.

Some file systems require file names to be encoded and you must encode file names when composing file system paths. On file systems that do not require encoding, this method simply returns the name unchanged.

Name Type Description
name string

The name to encode.

Returns:
Type Description
string The encoded name.

exists (path)Promise

Checks if the given path exists and returns a boolean Promise object.

Name Type Description
path string

The path to check for.

Returns:
Type Description
Promise The boolean Promise object.

fileInfo (path)Promise

Retrieves a file info object for the given path.

A file info object is a plain dictionary object with several entries describing a file or directory.

For example:

{
    path: "/etc/fstab",       // the full path
    dir: "/etc",              // the path to the parent directory
    name: "fstab",            // the filename
    type: "f",                // either "f" for files or "d" for directories
    size: 120,                // the file size in bytes
    mimetype: "text/plain",   // the MIME type of the file
    ctime: 1690621908,        // the creation time as a Unix timestamp
    mtime: 1690621908         // the modification time as a Unix timestamp
}
Name Type Description
path string

The path.

Returns:
Type Description
Promise The Promise object.

filename (path)string

Returns the file part of the given path.

Name Type Description
path string

The path.

Returns:
Type Description
string The file part of the path.

list (path)Promise

Lists the files at the given path and returns a Promise object with the file items.

Name Type Description
path string

The path to list.

Returns:
Type Description
Promise The Promise object.

makeFileData (dataSource)core.FileData

Returns a FileData object for the given data source.

Name Type Description
dataSource string | ArrayBuffer | ReadableStream | Blob | FileInfo

The data source.

Returns:
Type Description
core.FileData The FileData object.

mkdir (path, name)Promise

Creates a new directory at the given path.

Name Type Description
path string

The path where to create a new directory.

name string

The name of the new directory.

Returns:
Type Description
Promise The Promise object.

mkdirs (path)Promise

Creates a hierarchy of directories.

Name Type Description
path string

The hierarchy of directories to create.

Returns:
Type Description
Promise The Promise object.

move (sourcePath, destPath)Promise

Moves a file.

Name Type Description
sourcePath string

The source path.

destPath string

The destination path.

Returns:
Type Description
Promise The Promise object.

normalizePath (path)string

Normalizes the given path.

Name Type Description
path string

The path to normalize.

Returns:
Type Description
string The normalized path.

pathJoin (args)string

Joins a list of path components.

All path components must be encoded (@see core.Filesystem#encodeName).

Name Type Description
args Array.<string> repeatable

The path components.

Returns:
Type Description
string
  • The resulting path.

read (path, progressCallback)Promise

Reads the file at the given path and returns a Promise object with the Blob.

Name Type Description
path string

The path of the file to read.

progressCallback function

An optional progress callback, if supported by the implementation.

Returns:
Type Description
Promise

remove (path)Promise

Removes the given path.

Name Type Description
path string

The path to remove.

Returns:
Type Description
Promise The Promise object.

Searches for files matching a query and returns a Promise object with the file items. The format of the query string is defined by the particular implementation.

Name Type Description
path string

The path to search.

query string

The search query.

Returns:
Type Description
Promise The Promise object.

write (path, fileData, progressCallback)Promise

Writes the given Blob to the given path.

Name Type Description
path string

The path of the file to write.

fileData core.Filesystem.FileData

The data to write.

progressCallback function

An optional progress callback, if supported by the implementation.

Returns:
Type Description
Promise The Promise object.