Namespace: file

ENABLE. file

Functions for file system.

Methods

staticENABLE.file.deletePath(path){Object}

file.js, line 221

Deletes a file or directory

Name Type Description
path string

The path of the file or directory to delete

Since:
  • 1.9.0
Returns:
Name Type Description
object Object An object containing the following properties
Name Type Description
status_code string The status code of the operation
message string 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
url string

The URL of the file to download

fileName string

The desired name for the downloaded file

destination string

The destination directory where the file will be saved

options object optional

Additional options for the download

Name Type Description
headers object optional

Optional headers to include in the download request

onProgress function optional

Optional callback function to handle download progress in percentage, e.g. 40 for 40%

Since:
  • 1.9.0
Returns:
Name Type Description
object object object containing the member below
Name Type Description
promise Promise Resolves with download completion or rejects with an error
cancel function Function to cancel the download
getStatus function 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
path string

The path to the directory to list files from

Since:
  • 1.9.0
Returns:
Name Type Description
object Object An object containing the following properties
Name Type Description
status_code string The status code of the operation
files Array An array of file paths in the specified directory
message string 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
zipFilePath string

The path to the zip file to unzip

destination string

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.