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
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.
- 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 relativePathString the path at which the file or directory has to be created
fileDataString | 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 oldPathString the actual path of the file or directory to duplicate
newPathString the new path where the file or directory is to be duplicated
actionString 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
- 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 dirPathString the directory path to search
globPatternString 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 relativePathString 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 relativePathString 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 relativePathString 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 relativePathString the directory path at which the packd output is to be unpacked
readStreamexternal: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 baseDirString The basedir to watch for file additions and deletions
globPatternString <optional>
the glob pattern is used to filter watched files list in baseDir. If not specified, all files inside baseDir are watched.
eventTypeString <optional>
eventType, if specified, can be
createorremovewhich will restrict watching only file creations or deletions respectively. If not specified, both creation and deletion will be watched.callbackmodule: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 oldPathString the actual path of the file or directory to copy
newPathString 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
-
<inner> link(originalPath, linkPath) → {external:q}
-
This function creates a symbolic link at linkPath pointing to the file or directory at original path
Parameters:
Name Type Description originalPathString the actual path to link
linkPathString 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 oldPathString the actual path of the file or directory to move
newPathString 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