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