Functions for file system.
Methods
-
staticENABLE.file.deletePath(path){Object}
file.js, line 221 -
Deletes a file or directory
Name Type Description pathstring The path of the file or directory to delete
- Since:
- 1.9.0
Returns:
Name Type Description objectObject An object containing the following properties Name Type Description status_codestring The status code of the operation messagestring Optional message providing additional information about the deletion -
staticENABLE.file.download(url, fileName, destination, options){object}
file.js, line 78 -
Downloads a file in the destination directory and renames it to the specified fileName.
If file with the same name exists in destination, it will be overwritten.
Example:const { promise, cancel, getStatus } = ENABLE.file.download( "https://example.com/file.zip", "file.zip", "/storage/downloads", { headers: { Authorization: `Bearer mytesttoken` }, onProgress: (progress) => { console.log(`Download progress: ${progress}%`); } }); promise.then((filePath) => { console.log("File downloaded to:", filePath); }).catch((error) => { console.error("Download failed:", error); });Name Type Description urlstring The URL of the file to download
fileNamestring The desired name for the downloaded file
destinationstring The destination directory where the file will be saved
optionsobject optional Additional options for the download
Name Type Description headersobject optional Optional headers to include in the download request
onProgressfunction optional Optional callback function to handle download progress in percentage, e.g. 40 for 40%
- Since:
- 1.9.0
Returns:
Name Type Description objectobject object containing the member below Name Type Description promisePromise Resolves with download completion or rejects with an error cancelfunction Function to cancel the download getStatusfunction Function to get the current status of the download -
staticENABLE.file.list(path){Object}
file.js, line 245 -
Lists files in a specified directory
Name Type Description pathstring The path to the directory to list files from
- Since:
- 1.9.0
Returns:
Name Type Description objectObject An object containing the following properties Name Type Description status_codestring The status code of the operation filesArray An array of file paths in the specified directory messagestring Optional message providing additional information about the listing -
staticENABLE.file.unzip(zipFilePath, destination){Promise.<string>}
file.js, line 175 -
Unzip a file downloaded previously to a specific directory
Name Type Description zipFilePathstring The path to the zip file to unzip
destinationstring The directory where the contents of the zip file will be extracted
- Since:
- 1.9.0
Returns:
Type Description Promise.<string> A promise that resolves with the destination when the unzip is complete
or rejects with an error if the unzip fails, e.g. zipFilePath does not exist or destination is outside the virtual root.