ZEST / filestore.disk / Namespace: FileStoreFunctions

FileStoreFunctions

The filestore object is returned when filestore gets resolved. This Object has static functions to access the store.

Source:

Members

router

This is an express router to expose all filestore functions. This router exposes the below REST apis for handling the filestore

  1. GET apis are used to fetch files. It can be used with the below parameters

    1. <<relative/path/to/base/folder/>>?find=<<glob pattern>> to find the files matching a glob pattern in a folder. Responds with a JSON array of module:filestore-disk/utils~Stats for each file.

    2. <<relative/path/to/base/folder/>>?pack=true to export a folder into a tar.gz file and download it.

    3. <<relative/path/to/base/folder/or/file>> to stream a file or get the list of files in a folder. Responds with the file contents or Responds with a JSON array of module:filestore-disk/utils~Stats for each file in case the path corresponds to a folder.

  2. PUT apis are used to create files and folders

    1. <<relative/path/to/base/folder/>>?unpack=true to import a tar.gz stream sent through the request body into the specified folder. Responds with 200 OK when successful.

    2. <<relative/path/to/base/folder/>>?directory=true to create a directory at the relative path. Responds with 200 OK when successful.

    3. <<relative/path/to/file>> to create a file with request body as contents. Responds with 200 OK when successful.

  3. POST

    1. <<relative/path/to/base/folder/>>?link=<<new/relative/path>> to create a symlink for the path at the new path. Responds with 200 OK when successful.

    2. <<relative/path/to/base/folder/>>?move=<<new/relative/path>> to move the contents at the path to the new path. Responds with 200 OK when successful.

    3. <<relative/path/to/base/folder/>>?copy=<<new/relative/path>> to copy the contents at the path to the new path. Responds with 200 OK when successful.

  4. DELETE

    1. <<relative/path/to/base/folder/or/file>> to delete the folder or file at the path. Responds with 200 OK when successful.
Source:

Methods

create(relativePath, fileData) → {external:q}

The create function creates (or overrides) a file or a directory at the path specified. if the fileData variable is passed to the function, a file is created. Otherwise, a directory is created. If the parent path at which the file or directory is to be created does not exist, it is also created.

Parameters:
Name Type Argument Description
relativePath String

the path at which the file or directory has to be created

fileData String | external:Buffer | external:Readable <optional>

the file data to be used

Source:
Returns:

A promise that gets resolved when the file or directory is created

Type
external:q

duplicate(oldPath, newPath, action) → {external:q}

This function duplicates the file or folder at oldPath to the newPath. It copies, creates symlinks or moves the file / folder to the new path depending on the parameter passed. If the newPath does not exist, it is created.

Parameters:
Name Type Description
oldPath String

the actual path of the file or directory to duplicate

newPath String

the new path where the file or directory is to be duplicated

action String

action specifies the nature of duplication. It can take the following values

  • L if a symlink is to be created at the new path
  • M if the contents at the old path are to be moved to new path
  • C if the contents at the old path are to be copied to the new path
Source:
See:
Returns:

a promise that gets resolved when duplication succeeds.

Type
external:q

find(dirPath, globPattern) → {external:q}

This function searches a directory for files that match a glob Pattern and returns an array of file metadata for all such files.

Parameters:
Name Type Description
dirPath String

the directory path to search

globPattern String

glob pattern to use for searching

Source:
Returns:

A promise that gets resolved with an array of Stats objects, each representing a matched file.

Type
external:q

pack(relativePath) → {external:q}

This function packs any folder specified by the relativePath and creates a tar.gz stream from it. This stream can be stored or used to copy the folder to another location using unpack

Parameters:
Name Type Description
relativePath String

the path of the directory to pack

Source:
See:
Returns:

a promise that gets resolved with the read stream when serialization succeeds.

Type
external:q

read(relativePath) → {external:q}

This function reads a file or a directory at a path.

Parameters:
Name Type Description
relativePath String

the actual path of the file or directory to read

Source:
Returns:

a promise that gets resolved with the following:

  • an array of Stats object for all child items if the read path is a folder or a symlink to a folder.
  • The actual read stream if the read path is a file or a symlink to a file.
Type
external:q

remove(relativePath) → {external:q}

This function deletes anything at the given relative path (including its children if the path corresponds to a directory)

Parameters:
Name Type Description
relativePath String

the actual path of the file or directory to delete

Source:
Returns:

a promise that gets resolved when delete succeeds.

Type
external:q

unpack(relativePath, readStream) → {external:q}

The unpack function is used to import an exported filestore stream into a folder. The exported filestore stream is essentially a tar.gz of a complete folder hierarchy that is extracted at the relative path.

Parameters:
Name Type Description
relativePath String

the directory path at which the packd output is to be unpacked

readStream external:Readable

the readable stream which is to be unpacked

Source:
See:
Returns:

A promise that gets resolved import succeeds

Type
external:q

unwatch()

This function removes all file watchers registered by the FileStoreFunctions#watch function

Source:
See:

watch(baseDir, globPattern, eventType, callback)

This function registers watcher functions that get called everytime any of the watched files change

Parameters:
Name Type Argument Description
baseDir String

The basedir to watch for file additions and deletions

globPattern String <optional>

the glob pattern is used to filter watched files list in baseDir. If not specified, all files inside baseDir are watched.

eventType String <optional>

eventType, if specified, can be create or remove which will restrict watching only file creations or deletions respectively. If not specified, both creation and deletion will be watched.

callback module:filestore-disk/watch~Callback

the callback function to be called when a watched file is changed, created or removed

Source:
See:

<inner> copy(oldPath, newPath) → {external:q}

This function copies the file or folder at oldPath to the newPath. If the newPath does not exist, it is created.

Parameters:
Name Type Description
oldPath String

the actual path of the file or directory to copy

newPath String

the new path where the file or directory is to be copied

Source:
Returns:

a promise that gets resolved when copy succeeds.

Type
external:q

This function creates a symbolic link at linkPath pointing to the file or directory at original path

Parameters:
Name Type Description
originalPath String

the actual path to link

linkPath String

the location where the new link should be created

Source:
Returns:

a promise that gets resolved when the symbolic link is created

Type
external:q

<inner> move(oldPath, newPath) → {external:q}

This function moves (aka renames) the file or folder at oldPath to the newPath. If the newPath does not exist, it is created.

Parameters:
Name Type Description
oldPath String

the actual path of the file or directory to move

newPath String

the new path where the file or directory is to be moved

Source:
Returns:

a promise that gets resolved when move succeeds.

Type
external:q