volume.d.ts
17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { PathLike, symlink } from 'fs';
import { Node, Link, File } from './node';
import Stats from './Stats';
import Dirent from './Dirent';
import { TSetTimeout } from './setTimeoutUnref';
import { Readable, Writable } from 'stream';
import { constants } from './constants';
import { EventEmitter } from 'events';
import { TEncodingExtended, TDataOut } from './encoding';
export interface IError extends Error {
code?: string;
}
export declare type TFileId = PathLike | number;
export declare type TData = TDataOut | Uint8Array;
export declare type TFlags = string | number;
export declare type TMode = string | number;
export declare type TTime = number | string | Date;
export declare type TCallback<TData> = (error?: IError | null, data?: TData) => void;
export declare enum FLAGS {
r,
'r+',
rs,
sr,
'rs+',
'sr+',
w,
wx,
xw,
'w+',
'wx+',
'xw+',
a,
ax,
xa,
'a+',
'ax+',
'xa+'
}
export declare type TFlagsCopy = typeof constants.COPYFILE_EXCL | typeof constants.COPYFILE_FICLONE | typeof constants.COPYFILE_FICLONE_FORCE;
export declare function flagsToNumber(flags: TFlags | undefined): number;
export interface IOptions {
encoding?: BufferEncoding | TEncodingExtended;
}
export interface IFileOptions extends IOptions {
mode?: TMode;
flag?: TFlags;
}
export interface IReadFileOptions extends IOptions {
flag?: string;
}
export interface IWriteFileOptions extends IFileOptions {
}
export interface IAppendFileOptions extends IFileOptions {
}
export interface IRealpathOptions {
encoding?: TEncodingExtended;
}
export interface IWatchFileOptions {
persistent?: boolean;
interval?: number;
}
export interface IReadStreamOptions {
flags?: TFlags;
encoding?: BufferEncoding;
fd?: number;
mode?: TMode;
autoClose?: boolean;
start?: number;
end?: number;
}
export interface IWriteStreamOptions {
flags?: TFlags;
defaultEncoding?: BufferEncoding;
fd?: number;
mode?: TMode;
autoClose?: boolean;
start?: number;
}
export interface IWatchOptions extends IOptions {
persistent?: boolean;
recursive?: boolean;
}
export interface IMkdirOptions {
mode?: TMode;
recursive?: boolean;
}
export interface IRmdirOptions {
recursive?: boolean;
}
export interface IRmOptions {
force?: boolean;
maxRetries?: number;
recursive?: boolean;
retryDelay?: number;
}
export interface IReaddirOptions extends IOptions {
withFileTypes?: boolean;
}
export interface IStatOptions {
bigint?: boolean;
throwIfNoEntry?: boolean;
}
export interface IFStatOptions {
bigint?: boolean;
}
export declare function pathToFilename(path: PathLike): string;
export declare function filenameToSteps(filename: string, base?: string): string[];
export declare function pathToSteps(path: PathLike): string[];
export declare function dataToStr(data: TData, encoding?: string): string;
export declare function dataToBuffer(data: TData, encoding?: string): Buffer;
export declare function bufferToEncoding(buffer: Buffer, encoding?: TEncodingExtended): TDataOut;
export declare function toUnixTimestamp(time: any): any;
declare type DirectoryContent = string | null;
export interface DirectoryJSON {
[key: string]: DirectoryContent;
}
export interface NestedDirectoryJSON {
[key: string]: DirectoryContent | NestedDirectoryJSON;
}
/**
* `Volume` represents a file system.
*/
export declare class Volume {
static fromJSON(json: DirectoryJSON, cwd?: string): Volume;
static fromNestedJSON(json: NestedDirectoryJSON, cwd?: string): Volume;
/**
* Global file descriptor counter. UNIX file descriptors start from 0 and go sequentially
* up, so here, in order not to conflict with them, we choose some big number and descrease
* the file descriptor of every new opened file.
* @type {number}
* @todo This should not be static, right?
*/
static fd: number;
root: Link;
ino: number;
inodes: {
[ino: number]: Node;
};
releasedInos: number[];
fds: {
[fd: number]: File;
};
releasedFds: number[];
maxFiles: number;
openFiles: number;
StatWatcher: new () => StatWatcher;
ReadStream: new (...args: any[]) => IReadStream;
WriteStream: new (...args: any[]) => IWriteStream;
FSWatcher: new () => FSWatcher;
props: {
Node: new (...args: any[]) => Node;
Link: new (...args: any[]) => Link;
File: new (...args: any[]) => File;
};
private promisesApi;
get promises(): import("./promises").IPromisesAPI;
constructor(props?: {});
createLink(): Link;
createLink(parent: Link, name: string, isDirectory?: boolean, perm?: number): Link;
deleteLink(link: Link): boolean;
private newInoNumber;
private newFdNumber;
createNode(isDirectory?: boolean, perm?: number): Node;
private getNode;
private deleteNode;
genRndStr(): any;
getLink(steps: string[]): Link | null;
getLinkOrThrow(filename: string, funcName?: string): Link;
getResolvedLink(filenameOrSteps: string | string[]): Link | null;
getResolvedLinkOrThrow(filename: string, funcName?: string): Link;
resolveSymlinks(link: Link): Link | null;
private getLinkAsDirOrThrow;
private getLinkParent;
private getLinkParentAsDirOrThrow;
private getFileByFd;
private getFileByFdOrThrow;
/**
* @todo This is not used anymore. Remove.
*/
private wrapAsync;
private _toJSON;
toJSON(paths?: PathLike | PathLike[], json?: {}, isRelative?: boolean): DirectoryJSON;
fromJSON(json: DirectoryJSON, cwd?: string): void;
fromNestedJSON(json: NestedDirectoryJSON, cwd?: string): void;
reset(): void;
mountSync(mountpoint: string, json: DirectoryJSON): void;
private openLink;
private openFile;
private openBase;
openSync(path: PathLike, flags: TFlags, mode?: TMode): number;
open(path: PathLike, flags: TFlags, /* ... */ callback: TCallback<number>): any;
open(path: PathLike, flags: TFlags, mode: TMode, callback: TCallback<number>): any;
private closeFile;
closeSync(fd: number): void;
close(fd: number, callback: TCallback<void>): void;
private openFileOrGetById;
private readBase;
readSync(fd: number, buffer: Buffer | Uint8Array, offset: number, length: number, position: number): number;
read(fd: number, buffer: Buffer | Uint8Array, offset: number, length: number, position: number, callback: (err?: Error | null, bytesRead?: number, buffer?: Buffer | Uint8Array) => void): void;
private readFileBase;
readFileSync(file: TFileId, options?: IReadFileOptions | string): TDataOut;
readFile(id: TFileId, callback: TCallback<TDataOut>): any;
readFile(id: TFileId, options: IReadFileOptions | string, callback: TCallback<TDataOut>): any;
private writeBase;
writeSync(fd: number, buffer: Buffer | Uint8Array, offset?: number, length?: number, position?: number): number;
writeSync(fd: number, str: string, position?: number, encoding?: BufferEncoding): number;
write(fd: number, buffer: Buffer | Uint8Array, callback: (...args: any[]) => void): any;
write(fd: number, buffer: Buffer | Uint8Array, offset: number, callback: (...args: any[]) => void): any;
write(fd: number, buffer: Buffer | Uint8Array, offset: number, length: number, callback: (...args: any[]) => void): any;
write(fd: number, buffer: Buffer | Uint8Array, offset: number, length: number, position: number, callback: (...args: any[]) => void): any;
write(fd: number, str: string, callback: (...args: any[]) => void): any;
write(fd: number, str: string, position: number, callback: (...args: any[]) => void): any;
write(fd: number, str: string, position: number, encoding: BufferEncoding, callback: (...args: any[]) => void): any;
private writeFileBase;
writeFileSync(id: TFileId, data: TData, options?: IWriteFileOptions): void;
writeFile(id: TFileId, data: TData, callback: TCallback<void>): any;
writeFile(id: TFileId, data: TData, options: IWriteFileOptions | string, callback: TCallback<void>): any;
private linkBase;
private copyFileBase;
copyFileSync(src: PathLike, dest: PathLike, flags?: TFlagsCopy): void;
copyFile(src: PathLike, dest: PathLike, callback: TCallback<void>): any;
copyFile(src: PathLike, dest: PathLike, flags: TFlagsCopy, callback: TCallback<void>): any;
linkSync(existingPath: PathLike, newPath: PathLike): void;
link(existingPath: PathLike, newPath: PathLike, callback: TCallback<void>): void;
private unlinkBase;
unlinkSync(path: PathLike): void;
unlink(path: PathLike, callback: TCallback<void>): void;
private symlinkBase;
symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type): void;
symlink(target: PathLike, path: PathLike, callback: TCallback<void>): any;
symlink(target: PathLike, path: PathLike, type: symlink.Type, callback: TCallback<void>): any;
private realpathBase;
realpathSync(path: PathLike, options?: IRealpathOptions | string): TDataOut;
realpath(path: PathLike, callback: TCallback<TDataOut>): any;
realpath(path: PathLike, options: IRealpathOptions | string, callback: TCallback<TDataOut>): any;
private lstatBase;
lstatSync(path: PathLike): Stats<number>;
lstatSync(path: PathLike, options: {
throwIfNoEntry?: true | undefined;
}): Stats<number>;
lstatSync(path: PathLike, options: {
bigint: false;
throwIfNoEntry?: true | undefined;
}): Stats<number>;
lstatSync(path: PathLike, options: {
bigint: true;
throwIfNoEntry?: true | undefined;
}): Stats<bigint>;
lstatSync(path: PathLike, options: {
throwIfNoEntry: false;
}): Stats<number> | undefined;
lstatSync(path: PathLike, options: {
bigint: false;
throwIfNoEntry: false;
}): Stats<number> | undefined;
lstatSync(path: PathLike, options: {
bigint: true;
throwIfNoEntry: false;
}): Stats<bigint> | undefined;
lstat(path: PathLike, callback: TCallback<Stats>): void;
lstat(path: PathLike, options: IStatOptions, callback: TCallback<Stats>): void;
private statBase;
statSync(path: PathLike): Stats<number>;
statSync(path: PathLike, options: {
throwIfNoEntry?: true;
}): Stats<number>;
statSync(path: PathLike, options: {
throwIfNoEntry: false;
}): Stats<number> | undefined;
statSync(path: PathLike, options: {
bigint: false;
throwIfNoEntry?: true;
}): Stats<number>;
statSync(path: PathLike, options: {
bigint: true;
throwIfNoEntry?: true;
}): Stats<bigint>;
statSync(path: PathLike, options: {
bigint: false;
throwIfNoEntry: false;
}): Stats<number> | undefined;
statSync(path: PathLike, options: {
bigint: true;
throwIfNoEntry: false;
}): Stats<bigint> | undefined;
stat(path: PathLike, callback: TCallback<Stats>): void;
stat(path: PathLike, options: IStatOptions, callback: TCallback<Stats>): void;
private fstatBase;
fstatSync(fd: number): Stats<number>;
fstatSync(fd: number, options: {
bigint: false;
}): Stats<number>;
fstatSync(fd: number, options: {
bigint: true;
}): Stats<bigint>;
fstat(fd: number, callback: TCallback<Stats>): void;
fstat(fd: number, options: IFStatOptions, callback: TCallback<Stats>): void;
private renameBase;
renameSync(oldPath: PathLike, newPath: PathLike): void;
rename(oldPath: PathLike, newPath: PathLike, callback: TCallback<void>): void;
private existsBase;
existsSync(path: PathLike): boolean;
exists(path: PathLike, callback: (exists: boolean) => void): void;
private accessBase;
accessSync(path: PathLike, mode?: number): void;
access(path: PathLike, callback: TCallback<void>): any;
access(path: PathLike, mode: number, callback: TCallback<void>): any;
appendFileSync(id: TFileId, data: TData, options?: IAppendFileOptions | string): void;
appendFile(id: TFileId, data: TData, callback: TCallback<void>): any;
appendFile(id: TFileId, data: TData, options: IAppendFileOptions | string, callback: TCallback<void>): any;
private readdirBase;
readdirSync(path: PathLike, options?: IReaddirOptions | string): TDataOut[] | Dirent[];
readdir(path: PathLike, callback: TCallback<TDataOut[] | Dirent[]>): any;
readdir(path: PathLike, options: IReaddirOptions | string, callback: TCallback<TDataOut[] | Dirent[]>): any;
private readlinkBase;
readlinkSync(path: PathLike, options?: IOptions): TDataOut;
readlink(path: PathLike, callback: TCallback<TDataOut>): any;
readlink(path: PathLike, options: IOptions, callback: TCallback<TDataOut>): any;
private fsyncBase;
fsyncSync(fd: number): void;
fsync(fd: number, callback: TCallback<void>): void;
private fdatasyncBase;
fdatasyncSync(fd: number): void;
fdatasync(fd: number, callback: TCallback<void>): void;
private ftruncateBase;
ftruncateSync(fd: number, len?: number): void;
ftruncate(fd: number, callback: TCallback<void>): any;
ftruncate(fd: number, len: number, callback: TCallback<void>): any;
private truncateBase;
truncateSync(id: TFileId, len?: number): void;
truncate(id: TFileId, callback: TCallback<void>): any;
truncate(id: TFileId, len: number, callback: TCallback<void>): any;
private futimesBase;
futimesSync(fd: number, atime: TTime, mtime: TTime): void;
futimes(fd: number, atime: TTime, mtime: TTime, callback: TCallback<void>): void;
private utimesBase;
utimesSync(path: PathLike, atime: TTime, mtime: TTime): void;
utimes(path: PathLike, atime: TTime, mtime: TTime, callback: TCallback<void>): void;
private mkdirBase;
/**
* Creates directory tree recursively.
* @param filename
* @param modeNum
*/
private mkdirpBase;
mkdirSync(path: PathLike, options?: TMode | IMkdirOptions): void;
mkdir(path: PathLike, callback: TCallback<void>): any;
mkdir(path: PathLike, mode: TMode | IMkdirOptions, callback: TCallback<void>): any;
mkdirpSync(path: PathLike, mode?: TMode): void;
mkdirp(path: PathLike, callback: TCallback<void>): any;
mkdirp(path: PathLike, mode: TMode, callback: TCallback<void>): any;
private mkdtempBase;
mkdtempSync(prefix: string, options?: IOptions): TDataOut;
mkdtemp(prefix: string, callback: TCallback<void>): any;
mkdtemp(prefix: string, options: IOptions, callback: TCallback<void>): any;
private rmdirBase;
rmdirSync(path: PathLike, options?: IRmdirOptions): void;
rmdir(path: PathLike, callback: TCallback<void>): any;
rmdir(path: PathLike, options: IRmdirOptions, callback: TCallback<void>): any;
private rmBase;
rmSync(path: PathLike, options?: IRmOptions): void;
rm(path: PathLike, callback: TCallback<void>): void;
rm(path: PathLike, options: IRmOptions, callback: TCallback<void>): void;
private fchmodBase;
fchmodSync(fd: number, mode: TMode): void;
fchmod(fd: number, mode: TMode, callback: TCallback<void>): void;
private chmodBase;
chmodSync(path: PathLike, mode: TMode): void;
chmod(path: PathLike, mode: TMode, callback: TCallback<void>): void;
private lchmodBase;
lchmodSync(path: PathLike, mode: TMode): void;
lchmod(path: PathLike, mode: TMode, callback: TCallback<void>): void;
private fchownBase;
fchownSync(fd: number, uid: number, gid: number): void;
fchown(fd: number, uid: number, gid: number, callback: TCallback<void>): void;
private chownBase;
chownSync(path: PathLike, uid: number, gid: number): void;
chown(path: PathLike, uid: number, gid: number, callback: TCallback<void>): void;
private lchownBase;
lchownSync(path: PathLike, uid: number, gid: number): void;
lchown(path: PathLike, uid: number, gid: number, callback: TCallback<void>): void;
private statWatchers;
watchFile(path: PathLike, listener: (curr: Stats, prev: Stats) => void): StatWatcher;
watchFile(path: PathLike, options: IWatchFileOptions, listener: (curr: Stats, prev: Stats) => void): StatWatcher;
unwatchFile(path: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
createReadStream(path: PathLike, options?: IReadStreamOptions | string): IReadStream;
createWriteStream(path: PathLike, options?: IWriteStreamOptions | string): IWriteStream;
watch(path: PathLike, options?: IWatchOptions | string, listener?: (eventType: string, filename: string) => void): FSWatcher;
}
export declare class StatWatcher extends EventEmitter {
vol: Volume;
filename: string;
interval: number;
timeoutRef?: any;
setTimeout: TSetTimeout;
prev: Stats;
constructor(vol: Volume);
private loop;
private hasChanged;
private onInterval;
start(path: string, persistent?: boolean, interval?: number): void;
stop(): void;
}
export interface IReadStream extends Readable {
new (path: PathLike, options: IReadStreamOptions): any;
open(): any;
close(callback: TCallback<void>): any;
bytesRead: number;
path: string;
}
export interface IWriteStream extends Writable {
bytesWritten: number;
path: string;
new (path: PathLike, options: IWriteStreamOptions): any;
open(): any;
close(): any;
}
export declare class FSWatcher extends EventEmitter {
_vol: Volume;
_filename: string;
_steps: string[];
_filenameEncoded: TDataOut;
_recursive: boolean;
_encoding: BufferEncoding;
_link: Link;
_timer: any;
constructor(vol: Volume);
private _getName;
private _onNodeChange;
private _onParentChild;
private _emit;
private _persist;
start(path: PathLike, persistent?: boolean, recursive?: boolean, encoding?: BufferEncoding): void;
close(): void;
}
export {};