UNPKG

axiodb

Version:

The Pure JavaScript Alternative to SQLite. Embedded NoSQL database for Node.js with MongoDB-style queries, zero native dependencies, built-in InMemoryCache, and web GUI. Perfect for desktop apps, CLI tools, and embedded systems. No compilation, no platfor

101 lines (100 loc) 4.96 kB
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface"; export default class FileManager { private readonly responseHelper; private readonly WorkerProcess; constructor(); /** * Writes data to a file at the specified path. * * @param path - The path where the file will be written. * @param data - The data to be written to the file. * @returns A promise that resolves to a SuccessInterface if the file is written successfully, * or an ErrorInterface if an error occurs. */ WriteFile(path: string, data: string): Promise<SuccessInterface | ErrorInterface>; /** * Reads the content of a file at the specified path. * * @param path - The path to the file to be read. * @returns A promise that resolves to a SuccessInterface containing the file data if the read operation is successful, * or an ErrorInterface if an error occurs. */ ReadFile(path: string): Promise<SuccessInterface | ErrorInterface>; /** * Deletes a file at the specified path. * * @param {string} path - The path to the file to be deleted. * @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a SuccessInterface if the file is deleted successfully, or an ErrorInterface if an error occurs. */ DeleteFile(path: string): Promise<SuccessInterface | ErrorInterface>; /** * Checks if a file exists at the given path. * * @param path - The path to the file. * @returns A promise that resolves to a SuccessInterface if the file exists, * or an ErrorInterface if the file does not exist. */ FileExists(path: string): Promise<SuccessInterface | ErrorInterface>; /** * Creates a new file at the specified path. * * @param path - The path where the new file will be created. * @returns A promise that resolves to a SuccessInterface if the file is created successfully, * or an ErrorInterface if there is an error during file creation. */ CreateFile(path: string): Promise<SuccessInterface | ErrorInterface>; /** * Locks the specified file by changing its permissions to read-only. * * @param path - The path to the file to be locked. * @returns A promise that resolves to a SuccessInterface if the file is locked successfully, * or an ErrorInterface if an error occurs. */ LockFile(path: string): Promise<SuccessInterface | ErrorInterface>; /** * Unlocks the file at the specified path by changing its permissions to 777. * * @param {string} path - The path to the file to be unlocked. * @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a SuccessInterface if the file is unlocked successfully, or an ErrorInterface if an error occurs. */ UnlockFile(path: string): Promise<SuccessInterface | ErrorInterface>; /** * Moves a file from the specified old path to the new path. * * @param oldPath - The current path of the file to be moved. * @param newPath - The destination path where the file should be moved. * @returns A promise that resolves to a SuccessInterface if the file is moved successfully, * or an ErrorInterface if an error occurs during the file move operation. */ MoveFile(oldPath: string, newPath: string): Promise<SuccessInterface | ErrorInterface>; /** * Checks if the file at the given path is locked. * * A file is considered locked if its permissions are set to read-only for the owner (mode 0o400). * * @param path - The path to the file to check. * @returns A promise that resolves to a SuccessInterface if the file is locked, or an ErrorInterface if an error occurs. */ IsFileLocked(path: string): Promise<SuccessInterface | ErrorInterface>; /** * Retrieves the size of a file in bytes. * * @param path - The path to the file. * @returns A promise that resolves to a SuccessInterface containing the file size in bytes, * or an ErrorInterface if an error occurs. */ GetFileSize(path: string): Promise<SuccessInterface | ErrorInterface>; /** * Safely deletes a file with directory lock management. * * This method handles file deletion with proper directory lock/unlock sequences: * - If directory is unlocked: deletes file directly * - If directory is locked: unlocks, deletes file, then relocks directory * * @param collectionPath - The path to the collection directory * @param fileName - The name of the file to delete * @returns A promise that resolves to a SuccessInterface if the file is deleted successfully, * or an ErrorInterface if an error occurs during the deletion process. */ DeleteFileWithLock(collectionPath: string, fileName: string): Promise<SuccessInterface | ErrorInterface>; }