/** * Resolves paths to their true (on-disk) casing, caching directory listings * and resolutions so repeated lookups against the same directories don't re-hit * the filesystem. * * Intended to be used in hot paths where the same `from` directories are seen * over and over. * * Does not resolve symbolic links. * * This class caches successful resolutions internally, and may do some * duplicate work when multiple concurrent lookups for the same path are made * before the first one finishes. It does not cache failed resolutions as * negative result entries, but it does cache directory listings, so filesystem * changes may not be observed until `clear()` is called. After `clear()`, * previously cached directory and resolution data is discarded. If profiling * shows that this work duplication is a problem, we can either cache in-flight * operations, or add a mutex. */ export declare class TrueCasePathResolver { #private; /** * Determines the true-case path of a given relative path from a specified * directory, without resolving symbolic links. * * Note that the casing of the `from` path is not checked against the * filesystem, and is trusted as-is. This avoids unnecessary directory * listings for every ancestor of `from`, which can result in permission * errors for directories that are otherwise accessible. * * @param from The absolute path of the directory to start the search from. * @param relativePath The relative path to get the true case of. * @returns The true case of the relative path. Returns an empty string if * relativePath points to from. * @throws FileNotFoundError if the starting directory or the relative path * doesn't exist or is ambiguous. * @throws NotADirectoryError if the starting directory, or an intermediate * segment, is not a directory. * @throws FileSystemAccessError for any other error. */ getFileTrueCase(from: string, relativePath: string): Promise; /** * Clears all cached directory listings and resolutions. */ clear(): void; } /** * Determines the canonical pathname for a given path, resolving any symbolic * links, and returns it. * * @throws FileNotFoundError if absolutePath doesn't exist. * @throws FileSystemAccessError for any other error. */ export declare function getRealPath(absolutePath: string): Promise; /** * Recursively searches a directory and its subdirectories for files that * satisfy the specified condition, returning their absolute paths. * * @param dirFrom The absolute path of the directory to start the search from. * @param matches A function to filter files (not directories). * @param directoryFilter A function to filter which directories to recurse into * @returns An array of absolute paths. Each file has its true case, except * for the initial dirFrom part, which preserves the given casing. * No order is guaranteed. If dirFrom doesn't exist `[]` is returned. * @throws NotADirectoryError if dirFrom is not a directory. * @throws FileSystemAccessError for any other error. */ export declare function getAllFilesMatching(dirFrom: string, matches?: (absolutePathToFile: string) => Promise | boolean, directoryFilter?: (absolutePathToDir: string) => Promise | boolean): Promise; /** * Recursively searches a directory and its subdirectories for directories that * satisfy the specified condition, returning their absolute paths. Once a * directory is found, its subdirectories are not searched. * * Note: dirFrom is never returned, nor is `matches` called on it. * * @param dirFrom The absolute path of the directory to start the search from. * @param matches A function to filter directories (not files). * @returns An array of absolute paths. Each path has its true case, except * for the initial dirFrom part, which preserves the given casing. * No order is guaranteed. If dirFrom doesn't exist `[]` is returned. * @throws NotADirectoryError if dirFrom is not a directory. * @throws FileSystemAccessError for any other error. */ export declare function getAllDirectoriesMatching(dirFrom: string, matches?: (absolutePathToDir: string) => Promise | boolean): Promise; /** * Determines the true case path of a given relative path from a specified * directory, without resolving symbolic links, and returns it. * * @param from The absolute path of the directory to start the search from. * @param relativePath The relative path to get the true case of. * @returns The true case of the relative path. * @throws FileNotFoundError if the starting directory or the relative path doesn't exist. * @throws NotADirectoryError if the starting directory is not a directory. * @throws FileSystemAccessError for any other error. * @deprecated Use {@link TrueCasePathResolver} instead. */ export declare function getFileTrueCase(from: string, relativePath: string): Promise; /** * Checks if a given path is a directory. * * @param absolutePath The path to check. * @returns `true` if the path is a directory, `false` otherwise. * @throws FileNotFoundError if the path doesn't exist. * @throws FileSystemAccessError for any other error. */ export declare function isDirectory(absolutePath: string): Promise; /** * Reads a JSON file and parses it. The encoding used is "utf8". * * @param absolutePathToFile The path to the file. * @returns The parsed JSON object. * @throws FileNotFoundError if the file doesn't exist. * @throws InvalidFileFormatError if the file is not a valid JSON file. * @throws IsDirectoryError if the path is a directory instead of a file. * @throws FileSystemAccessError for any other error. */ export declare function readJsonFile(absolutePathToFile: string): Promise; /** * Reads a JSON file as a stream and parses it. The encoding used is "utf8". * This function should be used when parsing very large JSON files. * * @param absolutePathToFile The path to the file. * @returns The parsed JSON object. * @throws FileNotFoundError if the file doesn't exist. * @throws InvalidFileFormatError if the file is not a valid JSON file. * @throws IsDirectoryError if the path is a directory instead of a file. * @throws FileSystemAccessError for any other error. */ export declare function readJsonFileAsStream(absolutePathToFile: string): Promise; /** * Writes an object to a JSON file. The encoding used is "utf8" and the file is overwritten. * If part of the path doesn't exist, it will be created. * * @param absolutePathToFile The path to the file. If the file exists, it will be overwritten. * @param object The object to write. * @throws JsonSerializationError if the object can't be serialized to JSON. * @throws FileSystemAccessError for any other error. */ export declare function writeJsonFile(absolutePathToFile: string, object: T): Promise; /** * Writes an object to a JSON file as stream. The encoding used is "utf8" and the file is overwritten. * If part of the path doesn't exist, it will be created. * This function should be used when stringifying very large JSON objects. * * @param absolutePathToFile The path to the file. If the file exists, it will be overwritten. * @param object The object to write. * @throws JsonSerializationError if the object can't be serialized to JSON. * @throws FileSystemAccessError for any other error. */ export declare function writeJsonFileAsStream(absolutePathToFile: string, object: T): Promise; /** * Reads a file and returns its content as a string. The encoding used is "utf8". * * @param absolutePathToFile The path to the file. * @returns The content of the file as a string. * @throws FileNotFoundError if the file doesn't exist. * @throws IsDirectoryError if the path is a directory instead of a file. * @throws FileSystemAccessError for any other error. */ export declare function readUtf8File(absolutePathToFile: string): Promise; /** * Writes a string to a file. The encoding used is "utf8" and the file is overwritten by default. * If part of the path doesn't exist, it will be created. * * @param absolutePathToFile The path to the file. * @param data The data to write. * @param flag The flag to use when writing the file. If not provided, the file will be overwritten. * See https://nodejs.org/docs/latest-v20.x/api/fs.html#file-system-flags for more information. * @throws FileAlreadyExistsError if the file already exists and the flag "x" is used. * @throws FileSystemAccessError for any other error. */ export declare function writeUtf8File(absolutePathToFile: string, data: string, flag?: string): Promise; /** * Reads a file and returns its content as a Uint8Array. * * @param absolutePathToFile The path to the file. * @returns The content of the file as a Uint8Array. * @throws FileNotFoundError if the file doesn't exist. * @throws IsDirectoryError if the path is a directory instead of a file. * @throws FileSystemAccessError for any other error. */ export declare function readBinaryFile(absolutePathToFile: string): Promise; /** * Reads a directory and returns its content as an array of strings. * * @param absolutePathToDir The path to the directory. * @returns An array of strings with the names of the files and directories in the directory. * @throws FileNotFoundError if the directory doesn't exist. * @throws NotADirectoryError if the path is not a directory. * @throws FileSystemAccessError for any other error. */ export declare function readdir(absolutePathToDir: string): Promise; /** * Reads a directory and returns its content as an array of strings, returning * an empty array if the directory doesn't exist. * * @param absolutePathToDir The path to the directory. * @returns An array of strings with the names of the files and directories in the directory, and an empty array if the directory doesn't exist. * @throws NotADirectoryError if the path is not a directory. * @throws FileSystemAccessError for any other error. */ export declare function readdirOrEmpty(absolutePathToDir: string): Promise; /** * Creates a directory and any necessary directories along the way. If the directory already exists, * nothing is done. * * @param absolutePath The path to the directory to create. * @throws FileSystemAccessError for any error. */ export declare function mkdir(absolutePath: string): Promise; /** * Alias for `mkdir`. * @see mkdir */ export declare const ensureDir: typeof mkdir; /** * Creates a temporary directory with the specified prefix. * * @param prefix The prefix to use for the temporary directory. * @returns The absolute path to the created temporary directory. * @throws FileSystemAccessError for any error. */ export declare function mkdtemp(prefix: string): Promise; /** * Retrieves the last change time of a file or directory's properties. * This includes changes to the file's metadata or contents. * * @param absolutePath The absolute path to the file or directory. * @returns The time of the last change as a Date object. * @throws FileNotFoundError if the path does not exist. * @throws FileSystemAccessError for any other error. */ export declare function getChangeTime(absolutePath: string): Promise; /** * Retrieves the last access time of a file or directory's properties. * * @param absolutePath The absolute path to the file or directory. * @returns The time of the last access as a Date object. * @throws FileNotFoundError if the path does not exist. * @throws FileSystemAccessError for any other error. */ export declare function getAccessTime(absolutePath: string): Promise; /** * Retrieves the size of a file. * * @param absolutePath The absolute path to the file. * @returns The size of the file in bytes. * @throws FileNotFoundError if the path does not exist. * @throws FileSystemAccessError for any other error. */ export declare function getFileSize(absolutePath: string): Promise; /** * Checks if a file or directory exists. * * @param absolutePath The absolute path to the file or directory. * @param options Optional settings for the existence check. * @param options.followSymlinks If set to `false`, broken symbolic links will be treated as existing. Defaults to `true`. * @returns A boolean indicating whether the file or directory exists. */ export declare function exists(absolutePath: string, options?: { followSymlinks?: boolean; }): Promise; /** * Copies a file from a source to a destination. * If the destination file already exists, it will be overwritten. * * @param source The path to the source file. It can't be a directory. * @param destination The path to the destination file. It can't be a directory. * @throws FileNotFoundError if the source path or the destination path doesn't exist. * @throws IsDirectoryError if the source path or the destination path is a directory. * @throws FileSystemAccessError for any other error. */ export declare function copy(source: string, destination: string): Promise; /** * Moves a file or directory from a source to a destination. If the source is a * file and the destination is a file that already exists, it will be overwritten. * If the source is a directory and the destination is a directory, it needs to be empty. * * Note: This method may not work when moving files between different mount points * or file systems, as the underlying `fsPromises.rename` method may not support it. * * @param source The path to the source file or directory. * @param destination The path to the destination file or directory. * @throws FileNotFoundError if the source path or the destination path doesn't exist. * @throws DirectoryNotEmptyError if the source path is a directory and the destination * path is a directory that is not empty. * @throws FileSystemAccessError for any other error. */ export declare function move(source: string, destination: string): Promise; /** * Creates a symbolic link at `linkPath` that points to `target`. This function * is not meant to be used on Windows. * * @param target The path the symlink points to. May be relative to `linkPath`. * @param linkPath The absolute path of the symlink to create. * @throws FileNotFoundError if the parent directory of `linkPath` doesn't exist. * @throws FileAlreadyExistsError if `linkPath` already exists. * @throws FileSystemAccessError for any other error. */ export declare function symlink(target: string, linkPath: string): Promise; /** * Removes a file or directory recursively. * Exceptions are ignored for non-existent paths. * * @param absolutePath The path to the file or directory to remove. * @throws FileSystemAccessError for any error, except for non-existent path errors. */ export declare function remove(absolutePath: string): Promise; /** * Changes the permissions of a file or directory. * * @param absolutePath The path to the file or directory. * @param mode The permissions to set. It can be a string or a number representing the octal mode. * @throws FileNotFoundError if the path doesn't exist. * @throws FileSystemAccessError for any other error. */ export declare function chmod(absolutePath: string, mode: string | number): Promise; /** * Creates a file with an empty content. If the file already exists, it will be overwritten. * If part of the path doesn't exist, it will be created. * * @param absolutePath The path to the file to create. * @throws FileSystemAccessError for any other error. */ export declare function createFile(absolutePath: string): Promise; /** * Empties a directory by recursively removing all its content. If the * directory doesn't exist, it will be created. The directory itself is * not removed. * * @param absolutePath The path to the directory to empty. * @throws NotADirectoryError if the path is not a directory. * @throws FileSystemAccessError for any other error. */ export declare function emptyDir(absolutePath: string): Promise; /** * Looks for a file in the current directory and its parents. * * @param fileName The name of the file to look for. * @param from The directory to start the search from. Defaults to the current working directory. * @returns The absolute path to the file, or `undefined` if it wasn't found. */ export declare function findUp(fileName: string, from?: string): Promise; /** * This function uses some heuristics to check if a file is binary by reading the first bytesToCheck bytes from the file. */ export declare function isBinaryFile(filePath: string, bytesToCheck?: number): Promise; export { FileNotFoundError, FileSystemAccessError, InvalidFileFormatError, JsonSerializationError, FileAlreadyExistsError, NotADirectoryError, IsDirectoryError, DirectoryNotEmptyError, } from "./errors/fs.js"; //# sourceMappingURL=fs.d.ts.map