igir
Version:
🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.
179 lines (178 loc) • 6.76 kB
TypeScript
import fs, { MakeDirectoryOptions, ObjectEncodingOptions, PathLike, RmOptions } from 'node:fs';
export declare const MoveResult: {
readonly COPIED: 1;
readonly RENAMED: 2;
};
export type MoveResultKey = keyof typeof MoveResult;
export type MoveResultValue = (typeof MoveResult)[MoveResultKey];
export type FsWalkCallback = (increment: number) => void;
/**
* A collection of static filesystem utility functions.
*/
export default class FsPoly {
private static readonly DRIVES;
/**
* @param dirPath the path to a temporary directory
* @returns if the current runtime can create hardlinks
*/
static canHardlink(dirPath: string): Promise<boolean>;
/**
* @param dirPath the path to a temporary directory
* @returns if the current runtime can create symbolic links
*/
static canSymlink(dirPath: string): Promise<boolean>;
/**
* Copy the contents of {@param src} to {@param dest}, recursively, respecting subdirectories.
*/
static copyDir(src: string, dest: string): Promise<void>;
/**
* Copy {@param src} to {@param dest}, overwriting any existing file, and ensuring {@param dest}
* is writable.
*/
static copyFile(src: string, dest: string, attempt?: number): Promise<void>;
/**
* @returns all the directories in {@param dirPath}, non-recursively
*/
static dirs(dirPath: string): Promise<string[]>;
/**
* @returns the path to the disk that {@param filePath} is on
*/
static diskResolved(filePath: string): string | undefined;
private static disksSync;
/**
* @returns if {@param pathLike} exists, not following symbolic links
*/
static exists(pathLike: PathLike): Promise<boolean>;
/**
* @returns if {@param pathLike} exists, not following symbolic links
*/
static existsSync(pathLike: PathLike): boolean;
/**
* Create a hardlink at location {@param link} to the original file {@param target}.
*/
static hardlink(target: string, link: string): Promise<void>;
/**
* @returns the index node of {@param pathLike}
*/
static inode(pathLike: PathLike): Promise<number>;
/**
* @returns if {@param pathLike} is a directory, following symbolic links
*/
static isDirectory(pathLike: string): Promise<boolean>;
/**
* @returns if {@param pathLike} is a directory, following symbolic links
*/
static isDirectorySync(pathLike: string): boolean;
/**
* @returns if {@param pathLike} can be executed
*/
static isExecutable(pathLike: PathLike): Promise<boolean>;
/**
* @returns if {@param pathLike} has at least one related hardlink
*/
static isHardlink(pathLike: PathLike): Promise<boolean>;
/**
* @returns if {@param filePath} is on a samba path
*/
static isSamba(filePath: string): boolean;
/**
* @returns if {@param pathLike} is a symlink
*/
static isSymlink(pathLike: PathLike): Promise<boolean>;
/**
* @returns if {@param pathLike} is a symlink
*/
static isSymlinkSync(pathLike: PathLike): boolean;
/**
* @returns if the current runtime can write to {@param filePath}
*/
static isWritable(filePath: string): Promise<boolean>;
/**
* @returns a new filepath with all illegal characters removed
*/
static makeLegal(filePath: string, pathSep?: "/" | "\\"): string;
/**
* Makes the directory {@param pathLike} with the options {@param options}.
*/
static mkdir(pathLike: PathLike, options?: MakeDirectoryOptions): Promise<void>;
/**
* mkdtemp() takes a path "prefix" that's concatenated with random characters. Ignore that
* behavior and instead assume we always want to specify a root temp directory.
*/
static mkdtemp(rootDir: string): Promise<string>;
/**
* @returns a path to a temporary file that doesn't exist, without creating that file
*/
static mktemp(prefix: string): Promise<string>;
/**
* Move the file {@param oldPath} to {@param newPath}, retrying failures.
*/
static mv(oldPath: string, newPath: string, attempt?: number): Promise<MoveResultValue>;
private static onDifferentDrives;
/**
* @returns the target path for the symlink {@param pathLike}
*/
static readlink(pathLike: PathLike): Promise<string>;
/**
* @returns the target path for the symlink {@param pathLike}
*/
static readlinkSync(pathLike: PathLike): string;
/**
* @returns the absolute target path for the symlink {@param link}
*/
static readlinkResolved(link: string): Promise<string>;
/**
* @returns the absolute target path for the symlink {@param link}
*/
static readlinkResolvedSync(link: string): string;
/**
* @returns the fully resolved path to {@param pathLike}
*/
static realpath(pathLike: PathLike): Promise<string>;
/**
* Deletes the file or directory {@param pathLike} with the options {@param options}, retrying
* failures.
*/
static rm(pathLike: string, options?: RmOptions): Promise<void>;
/**
* Deletes the file or directory {@param pathLike} with the options {@param options}, retrying
* failures.
*/
static rmSync(pathLike: string, options?: RmOptions): void;
/**
* Note: this will follow symlinks and get the size of the target.
*/
static size(pathLike: PathLike): Promise<number>;
/**
* @see https://gist.github.com/zentala/1e6f72438796d74531803cc3833c039c
*/
static sizeReadable(bytes: number, decimals?: number): string;
/**
* Creates a relative symbolic link at {@param link} to the original file {@link target}
*
* Note: {@param target} should be processed with `path.resolve()` to create absolute path
* symlinks
*/
static symlink(target: PathLike, link: PathLike): Promise<void>;
/**
* Creates a relative symbolic link at {@param link} to the original file {@link target}
*/
static symlinkRelativePath(target: string, link: string): Promise<string>;
/**
* @returns the stats of {@param pathLike}
*/
static stat(pathLike: PathLike): Promise<fs.Stats>;
/**
* Create the file {@link filePath} if it doesn't exist, otherwise update the access and modified
* time to "now".
*/
static touch(filePath: string): Promise<void>;
/**
* Return every file in {@param pathLike}, recursively.
*/
static walk(pathLike: PathLike, callback?: FsWalkCallback): Promise<string[]>;
/**
* Write {@param data} to {@param filePath}.
*/
static writeFile(filePath: PathLike, data: string | Uint8Array, options?: ObjectEncodingOptions): Promise<void>;
}