// Type definitions for fs-extra 9.0 // Project: https://github.com/jprichardson/node-fs-extra // Definitions by: Alan Agius , // midknight41 , // Brendan Forster , // Mees van Dijk , // Justin Rockwood , // Sang Dang , // Florian Keller // Piotr Błażejewicz // Tiger Oakes // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// import * as fs from "fs"; import Stats = fs.Stats; import PathLike = fs.PathLike; export * from "fs"; export function copy(src: string, dest: string, options?: CopyOptions): Promise; export function copy(src: string, dest: string, callback: (err: Error) => void): void; export function copy(src: string, dest: string, options: CopyOptions, callback: (err: Error) => void): void; export function copySync(src: string, dest: string, options?: CopyOptionsSync): void; export function copyFile(src: string, dest: string, flags?: number): Promise; export function copyFile(src: string, dest: string, callback: (err: Error) => void): void; export function copyFile(src: string, dest: string, flags: number, callback: (err: Error) => void): void; export function move(src: string, dest: string, options?: MoveOptions): Promise; export function move(src: string, dest: string, callback: (err: Error) => void): void; export function move(src: string, dest: string, options: MoveOptions, callback: (err: Error) => void): void; export function moveSync(src: string, dest: string, options?: MoveOptions): void; export function createFile(file: string): Promise; export function createFile(file: string, callback: (err: Error) => void): void; export function createFileSync(file: string): void; export function createSymlink(src: string, dest: string, type: SymlinkType): Promise; export function createSymlink(src: string, dest: string, type: SymlinkType, callback?: (err: Error) => void): void; export function createSymlinkSync(src: string, dest: string, type: SymlinkType): void; export function ensureDir(path: string, options?: EnsureOptions | number): Promise; export function ensureDir(path: string, options?: EnsureOptions | number, callback?: (err: Error) => void): void; export function ensureDirSync(path: string, options?: EnsureOptions | number): void; export function mkdirs(dir: string): Promise; export function mkdirs(dir: string, callback: (err: Error) => void): void; export function mkdirp(dir: string): Promise; export function mkdirp(dir: string, callback: (err: Error) => void): void; export function mkdirsSync(dir: string): void; export function mkdirpSync(dir: string): void; export function outputFile(file: string, data: any, options?: WriteFileOptions | string): Promise; export function outputFile(file: string, data: any, callback: (err: Error) => void): void; export function outputFile(file: string, data: any, options: WriteFileOptions | string, callback: (err: Error) => void): void; export function outputFileSync(file: string, data: any, options?: WriteFileOptions | string): void; export function readJson(file: string, options?: ReadOptions): Promise; export function readJson(file: string, callback: (err: Error, jsonObject: any) => void): void; export function readJson(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void; export function readJSON(file: string, options?: ReadOptions): Promise; export function readJSON(file: string, callback: (err: Error, jsonObject: any) => void): void; export function readJSON(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void; export function readJsonSync(file: string, options?: ReadOptions): any; export function readJSONSync(file: string, options?: ReadOptions): any; export function remove(dir: string): Promise; export function remove(dir: string, callback: (err: Error) => void): void; export function removeSync(dir: string): void; export function outputJSON(file: string, data: any, options?: WriteOptions): Promise; export function outputJSON(file: string, data: any, options: WriteOptions, callback: (err: Error) => void): void; export function outputJSON(file: string, data: any, callback: (err: Error) => void): void; export function outputJson(file: string, data: any, options?: WriteOptions): Promise; export function outputJson(file: string, data: any, options: WriteOptions, callback: (err: Error) => void): void; export function outputJson(file: string, data: any, callback: (err: Error) => void): void; export function outputJsonSync(file: string, data: any, options?: WriteOptions): void; export function outputJSONSync(file: string, data: any, options?: WriteOptions): void; export function writeJSON(file: string, object: any, options?: WriteOptions): Promise; export function writeJSON(file: string, object: any, callback: (err: Error) => void): void; export function writeJSON(file: string, object: any, options: WriteOptions, callback: (err: Error) => void): void; export function writeJson(file: string, object: any, options?: WriteOptions): Promise; export function writeJson(file: string, object: any, callback: (err: Error) => void): void; export function writeJson(file: string, object: any, options: WriteOptions, callback: (err: Error) => void): void; export function writeJsonSync(file: string, object: any, options?: WriteOptions): void; export function writeJSONSync(file: string, object: any, options?: WriteOptions): void; export function ensureFile(path: string): Promise; export function ensureFile(path: string, callback: (err: Error) => void): void; export function ensureFileSync(path: string): void; export function ensureLink(src: string, dest: string): Promise; export function ensureLink(src: string, dest: string, callback: (err: Error) => void): void; // alias for ensureLink export const createLink: typeof ensureLink; export function ensureLinkSync(src: string, dest: string): void; // aliased as export const createLinkSync: typeof ensureLinkSync; export function ensureSymlink(src: string, dest: string, type?: SymlinkType): Promise; export function ensureSymlink(src: string, dest: string, type: SymlinkType, callback: (err: Error) => void): void; export function ensureSymlink(src: string, dest: string, callback: (err: Error) => void): void; export function ensureSymlinkSync(src: string, dest: string, type?: SymlinkType): void; export function emptyDir(path: string): Promise; export function emptyDir(path: string, callback: (err: Error) => void): void; export const emptydir: typeof emptyDir; export function emptyDirSync(path: string): void; export const emptydirSync: typeof emptyDirSync; export function pathExists(path: string): Promise; export function pathExists(path: string, callback: (err: Error, exists: boolean) => void): void; export function pathExistsSync(path: string): boolean; // fs async methods // copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v6/index.d.ts export function access(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void; export function access(path: PathLike, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; export function access(path: PathLike, mode?: number): Promise; export function appendFile(file: PathLike | number, data: any, options: { encoding?: string; mode?: number | string; flag?: string; }, callback: (err: NodeJS.ErrnoException) => void): void; export function appendFile(file: PathLike | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void; export function appendFile(file: PathLike | number, data: any, options?: { encoding?: string; mode?: number | string; flag?: string; }): Promise; export function chmod(path: PathLike, mode: Mode, callback: (err: NodeJS.ErrnoException) => void): void; export function chmod(path: PathLike, mode: Mode): Promise; export function chown(path: PathLike, uid: number, gid: number): Promise; export function chown(path: PathLike, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void; export function close(fd: number, callback: (err: NodeJS.ErrnoException) => void): void; export function close(fd: number): Promise; export function fchmod(fd: number, mode: Mode, callback: (err: NodeJS.ErrnoException) => void): void; export function fchmod(fd: number, mode: Mode): Promise; export function fchown(fd: number, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void; export function fchown(fd: number, uid: number, gid: number): Promise; export function fdatasync(fd: number, callback: () => void): void; export function fdatasync(fd: number): Promise; export function fstat(fd: number, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void; export function fstat(fd: number): Promise; export function fsync(fd: number, callback: (err: NodeJS.ErrnoException) => void): void; export function fsync(fd: number): Promise; export function ftruncate(fd: number, callback: (err: NodeJS.ErrnoException) => void): void; export function ftruncate(fd: number, len: number, callback: (err: NodeJS.ErrnoException) => void): void; export function ftruncate(fd: number, len?: number): Promise; export function futimes(fd: number, atime: number, mtime: number, callback: (err: NodeJS.ErrnoException) => void): void; export function futimes(fd: number, atime: Date, mtime: Date, callback: (err: NodeJS.ErrnoException) => void): void; export function futimes(fd: number, atime: number, mtime: number): Promise; export function futimes(fd: number, atime: Date, mtime: Date): Promise; export function lchown(path: PathLike, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void; export function lchown(path: PathLike, uid: number, gid: number): Promise; export function link(existingPath: PathLike, newPath: PathLike, callback: (err: NodeJS.ErrnoException) => void): void; export function link(existingPath: PathLike, newPath: PathLike): Promise; export function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void; export function lstat(path: PathLike): Promise; /** * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. * * @param callback No arguments other than a possible exception are given to the completion callback. */ export function mkdir(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void; /** * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. * * @param callback No arguments other than a possible exception are given to the completion callback. */ export function mkdir(path: PathLike, options: Mode | fs.MakeDirectoryOptions | null, callback: (err: NodeJS.ErrnoException) => void): void; export function mkdir(path: PathLike, options?: Mode | fs.MakeDirectoryOptions | null): Promise; export function mkdirSync(path: PathLike, options?: Mode | fs.MakeDirectoryOptions | null): void; export function open(path: PathLike, flags: string | number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void; export function open(path: PathLike, flags: string | number, mode: Mode, callback: (err: NodeJS.ErrnoException, fd: number) => void): void; export function open(path: PathLike, flags: string | number, mode?: Mode | null): Promise; export function opendir(path: string, cb: (err: NodeJS.ErrnoException | null, dir: fs.Dir) => void): void; export function opendir( path: string, options: fs.OpenDirOptions, cb: (err: NodeJS.ErrnoException | null, dir: fs.Dir) => void, ): void; export function opendir(path: string, options?: fs.OpenDirOptions): Promise; export function read(fd: number, buffer: TBuffer, offset: number, length: number, position: number | null, callback: (err: NodeJS.ErrnoException, bytesRead: number, buffer: TBuffer) => void): void; export function read(fd: number, buffer: TBuffer, offset: number, length: number, position: number | null): Promise<{ bytesRead: number, buffer: TBuffer }>; export function readFile(file: PathLike | number, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; export function readFile(file: PathLike | number, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; export function readFile(file: PathLike | number, options: { flag?: string; } | { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; export function readFile(file: PathLike | number, options: { flag?: string; } | { encoding: string; flag?: string; }): Promise; // tslint:disable-next-line:unified-signatures export function readFile(file: PathLike | number, encoding: string): Promise; export function readFile(file: PathLike | number): Promise; export function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void; export function readdir(path: PathLike, options?: { encoding: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | null): Promise; export function readdir(path: PathLike, options: "buffer" | { encoding: "buffer"; withFileTypes?: false }): Promise; export function readdir(path: PathLike, options?: { encoding?: string | null; withFileTypes?: false }): Promise; export function readdir(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Promise; export function readlink(path: PathLike, callback: (err: NodeJS.ErrnoException, linkString: string) => any): void; export function readlink(path: PathLike): Promise; export function realpath(path: PathLike, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; export function realpath(path: PathLike, cache: { [path: string]: string }, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; export function realpath(path: PathLike, cache?: { [path: string]: string }): Promise; export function rename(oldPath: PathLike, newPath: PathLike, callback: (err: NodeJS.ErrnoException) => void): void; export function rename(oldPath: PathLike, newPath: PathLike): Promise; /** * Asynchronous rmdir - removes the directory specified in {path} * * @param callback No arguments other than a possible exception are given to the completion callback. */ export function rmdir(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void; export function rmdir(path: PathLike): Promise; export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void; export function stat(path: PathLike): Promise; export function symlink(target: PathLike, path: PathLike, type: SymlinkType | undefined, callback: (err: NodeJS.ErrnoException) => void): void; export function symlink(target: PathLike, path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void; export function symlink(target: PathLike, path: PathLike, type?: SymlinkType): Promise; export function truncate(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void; export function truncate(path: PathLike, len: number, callback: (err: NodeJS.ErrnoException) => void): void; export function truncate(path: PathLike, len?: number): Promise; /** * Asynchronous unlink - deletes the file specified in {path} * * @param callback No arguments other than a possible exception are given to the completion callback. */ export function unlink(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void; export function unlink(path: PathLike): Promise; export function utimes(path: PathLike, atime: number, mtime: number, callback: (err: NodeJS.ErrnoException) => void): void; export function utimes(path: PathLike, atime: Date, mtime: Date, callback: (err: NodeJS.ErrnoException) => void): void; export function utimes(path: PathLike, atime: number, mtime: number): Promise; export function utimes(path: PathLike, atime: Date, mtime: Date): Promise; export function write( fd: number, buffer: TBuffer, offset: number, length: number, position: number | null, callback: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void ): void; export function write( fd: number, buffer: TBuffer, offset: number, length: number, callback: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void ): void; export function write(fd: number, data: any, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; export function write(fd: number, data: any, offset: number, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; export function write(fd: number, data: any, offset: number, encoding: string, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; export function write(fd: number, buffer: TBuffer, offset?: number, length?: number, position?: number | null): Promise<{ bytesWritten: number, buffer: TBuffer }>; export function write(fd: number, data: any, offset?: number, encoding?: string): Promise<{ bytesWritten: number, buffer: string }>; export function writeFile(file: PathLike | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void; export function writeFile(file: PathLike | number, data: any, options?: WriteFileOptions | string): Promise; export function writeFile(file: PathLike | number, data: any, options: WriteFileOptions | string, callback: (err: NodeJS.ErrnoException) => void): void; export function writev(fd: number, buffers: NodeJS.ArrayBufferView[], position: number, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void; export function writev(fd: number, buffers: NodeJS.ArrayBufferView[], cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void; export function writev(fd: number, buffers: NodeJS.ArrayBufferView[], position?: number): Promise; /** * Asynchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * * @param callback The created folder path is passed as a string to the callback's second parameter. */ export function mkdtemp(prefix: string): Promise; export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException, folder: string) => void): void; export interface PathEntry { path: string; stats: Stats; } export interface PathEntryStream { read(): PathEntry | null; } export type CopyFilterSync = (src: string, dest: string) => boolean; export type CopyFilterAsync = (src: string, dest: string) => Promise; export type SymlinkType = "dir" | "file" | "junction"; export type Mode = string | number; export type ArrayBufferView = NodeJS.TypedArray | DataView; export interface CopyOptions { dereference?: boolean; overwrite?: boolean; preserveTimestamps?: boolean; errorOnExist?: boolean; filter?: CopyFilterSync | CopyFilterAsync; recursive?: boolean; } export interface CopyOptionsSync extends CopyOptions { filter?: CopyFilterSync; } export interface EnsureOptions { mode?: number; } export interface MoveOptions { overwrite?: boolean; limit?: number; } export interface ReadOptions { throws?: boolean; fs?: object; reviver?: any; encoding?: string; flag?: string; } export interface WriteFileOptions { encoding?: string | null; flag?: string; mode?: number; } export interface WriteOptions extends WriteFileOptions { fs?: object; replacer?: any; spaces?: number | string; EOL?: string; } export interface WritevResult { bytesWritten: number; buffers: ArrayBufferView[]; }