Defines functions to interact with the file system as an extension to the Node.js filesystem module.
- Source:
Example
// Load module "fileSystem"
var fsApi = require('@openveo/api').fileSystem;
Members
(static, constant) ACTIONS :Object
The list of available actions for performActions.
Type:
- Object
- Default Value:
{"REMOVE":"remove","COPY":"copy"}
- Source:
(static, constant) FILE_SIGNATURES :Object
The list of file types.
Type:
- Object
- Source:
(static, constant) FILE_TYPES :Object
The list of file types.
Type:
- Object
- Default Value:
{"JPG":"jpg","PNG":"png","GIF":"gif","TAR":"tar","MP4":"mp4","BMP":"bmp","ZIP":"zip","UNKNOWN":"unknown"}
- Source:
Methods
(static) copy(sourcePath, destinationSourcePath, callback)
Copies a file or a directory.
Parameters:
Name | Type | Description |
---|---|---|
sourcePath |
String | Path of the source to copy |
destinationSourcePath |
String | Final path of the source |
callback |
callback | The function to call when done |
- Source:
(static) extract(filePath, destinationPath, callbackopt)
Extracts an archive to the given directory.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
filePath |
String | Path of the archive to extract |
|
destinationPath |
String | Path of the directory where to extract files |
|
callback |
callback |
<optional> |
The function to call when done |
- Source:
(static) getConfDir() → {String}
Gets OpenVeo configuration directory path.
OpenVeo configuration is stored in user home directory.
- Source:
Returns:
OpenVeo configuration directory path
- Type
- String
(static) getFileType(filePath, callback)
Gets file type.
Parameters:
Name | Type | Description |
---|---|---|
filePath |
String | The path of the file to get type from |
callback |
module:fileSystem~getFileTypeCallback | The function to call when done |
- Source:
(static) getFileTypeFromBuffer(file) → {String}
Gets file type from Buffer.
Parameters:
Name | Type | Description |
---|---|---|
file |
Buffer | At least the first 300 bytes of the file |
- Source:
Returns:
The file type
- Type
- String
(static) getJSONFileContent(filePath, callback)
Gets a JSON file content.
This will verify that the file exists first.
Parameters:
Name | Type | Description |
---|---|---|
filePath |
String | The path of the file to read |
callback |
module:fileSystem~getJSONFileContentCallback | The function to call when done |
- Source:
Throws:
-
An error if callback is not speficied
- Type
- TypeError
(static) mkdir(directoryPath, callbackopt)
Creates a directory.
If parent directory does not exist, it will be automatically created. If directory already exists, it won't do anything.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
directoryPath |
String | The directory system path to create |
|
callback |
callback |
<optional> |
The function to call when done |
- Source:
(static) performActions(actions, callback)
Performs all given copy / remove actions.
All actions are executed in parallel. Make sure one action does not depend on another.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
actions |
Array | The actions to perform Properties
|
||||||||||||||||
callback |
callback | The function to call when done |
- Source:
(static) prepend(filePath, data, callbackopt)
Prepends given data to file.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
filePath |
String | The system path of the file to add data to |
|
data |
String | Data to add to the beginning of the file |
|
callback |
callback |
<optional> |
The function to call when done |
- Source:
(static) readdir(directoryPath, callback)
Gets the content of a directory recursively and asynchronously.
Parameters:
Name | Type | Description |
---|---|---|
directoryPath |
String | Path of the directory |
callback |
module:fileSystem~readdirCallback | The function to call when done |
- Source:
(static) readFile(filePath, offsetopt, lengthopt, callback)
Gets part of a file as bytes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
filePath |
String | Path of the file |
|
offset |
Number |
<optional> |
Specify where to begin reading from in the file |
length |
Number |
<optional> |
The number of bytes ro read |
callback |
module:fileSystem~readFileCallback | The function to call when done |
- Source:
(static) replace(filePath, substitutions, callbackopt)
Replaces strings matching a pattern inside a file.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
filePath |
String | The system path of the file to parse |
||||||||||
substitutions |
Array | The list of substitutions Properties
|
||||||||||
callback |
callback |
<optional> |
The function to call when done |
- Source:
(static) rm(resourcePath, keepDirectoryopt, callbackopt)
Removes a resource.
If resource is a directory, the whole directory is removed.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
resourcePath |
String | Path of the resource to remove |
||
keepDirectory |
Boolean |
<optional> |
false | true to keep the directory in case the resource is a directory, false to also remove the directory |
callback |
callback |
<optional> |
The function to call when done |
- Source:
(static) rmdir(directoryPath, keepDirectoryopt, callbackopt)
Removes a directory and all its content recursively and asynchronously.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
directoryPath |
String | Path of the directory to remove |
||
keepDirectory |
Boolean |
<optional> |
false | true to keep the directory, false to also remove the directory |
callback |
callback |
<optional> |
The function to call when done |
- Deprecated:
- Use rm instead
- Source:
(private, inner) copyFile(sourceFilePath, destinationFilePath, callback)
Copies a file.
If directory does not exist it will be automatically created.
Parameters:
Name | Type | Description |
---|---|---|
sourceFilePath |
String | Path of the file |
destinationFilePath |
String | Final path of the file |
callback |
callback | The function to call when done |
- Source:
(private, inner) extractTarFile(filePath, destinationPath, callbackopt)
Extracts a tar file.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
filePath |
String | Path of the tar file to extract |
|
destinationPath |
String | Path of the directory where to extract files automatically |
|
callback |
callback |
<optional> |
The function to call when done |
- Source:
(private, inner) extractZipFile(filePath, destinationPath, callbackopt)
Extracts a zip file.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
filePath |
String | Path of the zip file to extract |
|
destinationPath |
String | Path of the directory where to extract files automatically |
|
callback |
callback |
<optional> |
The function to call when done |
- Source:
(private, inner) mkdirRecursive(directoryPath, callback)
Creates a directory recursively and asynchronously.
If parent directories do not exist, they will be automatically created.
Parameters:
Name | Type | Description |
---|---|---|
directoryPath |
String | The directory system path to create |
callback |
callback | The function to call when done |
- Source:
(private, inner) readdirRecursive(directoryPath, callback)
Reads a directory content recursively and asynchronously.
It is assumed that the directory exists.
Parameters:
Name | Type | Description |
---|---|---|
directoryPath |
String | Path of the directory |
callback |
module:fileSystem~readdirRecursiveCallback | The function to call when done |
- Source:
(private, inner) rmdirRecursive(directoryPath, keepDirectory, callback)
Removes a directory and all its content recursively and asynchronously.
It is assumed that the directory exists.
Parameters:
Name | Type | Description |
---|---|---|
directoryPath |
String | Path of the directory to remove |
keepDirectory |
Boolean | true to keep the directory in case the resource is a directory, false to also remove the directory |
callback |
callback | The function to call when done |
- Source:
Type Definitions
getFileTypeCallback(error, type)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
type |
String | The |
- Source:
getJSONFileContentCallback(error, content)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
content |
String | null | The file content or null if an error occurred |
- Source:
readdirCallback(error, resources)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
resources |
Array | Undefined | The list of resources insides the directory |
- Source:
readdirRecursiveCallback(error, stats)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
stats |
Array | The list of fs.Stats corresponding to resources inside the directory (files and directories) |
- Source:
readFileCallback(error, buffer)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
buffer |
Buffer | Undefined | The buffer containing read bytes |
- Source: