dax
Version:
Cross platform shell tools inspired by zx.
170 lines • 7.48 kB
TypeScript
import * as dntShim from "../../../../../_dnt.shims.js";
/** Information about a file or directory. Shape matches `node:fs` `Stats`. */
export interface FileInfo {
/** True if this is info about a regular file. */
isFile(): boolean;
/** True if this is info about a directory. */
isDirectory(): boolean;
/** True if this is info about a symbolic link. */
isSymbolicLink(): boolean;
/** Size of the file in bytes. */
size: number;
/** Last modified time. */
mtime: Date;
/** Last access time. */
atime: Date;
/** Creation time. */
birthtime: Date;
/** Numeric identifier of the device containing the file. */
dev: number;
/** File system specific inode number. */
ino: number;
/** File type and mode. */
mode: number;
/** Number of hard links. */
nlink: number;
/** User ID of the file's owner. */
uid: number;
/** Group ID of the file's owner. */
gid: number;
}
/** A directory entry returned by readDir. Shape matches `node:fs` `Dirent`. */
export interface DirEntryInfo {
/** Name of this entry (not the full path). */
name: string;
/** True if this entry is a regular file. */
isFile(): boolean;
/** True if this entry is a directory. */
isDirectory(): boolean;
/** True if this entry is a symbolic link. */
isSymbolicLink(): boolean;
}
/** Options for `mkdir`. */
export interface MkdirOptions {
/** Create parent directories as needed (like `mkdir -p`). */
recursive?: boolean;
/** Permission mode to apply to newly-created directories. */
mode?: number;
}
/** Options for opening a file. */
export interface OpenOptions {
/** Open for reading. */
read?: boolean;
/** Open for writing. */
write?: boolean;
/** Create the file if it doesn't exist. */
create?: boolean;
/** Create the file, failing if it already exists. */
createNew?: boolean;
/** Open in append mode. */
append?: boolean;
/** Truncate the file to zero length if it already exists. */
truncate?: boolean;
/** Permission mode to apply when creating a file. */
mode?: number;
}
/** Options for writing to a file. */
export interface WriteFileOptions {
/** Append to the file instead of overwriting. */
append?: boolean;
/** Create the file if it doesn't exist. */
create?: boolean;
/** Create the file, failing if it already exists. */
createNew?: boolean;
/** Permission mode to apply when creating a file. */
mode?: number;
/** Abort the write when the signal is triggered. */
signal?: AbortSignal;
}
/** Options for removing a file or directory. */
export interface RemoveOptions {
/** Recursively remove directory contents. */
recursive?: boolean;
}
/** Options for reading a file. */
export interface ReadFileOptions {
/** Abort the read when the signal is triggered. */
signal?: AbortSignal;
}
/** Checks if an error is a "not found" error. */
export declare function isNotFoundError(err: unknown): boolean;
/** Creates a "not found" error. */
export declare function createNotFoundError(message: string): Error;
/** Returns true if running on Windows. */
export declare function isWindows(): boolean;
/** A file handle backed by a Node.js file descriptor. */
export declare class FsFile {
/** @internal */
_fd: number;
/** @internal */
constructor(fd: number);
/** Writes data to the file, resolving to the number of bytes written.
*
* Strings are encoded as UTF-8.
*/
write(data: string | Uint8Array): Promise<number>;
/** Synchronously writes data to the file, returning the number of bytes written.
*
* Strings are encoded as UTF-8.
*/
writeSync(data: string | Uint8Array): number;
/** Reads into `buf`, resolving to the number of bytes read (0 at EOF). */
read(buf: Uint8Array): Promise<number>;
/** Synchronously reads into `buf`, returning the number of bytes read (0 at EOF). */
readSync(buf: Uint8Array): number;
/** Closes the file handle. */
close(): void;
/** A writable stream that writes to this file. */
get writable(): dntShim.WritableStream<Uint8Array>;
/** A readable stream that reads from this file. */
get readable(): dntShim.ReadableStream<Uint8Array>;
}
export declare function stat(path: string): Promise<FileInfo>;
export declare function statSync(path: string): FileInfo;
export declare function lstat(path: string): Promise<FileInfo>;
export declare function lstatSync(path: string): FileInfo;
export declare function realPath(path: string): Promise<string>;
export declare function realPathSync(path: string): string;
export declare function mkdirFn(path: string, options?: MkdirOptions): Promise<void>;
export declare function mkdirSyncFn(path: string, options?: MkdirOptions): void;
export declare function linkFn(oldPath: string, newPath: string): Promise<void>;
export declare function linkSyncFn(oldPath: string, newPath: string): void;
export declare function symlinkFn(target: string, path: string, type?: {
type: "file" | "dir" | "junction";
}): Promise<void>;
export declare function symlinkSyncFn(target: string, path: string, type?: {
type: "file" | "dir" | "junction";
}): void;
export declare function readDir(path: string): AsyncGenerator<DirEntryInfo>;
export declare function readDirSync(path: string): Generator<DirEntryInfo>;
export declare function readFile(path: string, options?: ReadFileOptions): Promise<Uint8Array>;
export declare function readFileSync(path: string): Uint8Array;
export declare function readTextFile(path: string, options?: ReadFileOptions): Promise<string>;
export declare function readTextFileSync(path: string): string;
export declare function chmod(path: string, mode: number): Promise<void>;
export declare function chmodSync(path: string, mode: number): void;
export declare function chown(path: string, uid: number | null, gid: number | null): Promise<void>;
export declare function chownSync(path: string, uid: number | null, gid: number | null): void;
export declare function openFile(path: string, options?: OpenOptions): Promise<FsFile>;
export declare function openFileSync(path: string, options?: OpenOptions): FsFile;
export declare function createFile(path: string): Promise<FsFile>;
export declare function createFileSync(path: string): FsFile;
export declare function remove(path: string, options?: RemoveOptions): Promise<void>;
export declare function removeSync(path: string, options?: RemoveOptions): void;
export declare function copyFileFn(src: string, dest: string): Promise<void>;
export declare function copyFileSyncFn(src: string, dest: string): void;
export declare function renameFn(oldPath: string, newPath: string): Promise<void>;
export declare function renameSyncFn(oldPath: string, newPath: string): void;
export declare function ensureDir(path: string): Promise<void>;
export declare function ensureDirSync(path: string): void;
export declare function ensureFile(path: string): Promise<void>;
export declare function ensureFileSync(path: string): void;
export declare function emptyDir(path: string): Promise<void>;
export declare function emptyDirSync(path: string): void;
export declare function copy(src: string, dest: string, options?: {
overwrite?: boolean;
}): Promise<void>;
export declare function copySync(src: string, dest: string, options?: {
overwrite?: boolean;
}): void;
//# sourceMappingURL=_fs.d.ts.map