import type FilenSDK from ".."; import { type FolderMetadata, type FileMetadata, type FileEncryptionVersion, type ProgressCallback, type Prettify } from "../types"; import { type PauseSignal } from "../cloud/signals"; import { type CloudItem } from "../cloud"; export type FSConfig = { sdk: FilenSDK; connectToSocket?: boolean; }; export type FSItemType = "file" | "directory"; export type FSItemBase = { uuid: string; }; export type FSItemFileBase = { region: string; bucket: string; version: FileEncryptionVersion; chunks: number; }; export type FSItemFileMetadata = Prettify; export type FSItem = Prettify<(FSItemBase & { type: "directory"; metadata: FolderMetadata & { timestamp: number; }; }) | (FSItemBase & { type: "file"; metadata: FSItemFileMetadata; })>; export type FSItems = Record; export type FSStatsBase = { size: number; mtimeMs: number; birthtimeMs: number; isDirectory: () => boolean; isFile: () => boolean; }; export type FSStats = Prettify<(FolderMetadata & FSStatsBase & { type: "directory"; uuid: string; }) | (FSItemFileBase & FileMetadata & FSStatsBase & { type: "file"; uuid: string; })>; export type StatFS = { type: number; bsize: number; blocks: number; bfree: number; bavail: number; files: number; ffree: number; used: number; max: number; }; export type FSItemUUID = FSItem & { path: string; }; /** * FS * @date 2/1/2024 - 2:44:47 AM * * @export * @class FS * @typedef {FS} */ export declare class FS { private readonly sdk; _items: FSItems; _uuidToItem: Record; private readonly socket; private readonly mutex; private readonly mkdirMutex; private readonly itemsMutex; constructor(params: FSConfig); /** * Wait for an API key (login) to become available * * @private * @async * @returns {Promise} */ private waitForValidAPIKey; /** * Attach listeners for relevant realtime events. * * @private * @async * @param {?boolean} [connect] * @returns {Promise} */ private _initSocketEvents; /** * Add an item to the internal item tree. * * @public * @async * @param {{ path: string; item: FSItem }} param0 * @param {string} param0.path * @param {(Prettify<(FSItemBase & { type: "directory"; metadata: FolderMetadata; }) | (FSItemBase & { type: "file"; metadata: Prettify; })>)} param0.item * @returns {Promise} */ _addItem({ path, item }: { path: string; item: FSItem; }): Promise; /** * Remove an item from the internal item tree. * * @public * @async * @param {{ path: string }} param0 * @param {string} param0.path * @returns {Promise} */ _removeItem({ path }: { path: string; }): Promise; /** * Normalizes a path to be used with FS. * @date 2/14/2024 - 12:50:52 AM * * @private * @param {{ path: string }} param0 * @param {string} param0.path * @returns {string} */ private normalizePath; pathToItemUUID({ path, type }: { path: string; type?: FSItemType; }): Promise; /** * List files and directories at path. * @date 2/20/2024 - 2:40:03 AM * * @public * @async * @param {{ path: string, recursive?: boolean }} param0 * @param {string} param0.path * @param {boolean} [param0.recursive=false] * @returns {Promise} */ readdir({ path, recursive }: { path: string; recursive?: boolean; }): Promise; /** * Alias of readdir. * @date 2/13/2024 - 8:48:40 PM * * @public * @async * @param {...Parameters} params * @returns {Promise} */ ls(...params: Parameters): Promise; stat({ path }: { path: string; }): Promise; /** * Alias of stat. * @date 2/13/2024 - 8:49:18 PM * * @public * @async * @param {...Parameters} params * @returns {Promise} */ lstat(...params: Parameters): Promise; /** * Creates a directory at path. Recursively creates intermediate directories if they don't exist. * @date 2/14/2024 - 1:34:11 AM * * @public * @async * @param {{ path: string }} param0 * @param {string} param0.path * @returns {Promise} */ mkdir({ path }: { path: string; }): Promise; /** * Rename or move a file/directory. Recursively creates intermediate directories if needed. * @date 2/14/2024 - 1:39:32 AM * * @public * @async * @param {{ from: string; to: string }} param0 * @param {string} param0.from * @param {string} param0.to * @returns {Promise} */ rename({ from, to }: { from: string; to: string; }): Promise; /** * Returns filesystem information. * @date 2/14/2024 - 2:13:19 AM * * @public * @async * @returns {Promise} */ statfs(): Promise; /** * Deletes file/directoy at path. * @date 2/28/2024 - 4:57:19 PM * * @private * @async * @param {{ path: string; type?: FSItemType, permanent?: boolean }} param0 * @param {string} param0.path * @param {FSItemType} param0.type * @param {boolean} [param0.permanent=false] * @returns {Promise} */ private _unlink; /** * Deletes file/directory at path. * @date 2/28/2024 - 4:58:37 PM * * @public * @async * @param {{ path: string, permanent?: boolean }} param0 * @param {string} param0.path * @param {boolean} [param0.permanent=false] * @returns {Promise} */ unlink({ path, permanent }: { path: string; permanent?: boolean; }): Promise; /** * Alias of unlink. * @date 2/28/2024 - 4:58:30 PM * * @public * @async * @param {{ path: string, permanent?: boolean }} param0 * @param {string} param0.path * @param {boolean} [param0.permanent=false] * @returns {Promise} */ rm({ path, permanent }: { path: string; permanent?: boolean; }): Promise; /** * Deletes directory at path. * @date 2/14/2024 - 2:53:48 AM * * @public * @async * @param {...Parameters} params * @returns {Promise} */ rmdir(...params: Parameters): Promise; /** * Deletes a file at path. * * @public * @async * @param {...Parameters} params * @returns {Promise} */ rmfile(...params: Parameters): Promise; /** * Read a file. Returns buffer of given length, at position and offset. Memory efficient to read only a small part of a file. * * @public * @async * @param {{ * path: string * offset?: number * length?: number * position?: number * abortSignal?: AbortSignal * pauseSignal?: PauseSignal * onProgress?: ProgressCallback * onProgressId?: string * }} param0 * @param {string} param0.path * @param {number} param0.offset * @param {number} param0.length * @param {number} param0.position * @param {AbortSignal} param0.abortSignal * @param {PauseSignal} param0.pauseSignal * @param {ProgressCallback} param0.onProgress * @param {string} param0.onProgressId * @returns {Promise} */ read({ path, offset, length, position, abortSignal, pauseSignal, onProgress, onProgressId }: { path: string; offset?: number; length?: number; position?: number; abortSignal?: AbortSignal; pauseSignal?: PauseSignal; onProgress?: ProgressCallback; onProgressId?: string; }): Promise; /** * Alias of writeFile. * @date 2/20/2024 - 9:45:40 PM * * @public * @async * @param {...Parameters} params * @returns {Promise} */ write(...params: Parameters): Promise; /** * Read a file at path. Warning: This reads the whole file into memory and can be pretty inefficient. * * @public * @async * @param {{ * path: string * abortSignal?: AbortSignal * pauseSignal?: PauseSignal * onProgress?: ProgressCallback * onProgressId?: string * }} param0 * @param {string} param0.path * @param {AbortSignal} param0.abortSignal * @param {PauseSignal} param0.pauseSignal * @param {ProgressCallback} param0.onProgress * @param {string} param0.onProgressId * @returns {Promise} */ readFile({ path, abortSignal, pauseSignal, onProgress, onProgressId }: { path: string; abortSignal?: AbortSignal; pauseSignal?: PauseSignal; onProgress?: ProgressCallback; onProgressId?: string; }): Promise; /** * Write to a file. Warning: This reads the whole file into memory and can be very inefficient. Only available in a Node.JS environment. * * @public * @async * @param {{ * path: string * content: Buffer * abortSignal?: AbortSignal * pauseSignal?: PauseSignal * onProgress?: ProgressCallback, * onProgressId?: string * }} param0 * @param {string} param0.path * @param {Buffer} param0.content * @param {AbortSignal} param0.abortSignal * @param {PauseSignal} param0.pauseSignal * @param {ProgressCallback} param0.onProgress * @param {string} param0.onProgressId * @returns {Promise} */ writeFile({ path, content, abortSignal, pauseSignal, onProgress, onProgressId, encryptionKey }: { path: string; content: Buffer; abortSignal?: AbortSignal; pauseSignal?: PauseSignal; onProgress?: ProgressCallback; onProgressId?: string; encryptionKey?: string; }): Promise; /** * Download a file or directory from path to a local destination path. Only available in a Node.JS environment. * * @public * @async * @param {{ * path: string * destination: string * abortSignal?: AbortSignal * pauseSignal?: PauseSignal * onProgress?: ProgressCallback * onProgressId?: string * }} param0 * @param {string} param0.path * @param {string} param0.destination * @param {AbortSignal} param0.abortSignal * @param {PauseSignal} param0.pauseSignal * @param {ProgressCallback} param0.onProgress * @param {string} param0.onProgressId * @returns {Promise} */ download({ path, destination, abortSignal, pauseSignal, onProgress, onProgressId }: { path: string; destination: string; abortSignal?: AbortSignal; pauseSignal?: PauseSignal; onProgress?: ProgressCallback; onProgressId?: string; }): Promise; /** * Upload file or directory to path from a local source path. Recursively creates intermediate directories if needed. Only available in a Node.JS environment. * * @public * @async * @param {{ * path: string * source: string * overwriteDirectory?: boolean * abortSignal?: AbortSignal * pauseSignal?: PauseSignal * onProgress?: ProgressCallback * onProgressId?: string * }} param0 * @param {string} param0.path * @param {string} param0.source * @param {boolean} [param0.overwriteDirectory=false] * @param {AbortSignal} param0.abortSignal * @param {PauseSignal} param0.pauseSignal * @param {ProgressCallback} param0.onProgress * @param {string} param0.onProgressId * @returns {Promise} */ upload({ path, source, overwriteDirectory, abortSignal, pauseSignal, onProgress, onProgressId }: { path: string; source: string; overwriteDirectory?: boolean; abortSignal?: AbortSignal; pauseSignal?: PauseSignal; onProgress?: ProgressCallback; onProgressId?: string; }): Promise; /** * Copy a file or directory structure. Recursively creates intermediate directories if needed. * Warning: Can be really inefficient when copying large directory structures. * All files need to be downloaded first and then reuploaded due to our end to end encryption. * Plain copying unfortunately does not work. Only available in a Node.JS environment. * * @public * @async * @param {{ * from: string * to: string * abortSignal?: AbortSignal * pauseSignal?: PauseSignal * onProgress?: ProgressCallback * onProgressId?: string * }} param0 * @param {string} param0.from * @param {string} param0.to * @param {AbortSignal} param0.abortSignal * @param {PauseSignal} param0.pauseSignal * @param {ProgressCallback} param0.onProgress * @param {string} param0.onProgressId * @returns {Promise} */ cp({ from, to, abortSignal, pauseSignal, onProgress, onProgressId }: { from: string; to: string; abortSignal?: AbortSignal; pauseSignal?: PauseSignal; onProgress?: ProgressCallback; onProgressId?: string; }): Promise; /** * Alias of cp. * @date 2/14/2024 - 5:07:27 AM * * @public * @async * @param {...Parameters} params * @returns {Promise} */ copy(...params: Parameters): Promise; } export default FS;