narraleaf
Version:
Create your visual novel with Electron and React
67 lines (66 loc) • 2.6 kB
TypeScript
export type FsResult<T, OK extends true | false = true | false> = OK extends true ? {
ok: true;
data: T;
} : {
ok: false;
error: string;
};
export type FileStat = {
name: string;
ext: string;
};
export declare class Fs {
static read(path: string, encoding?: BufferEncoding): Promise<FsResult<string>>;
static readRaw(path: string): Promise<FsResult<Buffer>>;
static write(path: string, data: string, encoding?: BufferEncoding): Promise<FsResult<void>>;
static writeRaw(path: string, data: Buffer): Promise<FsResult<void>>;
static append(path: string, data: string, encoding?: BufferEncoding): Promise<FsResult<void>>;
static createDir(path: string): Promise<FsResult<string | undefined>>;
static isFileExists(path: string): Promise<FsResult<void>>;
static appendSync(path: string, data: string, encoding?: BufferEncoding): FsResult<void>;
static isDirExists(path: string): Promise<FsResult<void>>;
static copyDir(src: string, destDir: string): Promise<FsResult<void>>;
static cpFile(src: string, destFile: string): Promise<FsResult<void>>;
static getFiles(dir: string, ext?: string | string[]): Promise<FsResult<string[]>>;
static listFiles(dir: string): Promise<FsResult<FileStat[]>>;
static deleteFile(path: string): Promise<FsResult<void>>;
private static errorToString;
private static wrap;
private static wrapSync;
}
export declare class ProjectFs {
readonly root: string;
constructor(root: string);
read(path: string, encoding?: BufferEncoding): Promise<FsResult<string>>;
/**
* Tries to read a file from the list of paths
*
* Returns the first path that exists
*/
tryRead(paths: string | string[], encoding?: BufferEncoding): Promise<FsResult<string>>;
/**
* Tries to access a file or a directory from the list of paths
*
* Returns the first path that exists
*/
tryAccessDir(pathsRaw: string | string[]): Promise<FsResult<string>>;
/**
* Tries to access a file from the list of paths
*
* Returns the first path that exists
*/
tryAccessFile(pathsRaw: string | string[]): Promise<FsResult<string>>;
/**
* This method will fail if the file doesn't exist
*/
isDirExists(path: string): Promise<FsResult<void>>;
/**
* This method will fail if the file doesn't exist
*/
isFileExists(path: string): Promise<FsResult<void>>;
resolve(p: string): string;
isProjectFile(p: string): boolean;
isRelative(p: string): boolean;
private retry;
private toRetryStack;
}