zest / filestore.disk
filestore.disk is a filestore component for zest that manages files on disks drives.
Component Methods
The filestore component exposes the below methods for file and directory handling. The parameter names are self-explainatory. For a complete documentation, refer the jsdocs.
create(relativePath, fileData)→PromiseThe 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.
This function returns a Promise that gets resolved when the file or directory is created.
duplicate(originalPath, linkPath, action)→PromiseThis 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.
Action specifies the nature of duplication. It can take the following values
Lif a symlink is to be created at the new pathMif the contents at the old path are to be moved to new pathCif the contents at the old path are to be copied to the new path
This function returns a promise that gets resolved when duplication succeeds.
read(relativePath)→PromiseThis function reads a file or a directory at a path.
It returns a Promise that gets resolved with the following:
- an array of object, each representing one of the 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.
find(dirPath, globPattern)→PromiseThis function searches a directory for files that match a glob Pattern and returns an array of file metadata for all such files.
It returns a Promise that gets resolved with an array of objects, each representing a matched file.
remove(relativePath)→PromiseThis function deletes anything at the given relative path (including its children if the path corresponds to a directory)
It returns a Promise that gets resolved when delete succeeds.
pack(relativePath)→PromiseThis 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
It returns a Promise that gets resolved with the read stream when serialization succeeds.
unpack(relativePath, readStream)→PromiseThe 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.
This function returns a Promise that gets resolved import succeeds.
watch(baseDir, globPattern, eventType, callback)This function registers watcher functions that get called everytime any of the watched files change.
unwatch()This function removes all file watchers registered by the
watchfunctionrouterThis is an express router to expose all filestore functions. This router exposes the below REST apis for handling the filestore
GETapis are used to fetch files. It can be used with the below parameters<<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.<<relative/path/to/base/folder/>>?pack=trueto export a folder into atar.gzfile and download it.<<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.
PUTapis are used to create files and folders<<relative/path/to/base/folder/>>?unpack=trueto import a tar.gz stream sent through the request body into the specified folder. Responds with200 OKwhen successful.<<relative/path/to/base/folder/>>?directory=trueto create a directory at the relative path. Responds with200 OKwhen successful.<<relative/path/to/file>>to create a file with request body as contents. Responds with200 OKwhen successful.
POST<<relative/path/to/base/folder/>>?link=<<new/relative/path>>to create a symlink for the path at the new path. Responds with200 OKwhen successful.<<relative/path/to/base/folder/>>?move=<<new/relative/path>>to move the contents at the path to the new path. Responds with200 OKwhen successful.<<relative/path/to/base/folder/>>?copy=<<new/relative/path>>to copy the contents at the path to the new path. Responds with200 OKwhen successful.
DELETE<<relative/path/to/base/folder/or/file>>to delete the folder or file at the path. Responds with200 OKwhen successful.