/** * @file Abstract, `node:fs/promises`-compatible file system. * * The class is a working implementation on its own: permissions, ownership and * timestamps are stored in an in-memory side table. Backends extend it and * override the `_`-prefixed protected hooks to delegate storage to a real * medium. * * @divergence Every protected hook receives and returns raw values. Encoding, * validation and metadata merging happen in the public methods. */ import { Dirent, Stats } from './stats.mjs'; import { FileHandle } from './handle.mjs'; export type FSDirectoryEntry = import('./stats.mjs').FSDirectoryEntry; export type StatsModule = import('./stats.mjs').Stats; export type FSMetadata = import('./stats.mjs').FSMetadata; export type FSStatDescriptor = import('./stats.mjs').FSStatDescriptor; export type FSIdentity = { /** * Effective user id. */ uid: number; /** * Effective group id. */ gid: number; /** * Supplementary group ids. */ groups: number[]; }; export type FSOptions = { /** * Working directory used to resolve relative paths. */ cwd?: string; /** * Permission mask applied on creation. */ umask?: number; /** * Effective identity used by `access`. */ identity?: FSIdentity; }; export type FSCapabilities = { permissions: boolean; ownership: boolean; symlinks: boolean; timestamps: boolean; atomicRename: boolean; seekableHandles: boolean; }; export type TReadFileOptions = { /** * When omitted or `null`, a `Uint8Array` is returned. */ encoding?: string | null; }; export type TWriteFileOptions = { /** * Encoding used to serialise string input. */ encoding?: string | null; /** * When `true`, the payload is appended. */ append?: boolean; /** * Permission bits applied when the file is created. */ mode?: number; }; export type TReaddirOptions = { /** * When `true`, resolves to `Dirent[]`. */ withFileTypes?: boolean; /** * When `true`, walks sub-directories depth-first. */ recursive?: boolean; }; export type TMkdirOptions = { /** * When `true`, missing parents are created. */ recursive?: boolean; /** * Permission bits applied to the new directory. */ mode?: number; }; export type TRmOptions = { /** * When `true`, removes directories and their contents. */ recursive?: boolean; /** * When `true`, a missing path is not an error. */ force?: boolean; }; export type TStatOptions = { /** * When `false`, resolves to `undefined` instead of throwing. */ throwIfNoEntry?: boolean; }; export type TCopyFileOptions = { /** * Bitmask of `constants.COPYFILE_*` flags. */ mode?: number; }; /** * Abstract, `node:fs/promises`-compatible file system. * @beta */ declare class TinyFSCore { #private; /** * @param {FSOptions} [options] Construction options. */ constructor(options?: FSOptions); /** * @returns {FSCapabilities} The capabilities advertised by the backend. */ static get capabilities(): FSCapabilities; /** @returns {string} Working directory used to resolve relative paths. */ get cwd(): string; /** @returns {number} Permission mask applied on creation. */ get umask(): number; /** @returns {FSIdentity} Effective identity used by `access`. */ get identity(): FSIdentity; /** * @protected * @param {string} targetPath Absolute path of the file. * @returns {Promise} The raw file contents. */ protected _readFile(targetPath: string): Promise; /** * @protected * @param {string} targetPath Absolute path of the file. * @param {Uint8Array} bytes Payload to persist. * @param {TWriteFileOptions} options Write options. * @returns {Promise} Resolves once the payload is committed. */ protected _writeFile(targetPath: string, bytes: Uint8Array, options: TWriteFileOptions): Promise; /** * @protected * @param {string} targetPath Absolute path of the directory. * @returns {Promise} The directory entries. */ protected _readdir(targetPath: string): Promise; /** * @protected * @param {string} targetPath Absolute path of the directory. * @param {TMkdirOptions} options Creation options. * @returns {Promise} Resolves once the directory exists. */ protected _mkdir(targetPath: string, options: TMkdirOptions): Promise; /** * @protected * @param {string} targetPath Absolute path of the entry. * @param {TRmOptions} options Removal options. * @returns {Promise} Resolves once the entry is gone. */ protected _rm(targetPath: string, options: TRmOptions): Promise; /** * @protected * @param {string} targetPath Absolute path of the entry. * @returns {Promise} The raw descriptor, or `undefined`. */ protected _stat(targetPath: string): Promise; /** * @protected * @param {string} oldPath Current absolute path. * @param {string} newPath Target absolute path. * @returns {Promise} Resolves once the move is complete. */ protected _rename(oldPath: string, newPath: string): Promise; /** * @protected * @param {string} sourcePath Absolute path of the source file. * @param {string} destinationPath Absolute path of the destination file. * @param {number} mode Bitmask of `constants.COPYFILE_*` flags. * @returns {Promise} Resolves once the copy is complete. */ protected _copyFile(sourcePath: string, destinationPath: string, mode: number): Promise; /** * @protected * @param {string} targetPath Absolute path of the entry. * @returns {Promise} The stored metadata. */ protected _readMetadata(targetPath: string): Promise; /** * @protected * @param {string} targetPath Absolute path of the entry. * @param {FSMetadata} metadata Metadata to persist. * @returns {Promise} Resolves once the metadata is committed. */ protected _writeMetadata(targetPath: string, metadata: FSMetadata): Promise; /** * Reads the entire contents of a file. * * @param {string} path Absolute path of the file. * @param {TReadFileOptions} [options] Read options. * @returns {Promise} The file contents. */ readFile(path: string, options?: TReadFileOptions): Promise; /** * Writes data to a file, replacing it when it already exists. * * @param {string} path Absolute path of the file. * @param {string | Uint8Array | ArrayBuffer} data Payload to persist. * @param {TWriteFileOptions} [options] Write options. * @returns {Promise} Resolves once the payload is committed. */ writeFile(path: string, data: string | Uint8Array | ArrayBuffer, options?: TWriteFileOptions): Promise; /** * Appends data to a file, creating it when missing. * * @param {string} path Absolute path of the file. * @param {string | Uint8Array | ArrayBuffer} data Payload to append. * @param {TWriteFileOptions} [options] Write options. * @returns {Promise} Resolves once the payload is committed. */ appendFile(path: string, data: string | Uint8Array | ArrayBuffer, options?: TWriteFileOptions): Promise; /** * Reads the contents of a directory. * * @param {string} path Absolute path of the directory. * @param {TReaddirOptions} [options] Read options. * @returns {Promise>} The entry names, or `Dirent` objects. */ readdir(path: string, options?: TReaddirOptions): Promise>; /** * Creates a directory. * * @param {string} path Absolute path of the directory. * @param {TMkdirOptions} [options] Creation options. * @returns {Promise} The created path when `recursive` is `true`. */ mkdir(path: string, options?: TMkdirOptions): Promise; /** * Removes a file or, when `recursive` is `true`, a directory tree. * * @param {string} path Absolute path of the entry. * @param {TRmOptions} [options] Removal options. * @returns {Promise} Resolves once the entry is gone. */ rm(path: string, options?: TRmOptions): Promise; /** * Removes a file. * * @param {string} path Absolute path of the file. * @returns {Promise} Resolves once the file is gone. */ unlink(path: string): Promise; /** * Removes a directory. * * @param {string} path Absolute path of the directory. * @param {TRmOptions} [options] Removal options. * @returns {Promise} Resolves once the directory is gone. */ rmdir(path: string, options?: TRmOptions): Promise; /** * Renames or moves a file or directory. * * @param {string} oldPath Current absolute path. * @param {string} newPath Target absolute path. * @returns {Promise} Resolves once the move is complete. */ rename(oldPath: string, newPath: string): Promise; /** * Copies a file. * * @param {string} sourcePath Absolute path of the source file. * @param {string} destinationPath Absolute path of the destination file. * @param {number | TCopyFileOptions} [mode] Bitmask of `constants.COPYFILE_*` flags. * @returns {Promise} Resolves once the copy is complete. */ copyFile(sourcePath: string, destinationPath: string, mode?: number | TCopyFileOptions): Promise; /** * Retrieves metadata about a file or directory. * * @param {string} path Absolute path of the entry. * @param {TStatOptions} [options] Stat options. * @returns {Promise} The metadata snapshot. */ __stat(path: string, options?: TStatOptions): Promise; /** * Retrieves metadata about a file or directory. * * @param {string} path Absolute path of the entry. * @param {TStatOptions} [options] Stat options. * @returns {Promise} The metadata snapshot. */ stat(path: string, options?: TStatOptions): Promise; /** * Alias of `stat`. The base class has no symbolic links. * * @param {string} path Absolute path of the entry. * @param {TStatOptions} [options] Stat options. * @returns {Promise} The metadata snapshot. */ lstat(path: string, options?: TStatOptions): Promise; /** * Checks whether a path is reachable. * * @param {string} path Absolute path of the entry. * @param {number} [mode] Bitmask of `constants.F_OK`, `R_OK`, `W_OK` and `X_OK`. * @returns {Promise} Resolves when the path is reachable. * @throws {Error} With `code: 'EACCES'` when the permission is missing. */ access(path: string, mode?: number): Promise; /** * Changes the permission bits of an entry. * * @param {string} path Absolute path of the entry. * @param {number} mode New permission bits. * @returns {Promise} Resolves once the mode is committed. */ chmod(path: string, mode: number): Promise; /** * Changes the owner of an entry. * * @param {string} path Absolute path of the entry. * @param {number} uid New owner user id. * @param {number} [gid] New owner group id. Defaults to `uid`. * @returns {Promise} Resolves once the ownership is committed. */ chown(path: string, uid: number, gid?: number): Promise; /** * Updates the access and modification times of an entry. * * @param {string} path Absolute path of the entry. * @param {number} atimeMs New access time in milliseconds since the epoch. * @param {number} [mtimeMs] New modification time. Defaults to `atimeMs`. * @returns {Promise} Resolves once the timestamps are committed. */ utimes(path: string, atimeMs: number, mtimeMs?: number): Promise; /** * Truncates a file to the given length. * * @param {string} path Absolute path of the file. * @param {number} [length] Target length in bytes. * @returns {Promise} Resolves once the file is truncated. */ truncate(path: string, length?: number): Promise; /** * Resolves the canonical absolute path. * * @param {string} path Absolute path of the entry. * @returns {Promise} The normalised absolute path. */ realpath(path: string): Promise; /** * Opens a file and returns a handle. * * @param {string} path Absolute path of the file. * @param {string} [flags] Access mode, e.g. `'r'`, `'w'`, `'a'`. * @returns {Promise} The opened handle. */ open(path: string, flags?: string): Promise; /** * Reports whether a path exists. * * @param {string} path Absolute path of the entry. * @returns {Promise} `true` when the entry exists. */ exists(path: string): Promise; } export default TinyFSCore; //# sourceMappingURL=index.d.mts.map