UNPKG

13.8 kBTypeScriptView Raw
1// Type definitions for fs-extra
2// Project: https://github.com/jprichardson/node-fs-extra
3// Definitions by: midknight41 <https://github.com/midknight41>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6// Imported from: https://github.com/soywiz/typescript-node-definitions/fs-extra.d.ts
7
8///<reference types="node"/>
9
10
11import stream = require("stream");
12
13export interface Stats {
14 isFile(): boolean;
15 isDirectory(): boolean;
16 isBlockDevice(): boolean;
17 isCharacterDevice(): boolean;
18 isSymbolicLink(): boolean;
19 isFIFO(): boolean;
20 isSocket(): boolean;
21 dev: number;
22 ino: number;
23 mode: number;
24 nlink: number;
25 uid: number;
26 gid: number;
27 rdev: number;
28 size: number;
29 blksize: number;
30 blocks: number;
31 atime: Date;
32 mtime: Date;
33 ctime: Date;
34}
35
36export interface FSWatcher {
37 close(): void;
38}
39
40export declare class ReadStream extends stream.Readable { }
41export declare class WriteStream extends stream.Writable { }
42
43//extended methods
44export declare function copy(src: string, dest: string, callback?: (err: Error) => void): void;
45export declare function copy(src: string, dest: string, filter: CopyFilter, callback?: (err: Error) => void): void;
46export declare function copy(src: string, dest: string, options: CopyOptions, callback?: (err: Error) => void): void;
47
48export declare function copySync(src: string, dest: string): void;
49export declare function copySync(src: string, dest: string, filter: CopyFilter): void;
50export declare function copySync(src: string, dest: string, options: CopyOptions): void;
51
52export declare function createFile(file: string, callback?: (err: Error) => void): void;
53export declare function createFileSync(file: string): void;
54
55export declare function mkdirs(dir: string, callback?: (err: Error) => void): void;
56export declare function mkdirp(dir: string, callback?: (err: Error) => void): void;
57export declare function mkdirs(dir: string, options?: MkdirOptions, callback?: (err: Error) => void): void;
58export declare function mkdirp(dir: string, options?: MkdirOptions, callback?: (err: Error) => void): void;
59export declare function mkdirsSync(dir: string, options?: MkdirOptions): void;
60export declare function mkdirpSync(dir: string, options?: MkdirOptions): void;
61
62export declare function outputFile(file: string, data: any, callback?: (err: Error) => void): void;
63export declare function outputFileSync(file: string, data: any): void;
64
65export declare function outputJson(file: string, data: any, callback?: (err: Error) => void): void;
66export declare function outputJSON(file: string, data: any, callback?: (err: Error) => void): void;
67export declare function outputJsonSync(file: string, data: any): void;
68export declare function outputJSONSync(file: string, data: any): void;
69
70export declare function readJson(file: string, callback: (err: Error, jsonObject: any) => void): void;
71export declare function readJson(file: string, options: OpenOptions, callback: (err: Error, jsonObject: any) => void): void;
72export declare function readJSON(file: string, callback: (err: Error, jsonObject: any) => void): void;
73export declare function readJSON(file: string, options: OpenOptions, callback: (err: Error, jsonObject: any) => void): void;
74
75export declare function readJsonSync(file: string, options?: OpenOptions): any;
76export declare function readJSONSync(file: string, options?: OpenOptions): any;
77
78export declare function remove(dir: string, callback?: (err: Error) => void): void;
79export declare function removeSync(dir: string): void;
80// export function delete(dir: string, callback?: (err: Error) => void): void;
81// export function deleteSync(dir: string): void;
82
83export declare function writeJson(file: string, object: any, callback?: (err: Error) => void): void;
84export declare function writeJson(file: string, object: any, options?: OpenOptions, callback?: (err: Error) => void): void;
85export declare function writeJSON(file: string, object: any, callback?: (err: Error) => void): void;
86export declare function writeJSON(file: string, object: any, options?: OpenOptions, callback?: (err: Error) => void): void;
87
88export declare function writeJsonSync(file: string, object: any, options?: OpenOptions): void;
89export declare function writeJSONSync(file: string, object: any, options?: OpenOptions): void;
90
91export declare function rename(oldPath: string, newPath: string, callback?: (err: Error) => void): void;
92export declare function renameSync(oldPath: string, newPath: string): void;
93export declare function truncate(fd: number, len: number, callback?: (err: Error) => void): void;
94export declare function truncateSync(fd: number, len: number): void;
95export declare function chown(path: string, uid: number, gid: number, callback?: (err: Error) => void): void;
96export declare function chownSync(path: string, uid: number, gid: number): void;
97export declare function fchown(fd: number, uid: number, gid: number, callback?: (err: Error) => void): void;
98export declare function fchownSync(fd: number, uid: number, gid: number): void;
99export declare function lchown(path: string, uid: number, gid: number, callback?: (err: Error) => void): void;
100export declare function lchownSync(path: string, uid: number, gid: number): void;
101export declare function chmod(path: string, mode: number, callback?: (err: Error) => void): void;
102export declare function chmod(path: string, mode: string, callback?: (err: Error) => void): void;
103export declare function chmodSync(path: string, mode: number): void;
104export declare function chmodSync(path: string, mode: string): void;
105export declare function fchmod(fd: number, mode: number, callback?: (err: Error) => void): void;
106export declare function fchmod(fd: number, mode: string, callback?: (err: Error) => void): void;
107export declare function fchmodSync(fd: number, mode: number): void;
108export declare function fchmodSync(fd: number, mode: string): void;
109export declare function lchmod(path: string, mode: string, callback?: (err: Error) => void): void;
110export declare function lchmod(path: string, mode: number, callback?: (err: Error) => void): void;
111export declare function lchmodSync(path: string, mode: number): void;
112export declare function lchmodSync(path: string, mode: string): void;
113export declare function stat(path: string, callback?: (err: Error, stats: Stats) => void): void;
114export declare function lstat(path: string, callback?: (err: Error, stats: Stats) => void): void;
115export declare function fstat(fd: number, callback?: (err: Error, stats: Stats) => void): void;
116export declare function statSync(path: string): Stats;
117export declare function lstatSync(path: string): Stats;
118export declare function fstatSync(fd: number): Stats;
119export declare function link(srcpath: string, dstpath: string, callback?: (err: Error) => void): void;
120export declare function linkSync(srcpath: string, dstpath: string): void;
121export declare function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err: Error) => void): void;
122export declare function symlinkSync(srcpath: string, dstpath: string, type?: string): void;
123export declare function readlink(path: string, callback?: (err: Error, linkString: string) => void): void;
124export declare function realpath(path: string, callback?: (err: Error, resolvedPath: string) => void): void;
125export declare function realpath(path: string, cache: string, callback: (err: Error, resolvedPath: string) => void): void;
126export declare function realpathSync(path: string, cache?: boolean): string;
127export declare function unlink(path: string, callback?: (err: Error) => void): void;
128export declare function unlinkSync(path: string): void;
129export declare function rmdir(path: string, callback?: (err: Error) => void): void;
130export declare function rmdirSync(path: string): void;
131export declare function mkdir(path: string, mode?: number, callback?: (err: Error) => void): void;
132export declare function mkdir(path: string, mode?: string, callback?: (err: Error) => void): void;
133export declare function mkdirSync(path: string, mode?: number): void;
134export declare function mkdirSync(path: string, mode?: string): void;
135export declare function readdir(path: string, callback?: (err: Error, files: string[]) => void): void;
136export declare function readdirSync(path: string): string[];
137export declare function close(fd: number, callback?: (err: Error) => void): void;
138export declare function closeSync(fd: number): void;
139export declare function open(path: string, flags: string, mode?: string, callback?: (err: Error, fs: number) => void): void;
140export declare function openSync(path: string, flags: string, mode?: string): number;
141export declare function utimes(path: string, atime: number, mtime: number, callback?: (err: Error) => void): void;
142export declare function utimesSync(path: string, atime: number, mtime: number): void;
143export declare function futimes(fd: number, atime: number, mtime: number, callback?: (err: Error) => void): void;
144export declare function futimesSync(fd: number, atime: number, mtime: number): void;
145export declare function fsync(fd: number, callback?: (err: Error) => void): void;
146export declare function fsyncSync(fd: number): void;
147export declare function write(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number, callback?: (err: Error, written: number, buffer: NodeBuffer) => void): void;
148export declare function writeSync(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number): number;
149export declare function read(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number, callback?: (err: Error, bytesRead: number, buffer: NodeBuffer) => void): void;
150export declare function readSync(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number): number;
151export declare function readFile(filename: string, encoding: string, callback: (err: Error, data: string) => void): void;
152export declare function readFile(filename: string, options: OpenOptions, callback: (err: Error, data: string) => void): void;
153export declare function readFile(filename: string, callback: (err: Error, data: NodeBuffer) => void): void;
154export declare function readFileSync(filename: string): NodeBuffer;
155export declare function readFileSync(filename: string, encoding: string): string;
156export declare function readFileSync(filename: string, options: OpenOptions): string;
157export declare function writeFile(filename: string, data: any, encoding?: string, callback?: (err: Error) => void): void;
158export declare function writeFile(filename: string, data: any, options?: OpenOptions, callback?: (err: Error) => void): void;
159export declare function writeFileSync(filename: string, data: any, encoding?: string): void;
160export declare function writeFileSync(filename: string, data: any, option?: OpenOptions): void;
161export declare function appendFile(filename: string, data: any, encoding?: string, callback?: (err: Error) => void): void;
162export declare function appendFile(filename: string, data: any, option?: OpenOptions, callback?: (err: Error) => void): void;
163export declare function appendFileSync(filename: string, data: any, encoding?: string): void;
164export declare function appendFileSync(filename: string, data: any, option?: OpenOptions): void;
165export declare function watchFile(filename: string, listener: { curr: Stats; prev: Stats; }): void;
166export declare function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: { curr: Stats; prev: Stats; }): void;
167export declare function unwatchFile(filename: string, listener?: Stats): void;
168export declare function watch(filename: string, options?: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher;
169export declare function exists(path: string, callback?: (exists: boolean) => void): void;
170export declare function existsSync(path: string): boolean;
171export declare function ensureDir(path: string, cb: (err: Error) => void): void;
172export declare function ensureDirSync(path: string): void;
173export declare function ensureFile(path: string, cb: (err: Error) => void): void;
174export declare function ensureFileSync(path: string): void;
175export declare function ensureLink(path: string, cb: (err: Error) => void): void;
176export declare function ensureLinkSync(path: string): void;
177export declare function ensureSymlink(path: string, cb: (err: Error) => void): void;
178export declare function ensureSymlinkSync(path: string): void;
179export declare function emptyDir(path: string, callback?: (err: Error) => void): void;
180export declare function emptyDirSync(path: string): boolean;
181
182export interface CopyFilterFunction {
183 (src: string): boolean
184}
185
186export type CopyFilter = CopyFilterFunction | RegExp;
187
188export interface CopyOptions {
189 clobber?: boolean
190 preserveTimestamps?: boolean
191 filter?: CopyFilter
192}
193
194export interface OpenOptions {
195 encoding?: string;
196 flag?: string;
197}
198
199export interface MkdirOptions {
200 fs?: any;
201 mode?: number;
202}
203
204export interface ReadStreamOptions {
205 flags?: string;
206 encoding?: string;
207 fd?: number;
208 mode?: number;
209 bufferSize?: number;
210}
211export interface WriteStreamOptions {
212 flags?: string;
213 encoding?: string;
214 string?: string;
215}
216export declare function createReadStream(path: string, options?: ReadStreamOptions): ReadStream;
217export declare function createWriteStream(path: string, options?: WriteStreamOptions): WriteStream;
218export declare function createOutputStream(path: string, options?: WriteStreamOptions): WriteStream;