memfs 3.5.3 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Dirent.js +26 -27
- package/lib/Stats.js +27 -31
- package/lib/encoding.js +2 -2
- package/lib/index.d.ts +16 -2
- package/lib/index.js +28 -26
- package/lib/internal/buffer.js +5 -18
- package/lib/internal/errors.js +61 -91
- package/lib/node/FileHandle.d.ts +30 -0
- package/lib/node/FileHandle.js +50 -0
- package/lib/node/promises.d.ts +2 -0
- package/lib/node/promises.js +88 -0
- package/lib/node/types/callback.d.ts +83 -0
- package/lib/node/types/callback.js +2 -0
- package/lib/node/types/index.d.ts +7 -0
- package/lib/node/types/index.js +2 -0
- package/lib/node/types/misc.d.ts +112 -0
- package/lib/node/types/misc.js +2 -0
- package/lib/node/types/options.d.ts +72 -0
- package/lib/node/types/options.js +2 -0
- package/lib/node/types/promises.d.ts +31 -0
- package/lib/node/types/promises.js +2 -0
- package/lib/node/types/sync.d.ts +100 -0
- package/lib/node/types/sync.js +2 -0
- package/lib/node/util.d.ts +2 -0
- package/lib/node/util.js +13 -0
- package/lib/node.d.ts +2 -2
- package/lib/node.js +209 -289
- package/lib/process.js +5 -5
- package/lib/setImmediate.js +1 -1
- package/lib/setTimeoutUnref.js +1 -1
- package/lib/volume-localstorage.js +48 -85
- package/lib/volume.d.ts +13 -10
- package/lib/volume.js +789 -897
- package/package.json +1 -1
- package/lib/promises.d.ts +0 -78
- package/lib/promises.js +0 -158
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileHandle = void 0;
|
|
4
|
+
const util_1 = require("./util");
|
|
5
|
+
class FileHandle {
|
|
6
|
+
constructor(fs, fd) {
|
|
7
|
+
this.fs = fs;
|
|
8
|
+
this.fd = fd;
|
|
9
|
+
}
|
|
10
|
+
appendFile(data, options) {
|
|
11
|
+
return (0, util_1.promisify)(this.fs, 'appendFile')(this.fd, data, options);
|
|
12
|
+
}
|
|
13
|
+
chmod(mode) {
|
|
14
|
+
return (0, util_1.promisify)(this.fs, 'fchmod')(this.fd, mode);
|
|
15
|
+
}
|
|
16
|
+
chown(uid, gid) {
|
|
17
|
+
return (0, util_1.promisify)(this.fs, 'fchown')(this.fd, uid, gid);
|
|
18
|
+
}
|
|
19
|
+
close() {
|
|
20
|
+
return (0, util_1.promisify)(this.fs, 'close')(this.fd);
|
|
21
|
+
}
|
|
22
|
+
datasync() {
|
|
23
|
+
return (0, util_1.promisify)(this.fs, 'fdatasync')(this.fd);
|
|
24
|
+
}
|
|
25
|
+
read(buffer, offset, length, position) {
|
|
26
|
+
return (0, util_1.promisify)(this.fs, 'read', bytesRead => ({ bytesRead, buffer }))(this.fd, buffer, offset, length, position);
|
|
27
|
+
}
|
|
28
|
+
readFile(options) {
|
|
29
|
+
return (0, util_1.promisify)(this.fs, 'readFile')(this.fd, options);
|
|
30
|
+
}
|
|
31
|
+
stat(options) {
|
|
32
|
+
return (0, util_1.promisify)(this.fs, 'fstat')(this.fd, options);
|
|
33
|
+
}
|
|
34
|
+
sync() {
|
|
35
|
+
return (0, util_1.promisify)(this.fs, 'fsync')(this.fd);
|
|
36
|
+
}
|
|
37
|
+
truncate(len) {
|
|
38
|
+
return (0, util_1.promisify)(this.fs, 'ftruncate')(this.fd, len);
|
|
39
|
+
}
|
|
40
|
+
utimes(atime, mtime) {
|
|
41
|
+
return (0, util_1.promisify)(this.fs, 'futimes')(this.fd, atime, mtime);
|
|
42
|
+
}
|
|
43
|
+
write(buffer, offset, length, position) {
|
|
44
|
+
return (0, util_1.promisify)(this.fs, 'write', bytesWritten => ({ bytesWritten, buffer }))(this.fd, buffer, offset, length, position);
|
|
45
|
+
}
|
|
46
|
+
writeFile(data, options) {
|
|
47
|
+
return (0, util_1.promisify)(this.fs, 'writeFile')(this.fd, data, options);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.FileHandle = FileHandle;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPromisesApi = void 0;
|
|
4
|
+
const FileHandle_1 = require("./FileHandle");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
function createPromisesApi(vol) {
|
|
7
|
+
if (typeof Promise === 'undefined')
|
|
8
|
+
return null;
|
|
9
|
+
return {
|
|
10
|
+
FileHandle: FileHandle_1.FileHandle,
|
|
11
|
+
access(path, mode) {
|
|
12
|
+
return (0, util_1.promisify)(vol, 'access')(path, mode);
|
|
13
|
+
},
|
|
14
|
+
appendFile(path, data, options) {
|
|
15
|
+
return (0, util_1.promisify)(vol, 'appendFile')(path instanceof FileHandle_1.FileHandle ? path.fd : path, data, options);
|
|
16
|
+
},
|
|
17
|
+
chmod(path, mode) {
|
|
18
|
+
return (0, util_1.promisify)(vol, 'chmod')(path, mode);
|
|
19
|
+
},
|
|
20
|
+
chown(path, uid, gid) {
|
|
21
|
+
return (0, util_1.promisify)(vol, 'chown')(path, uid, gid);
|
|
22
|
+
},
|
|
23
|
+
copyFile(src, dest, flags) {
|
|
24
|
+
return (0, util_1.promisify)(vol, 'copyFile')(src, dest, flags);
|
|
25
|
+
},
|
|
26
|
+
lchmod(path, mode) {
|
|
27
|
+
return (0, util_1.promisify)(vol, 'lchmod')(path, mode);
|
|
28
|
+
},
|
|
29
|
+
lchown(path, uid, gid) {
|
|
30
|
+
return (0, util_1.promisify)(vol, 'lchown')(path, uid, gid);
|
|
31
|
+
},
|
|
32
|
+
link(existingPath, newPath) {
|
|
33
|
+
return (0, util_1.promisify)(vol, 'link')(existingPath, newPath);
|
|
34
|
+
},
|
|
35
|
+
lstat(path, options) {
|
|
36
|
+
return (0, util_1.promisify)(vol, 'lstat')(path, options);
|
|
37
|
+
},
|
|
38
|
+
mkdir(path, options) {
|
|
39
|
+
return (0, util_1.promisify)(vol, 'mkdir')(path, options);
|
|
40
|
+
},
|
|
41
|
+
mkdtemp(prefix, options) {
|
|
42
|
+
return (0, util_1.promisify)(vol, 'mkdtemp')(prefix, options);
|
|
43
|
+
},
|
|
44
|
+
open(path, flags, mode) {
|
|
45
|
+
return (0, util_1.promisify)(vol, 'open', fd => new FileHandle_1.FileHandle(vol, fd))(path, flags, mode);
|
|
46
|
+
},
|
|
47
|
+
readdir(path, options) {
|
|
48
|
+
return (0, util_1.promisify)(vol, 'readdir')(path, options);
|
|
49
|
+
},
|
|
50
|
+
readFile(id, options) {
|
|
51
|
+
return (0, util_1.promisify)(vol, 'readFile')(id instanceof FileHandle_1.FileHandle ? id.fd : id, options);
|
|
52
|
+
},
|
|
53
|
+
readlink(path, options) {
|
|
54
|
+
return (0, util_1.promisify)(vol, 'readlink')(path, options);
|
|
55
|
+
},
|
|
56
|
+
realpath(path, options) {
|
|
57
|
+
return (0, util_1.promisify)(vol, 'realpath')(path, options);
|
|
58
|
+
},
|
|
59
|
+
rename(oldPath, newPath) {
|
|
60
|
+
return (0, util_1.promisify)(vol, 'rename')(oldPath, newPath);
|
|
61
|
+
},
|
|
62
|
+
rmdir(path, options) {
|
|
63
|
+
return (0, util_1.promisify)(vol, 'rmdir')(path, options);
|
|
64
|
+
},
|
|
65
|
+
rm(path, options) {
|
|
66
|
+
return (0, util_1.promisify)(vol, 'rm')(path, options);
|
|
67
|
+
},
|
|
68
|
+
stat(path, options) {
|
|
69
|
+
return (0, util_1.promisify)(vol, 'stat')(path, options);
|
|
70
|
+
},
|
|
71
|
+
symlink(target, path, type) {
|
|
72
|
+
return (0, util_1.promisify)(vol, 'symlink')(target, path, type);
|
|
73
|
+
},
|
|
74
|
+
truncate(path, len) {
|
|
75
|
+
return (0, util_1.promisify)(vol, 'truncate')(path, len);
|
|
76
|
+
},
|
|
77
|
+
unlink(path) {
|
|
78
|
+
return (0, util_1.promisify)(vol, 'unlink')(path);
|
|
79
|
+
},
|
|
80
|
+
utimes(path, atime, mtime) {
|
|
81
|
+
return (0, util_1.promisify)(vol, 'utimes')(path, atime, mtime);
|
|
82
|
+
},
|
|
83
|
+
writeFile(id, data, options) {
|
|
84
|
+
return (0, util_1.promisify)(vol, 'writeFile')(id instanceof FileHandle_1.FileHandle ? id.fd : id, data, options);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
exports.createPromisesApi = createPromisesApi;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { PathLike, symlink } from 'fs';
|
|
4
|
+
import type * as misc from './misc';
|
|
5
|
+
import type * as opts from './options';
|
|
6
|
+
export interface FsCallbackApi {
|
|
7
|
+
open(path: PathLike, flags: misc.TFlags, /* ... */ callback: misc.TCallback<number>): any;
|
|
8
|
+
open(path: PathLike, flags: misc.TFlags, mode: misc.TMode, callback: misc.TCallback<number>): any;
|
|
9
|
+
close(fd: number, callback: misc.TCallback<void>): void;
|
|
10
|
+
read(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number, callback: (err?: Error | null, bytesRead?: number, buffer?: Buffer | ArrayBufferView | DataView) => void): void;
|
|
11
|
+
readFile(id: misc.TFileId, callback: misc.TCallback<misc.TDataOut>): any;
|
|
12
|
+
readFile(id: misc.TFileId, options: opts.IReadFileOptions | string, callback: misc.TCallback<misc.TDataOut>): any;
|
|
13
|
+
write(fd: number, buffer: Buffer | ArrayBufferView | DataView, callback: (...args: any[]) => void): any;
|
|
14
|
+
write(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, callback: (...args: any[]) => void): any;
|
|
15
|
+
write(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, callback: (...args: any[]) => void): any;
|
|
16
|
+
write(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number, callback: (...args: any[]) => void): any;
|
|
17
|
+
write(fd: number, str: string, callback: (...args: any[]) => void): any;
|
|
18
|
+
write(fd: number, str: string, position: number, callback: (...args: any[]) => void): any;
|
|
19
|
+
write(fd: number, str: string, position: number, encoding: BufferEncoding, callback: (...args: any[]) => void): any;
|
|
20
|
+
writeFile(id: misc.TFileId, data: misc.TData, callback: misc.TCallback<void>): any;
|
|
21
|
+
writeFile(id: misc.TFileId, data: misc.TData, options: opts.IWriteFileOptions | string, callback: misc.TCallback<void>): any;
|
|
22
|
+
copyFile(src: PathLike, dest: PathLike, callback: misc.TCallback<void>): any;
|
|
23
|
+
copyFile(src: PathLike, dest: PathLike, flags: misc.TFlagsCopy, callback: misc.TCallback<void>): any;
|
|
24
|
+
link(existingPath: PathLike, newPath: PathLike, callback: misc.TCallback<void>): void;
|
|
25
|
+
unlink(path: PathLike, callback: misc.TCallback<void>): void;
|
|
26
|
+
symlink(target: PathLike, path: PathLike, callback: misc.TCallback<void>): any;
|
|
27
|
+
symlink(target: PathLike, path: PathLike, type: symlink.Type, callback: misc.TCallback<void>): any;
|
|
28
|
+
realpath(path: PathLike, callback: misc.TCallback<misc.TDataOut>): any;
|
|
29
|
+
realpath(path: PathLike, options: opts.IRealpathOptions | string, callback: misc.TCallback<misc.TDataOut>): any;
|
|
30
|
+
lstat(path: PathLike, callback: misc.TCallback<misc.IStats>): void;
|
|
31
|
+
lstat(path: PathLike, options: opts.IStatOptions, callback: misc.TCallback<misc.IStats>): void;
|
|
32
|
+
stat(path: PathLike, callback: misc.TCallback<misc.IStats>): void;
|
|
33
|
+
stat(path: PathLike, options: opts.IStatOptions, callback: misc.TCallback<misc.IStats>): void;
|
|
34
|
+
fstat(fd: number, callback: misc.TCallback<misc.IStats>): void;
|
|
35
|
+
fstat(fd: number, options: opts.IFStatOptions, callback: misc.TCallback<misc.IStats>): void;
|
|
36
|
+
rename(oldPath: PathLike, newPath: PathLike, callback: misc.TCallback<void>): void;
|
|
37
|
+
exists(path: PathLike, callback: (exists: boolean) => void): void;
|
|
38
|
+
access(path: PathLike, callback: misc.TCallback<void>): any;
|
|
39
|
+
access(path: PathLike, mode: number, callback: misc.TCallback<void>): any;
|
|
40
|
+
appendFile(id: misc.TFileId, data: misc.TData, callback: misc.TCallback<void>): any;
|
|
41
|
+
appendFile(id: misc.TFileId, data: misc.TData, options: opts.IAppendFileOptions | string, callback: misc.TCallback<void>): any;
|
|
42
|
+
readdir(path: PathLike, callback: misc.TCallback<misc.TDataOut[] | misc.IDirent[]>): any;
|
|
43
|
+
readdir(path: PathLike, options: opts.IReaddirOptions | string, callback: misc.TCallback<misc.TDataOut[] | misc.IDirent[]>): any;
|
|
44
|
+
readlink(path: PathLike, callback: misc.TCallback<misc.TDataOut>): any;
|
|
45
|
+
readlink(path: PathLike, options: opts.IOptions, callback: misc.TCallback<misc.TDataOut>): any;
|
|
46
|
+
fsyncSync(fd: number): void;
|
|
47
|
+
fsync(fd: number, callback: misc.TCallback<void>): void;
|
|
48
|
+
fdatasync(fd: number, callback: misc.TCallback<void>): void;
|
|
49
|
+
ftruncate(fd: number, callback: misc.TCallback<void>): any;
|
|
50
|
+
ftruncate(fd: number, len: number, callback: misc.TCallback<void>): any;
|
|
51
|
+
truncate(id: misc.TFileId, callback: misc.TCallback<void>): any;
|
|
52
|
+
truncate(id: misc.TFileId, len: number, callback: misc.TCallback<void>): any;
|
|
53
|
+
futimes(fd: number, atime: misc.TTime, mtime: misc.TTime, callback: misc.TCallback<void>): void;
|
|
54
|
+
utimes(path: PathLike, atime: misc.TTime, mtime: misc.TTime, callback: misc.TCallback<void>): void;
|
|
55
|
+
mkdir(path: PathLike, callback: misc.TCallback<void>): any;
|
|
56
|
+
mkdir(path: PathLike, mode: misc.TMode | (opts.IMkdirOptions & {
|
|
57
|
+
recursive?: false;
|
|
58
|
+
}), callback: misc.TCallback<void>): any;
|
|
59
|
+
mkdir(path: PathLike, mode: opts.IMkdirOptions & {
|
|
60
|
+
recursive: true;
|
|
61
|
+
}, callback: misc.TCallback<string>): any;
|
|
62
|
+
mkdir(path: PathLike, mode: misc.TMode | opts.IMkdirOptions, callback: misc.TCallback<string>): any;
|
|
63
|
+
mkdirp(path: PathLike, callback: misc.TCallback<string>): any;
|
|
64
|
+
mkdirp(path: PathLike, mode: misc.TMode, callback: misc.TCallback<string>): any;
|
|
65
|
+
mkdtemp(prefix: string, callback: misc.TCallback<void>): void;
|
|
66
|
+
mkdtemp(prefix: string, options: opts.IOptions, callback: misc.TCallback<void>): any;
|
|
67
|
+
rmdir(path: PathLike, callback: misc.TCallback<void>): any;
|
|
68
|
+
rmdir(path: PathLike, options: opts.IRmdirOptions, callback: misc.TCallback<void>): any;
|
|
69
|
+
rm(path: PathLike, callback: misc.TCallback<void>): void;
|
|
70
|
+
rm(path: PathLike, options: opts.IRmOptions, callback: misc.TCallback<void>): void;
|
|
71
|
+
fchmod(fd: number, mode: misc.TMode, callback: misc.TCallback<void>): void;
|
|
72
|
+
chmod(path: PathLike, mode: misc.TMode, callback: misc.TCallback<void>): void;
|
|
73
|
+
lchmod(path: PathLike, mode: misc.TMode, callback: misc.TCallback<void>): void;
|
|
74
|
+
fchown(fd: number, uid: number, gid: number, callback: misc.TCallback<void>): void;
|
|
75
|
+
chown(path: PathLike, uid: number, gid: number, callback: misc.TCallback<void>): void;
|
|
76
|
+
lchown(path: PathLike, uid: number, gid: number, callback: misc.TCallback<void>): void;
|
|
77
|
+
watchFile(path: PathLike, listener: (curr: misc.IStats, prev: misc.IStats) => void): misc.IStatWatcher;
|
|
78
|
+
watchFile(path: PathLike, options: opts.IWatchFileOptions, listener: (curr: misc.IStats, prev: misc.IStats) => void): misc.IStatWatcher;
|
|
79
|
+
unwatchFile(path: PathLike, listener?: (curr: misc.IStats, prev: misc.IStats) => void): void;
|
|
80
|
+
createReadStream(path: PathLike, options?: opts.IReadStreamOptions | string): misc.IReadStream;
|
|
81
|
+
createWriteStream(path: PathLike, options?: opts.IWriteStreamOptions | string): misc.IWriteStream;
|
|
82
|
+
watch(path: PathLike, options?: opts.IWatchOptions | string, listener?: (eventType: string, filename: string) => void): misc.IFSWatcher;
|
|
83
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FsSynchronousApi } from './sync';
|
|
2
|
+
import type { FsCallbackApi } from './callback';
|
|
3
|
+
import type { FsPromisesApi } from './promises';
|
|
4
|
+
export { FsSynchronousApi, FsCallbackApi, FsPromisesApi };
|
|
5
|
+
export interface FsApi extends FsCallbackApi, FsSynchronousApi {
|
|
6
|
+
promises: FsPromisesApi;
|
|
7
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import type { PathLike, symlink } from 'fs';
|
|
6
|
+
import type { constants } from '../../constants';
|
|
7
|
+
import type { EventEmitter } from 'events';
|
|
8
|
+
import type { TSetTimeout } from '../../setTimeoutUnref';
|
|
9
|
+
import type { IAppendFileOptions, IReadFileOptions, IReadStreamOptions, IStatOptions, IWriteFileOptions, IWriteStreamOptions } from './options';
|
|
10
|
+
import type { Readable, Writable } from 'stream';
|
|
11
|
+
export { PathLike, symlink };
|
|
12
|
+
export type TDataOut = string | Buffer;
|
|
13
|
+
export type TEncodingExtended = BufferEncoding | 'buffer';
|
|
14
|
+
export type TFileId = PathLike | number;
|
|
15
|
+
export type TData = TDataOut | ArrayBufferView | DataView;
|
|
16
|
+
export type TFlags = string | number;
|
|
17
|
+
export type TMode = string | number;
|
|
18
|
+
export type TTime = number | string | Date;
|
|
19
|
+
export type TCallback<TData> = (error?: IError | null, data?: TData) => void;
|
|
20
|
+
export interface IError extends Error {
|
|
21
|
+
code?: string;
|
|
22
|
+
}
|
|
23
|
+
export type TFlagsCopy = typeof constants.COPYFILE_EXCL | typeof constants.COPYFILE_FICLONE | typeof constants.COPYFILE_FICLONE_FORCE;
|
|
24
|
+
export type TStatNumber = number | bigint;
|
|
25
|
+
export interface IStats<T = TStatNumber> {
|
|
26
|
+
uid: T;
|
|
27
|
+
gid: T;
|
|
28
|
+
rdev: T;
|
|
29
|
+
blksize: T;
|
|
30
|
+
ino: T;
|
|
31
|
+
size: T;
|
|
32
|
+
blocks: T;
|
|
33
|
+
atime: Date;
|
|
34
|
+
mtime: Date;
|
|
35
|
+
ctime: Date;
|
|
36
|
+
birthtime: Date;
|
|
37
|
+
atimeMs: T;
|
|
38
|
+
mtimeMs: T;
|
|
39
|
+
ctimeMs: T;
|
|
40
|
+
birthtimeMs: T;
|
|
41
|
+
dev: T;
|
|
42
|
+
mode: T;
|
|
43
|
+
nlink: T;
|
|
44
|
+
isDirectory(): boolean;
|
|
45
|
+
isFile(): boolean;
|
|
46
|
+
isBlockDevice(): boolean;
|
|
47
|
+
isCharacterDevice(): boolean;
|
|
48
|
+
isSymbolicLink(): boolean;
|
|
49
|
+
isFIFO(): boolean;
|
|
50
|
+
isSocket(): boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface IDirent {
|
|
53
|
+
name: TDataOut;
|
|
54
|
+
isDirectory(): boolean;
|
|
55
|
+
isFile(): boolean;
|
|
56
|
+
isBlockDevice(): boolean;
|
|
57
|
+
isCharacterDevice(): boolean;
|
|
58
|
+
isSymbolicLink(): boolean;
|
|
59
|
+
isFIFO(): boolean;
|
|
60
|
+
isSocket(): boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface IStatWatcher extends EventEmitter {
|
|
63
|
+
filename: string;
|
|
64
|
+
interval: number;
|
|
65
|
+
timeoutRef?: any;
|
|
66
|
+
setTimeout: TSetTimeout;
|
|
67
|
+
prev: IStats;
|
|
68
|
+
start(path: string, persistent?: boolean, interval?: number): void;
|
|
69
|
+
stop(): void;
|
|
70
|
+
}
|
|
71
|
+
export interface IReadStream extends Readable {
|
|
72
|
+
new (path: PathLike, options: IReadStreamOptions): any;
|
|
73
|
+
open(): any;
|
|
74
|
+
close(callback: TCallback<void>): any;
|
|
75
|
+
bytesRead: number;
|
|
76
|
+
path: string;
|
|
77
|
+
}
|
|
78
|
+
export interface IWriteStream extends Writable {
|
|
79
|
+
bytesWritten: number;
|
|
80
|
+
path: string;
|
|
81
|
+
new (path: PathLike, options: IWriteStreamOptions): any;
|
|
82
|
+
open(): any;
|
|
83
|
+
close(): any;
|
|
84
|
+
}
|
|
85
|
+
export interface IFSWatcher extends EventEmitter {
|
|
86
|
+
start(path: PathLike, persistent?: boolean, recursive?: boolean, encoding?: BufferEncoding): void;
|
|
87
|
+
close(): void;
|
|
88
|
+
}
|
|
89
|
+
export interface IFileHandle {
|
|
90
|
+
fd: number;
|
|
91
|
+
appendFile(data: TData, options?: IAppendFileOptions | string): Promise<void>;
|
|
92
|
+
chmod(mode: TMode): Promise<void>;
|
|
93
|
+
chown(uid: number, gid: number): Promise<void>;
|
|
94
|
+
close(): Promise<void>;
|
|
95
|
+
datasync(): Promise<void>;
|
|
96
|
+
read(buffer: Buffer | Uint8Array, offset: number, length: number, position: number): Promise<TFileHandleReadResult>;
|
|
97
|
+
readFile(options?: IReadFileOptions | string): Promise<TDataOut>;
|
|
98
|
+
stat(options?: IStatOptions): Promise<IStats>;
|
|
99
|
+
truncate(len?: number): Promise<void>;
|
|
100
|
+
utimes(atime: TTime, mtime: TTime): Promise<void>;
|
|
101
|
+
write(buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): Promise<TFileHandleWriteResult>;
|
|
102
|
+
writeFile(data: TData, options?: IWriteFileOptions): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
export type TFileHandle = PathLike | IFileHandle;
|
|
105
|
+
export interface TFileHandleReadResult {
|
|
106
|
+
bytesRead: number;
|
|
107
|
+
buffer: Buffer | Uint8Array;
|
|
108
|
+
}
|
|
109
|
+
export interface TFileHandleWriteResult {
|
|
110
|
+
bytesWritten: number;
|
|
111
|
+
buffer: Buffer | Uint8Array;
|
|
112
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { TEncodingExtended, TFlags, TMode } from './misc';
|
|
3
|
+
export interface IOptions {
|
|
4
|
+
encoding?: BufferEncoding | TEncodingExtended;
|
|
5
|
+
}
|
|
6
|
+
export interface IFileOptions extends IOptions {
|
|
7
|
+
mode?: TMode;
|
|
8
|
+
flag?: TFlags;
|
|
9
|
+
}
|
|
10
|
+
export interface IWriteFileOptions extends IFileOptions {
|
|
11
|
+
}
|
|
12
|
+
export interface IReadFileOptions extends IOptions {
|
|
13
|
+
flag?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IRealpathOptions {
|
|
16
|
+
encoding?: TEncodingExtended;
|
|
17
|
+
}
|
|
18
|
+
export interface IAppendFileOptions extends IFileOptions {
|
|
19
|
+
}
|
|
20
|
+
export interface IStatOptions {
|
|
21
|
+
bigint?: boolean;
|
|
22
|
+
throwIfNoEntry?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface IFStatOptions {
|
|
25
|
+
bigint?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface IAppendFileOptions extends IFileOptions {
|
|
28
|
+
}
|
|
29
|
+
export interface IReaddirOptions extends IOptions {
|
|
30
|
+
withFileTypes?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface IMkdirOptions {
|
|
33
|
+
mode?: TMode;
|
|
34
|
+
recursive?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface IRmdirOptions {
|
|
37
|
+
/** @deprecated */
|
|
38
|
+
recursive?: boolean;
|
|
39
|
+
maxRetries?: number;
|
|
40
|
+
retryDelay?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface IRmOptions {
|
|
43
|
+
force?: boolean;
|
|
44
|
+
maxRetries?: number;
|
|
45
|
+
recursive?: boolean;
|
|
46
|
+
retryDelay?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface IWatchFileOptions {
|
|
49
|
+
persistent?: boolean;
|
|
50
|
+
interval?: number;
|
|
51
|
+
}
|
|
52
|
+
export interface IReadStreamOptions {
|
|
53
|
+
flags?: TFlags;
|
|
54
|
+
encoding?: BufferEncoding;
|
|
55
|
+
fd?: number;
|
|
56
|
+
mode?: TMode;
|
|
57
|
+
autoClose?: boolean;
|
|
58
|
+
start?: number;
|
|
59
|
+
end?: number;
|
|
60
|
+
}
|
|
61
|
+
export interface IWriteStreamOptions {
|
|
62
|
+
flags?: TFlags;
|
|
63
|
+
defaultEncoding?: BufferEncoding;
|
|
64
|
+
fd?: number;
|
|
65
|
+
mode?: TMode;
|
|
66
|
+
autoClose?: boolean;
|
|
67
|
+
start?: number;
|
|
68
|
+
}
|
|
69
|
+
export interface IWatchOptions extends IOptions {
|
|
70
|
+
persistent?: boolean;
|
|
71
|
+
recursive?: boolean;
|
|
72
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as misc from './misc';
|
|
3
|
+
import * as opts from './options';
|
|
4
|
+
export interface FsPromisesApi {
|
|
5
|
+
FileHandle: new (...args: unknown[]) => misc.IFileHandle;
|
|
6
|
+
access(path: misc.PathLike, mode?: number): Promise<void>;
|
|
7
|
+
appendFile(path: misc.TFileHandle, data: misc.TData, options?: opts.IAppendFileOptions | string): Promise<void>;
|
|
8
|
+
chmod(path: misc.PathLike, mode: misc.TMode): Promise<void>;
|
|
9
|
+
chown(path: misc.PathLike, uid: number, gid: number): Promise<void>;
|
|
10
|
+
copyFile(src: misc.PathLike, dest: misc.PathLike, flags?: misc.TFlagsCopy): Promise<void>;
|
|
11
|
+
lchmod(path: misc.PathLike, mode: misc.TMode): Promise<void>;
|
|
12
|
+
lchown(path: misc.PathLike, uid: number, gid: number): Promise<void>;
|
|
13
|
+
link(existingPath: misc.PathLike, newPath: misc.PathLike): Promise<void>;
|
|
14
|
+
lstat(path: misc.PathLike, options?: opts.IStatOptions): Promise<misc.IStats>;
|
|
15
|
+
mkdir(path: misc.PathLike, options?: misc.TMode | opts.IMkdirOptions): Promise<void>;
|
|
16
|
+
mkdtemp(prefix: string, options?: opts.IOptions): Promise<misc.TDataOut>;
|
|
17
|
+
open(path: misc.PathLike, flags: misc.TFlags, mode?: misc.TMode): Promise<misc.IFileHandle>;
|
|
18
|
+
readdir(path: misc.PathLike, options?: opts.IReaddirOptions | string): Promise<misc.TDataOut[] | misc.IDirent[]>;
|
|
19
|
+
readFile(id: misc.TFileHandle, options?: opts.IReadFileOptions | string): Promise<misc.TDataOut>;
|
|
20
|
+
readlink(path: misc.PathLike, options?: opts.IOptions): Promise<misc.TDataOut>;
|
|
21
|
+
realpath(path: misc.PathLike, options?: opts.IRealpathOptions | string): Promise<misc.TDataOut>;
|
|
22
|
+
rename(oldPath: misc.PathLike, newPath: misc.PathLike): Promise<void>;
|
|
23
|
+
rmdir(path: misc.PathLike, options?: opts.IRmdirOptions): Promise<void>;
|
|
24
|
+
rm(path: misc.PathLike, options?: opts.IRmOptions): Promise<void>;
|
|
25
|
+
stat(path: misc.PathLike, options?: opts.IStatOptions): Promise<misc.IStats>;
|
|
26
|
+
symlink(target: misc.PathLike, path: misc.PathLike, type?: misc.symlink.Type): Promise<void>;
|
|
27
|
+
truncate(path: misc.PathLike, len?: number): Promise<void>;
|
|
28
|
+
unlink(path: misc.PathLike): Promise<void>;
|
|
29
|
+
utimes(path: misc.PathLike, atime: misc.TTime, mtime: misc.TTime): Promise<void>;
|
|
30
|
+
writeFile(id: misc.TFileHandle, data: misc.TData, options?: opts.IWriteFileOptions): Promise<void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { PathLike, symlink } from 'fs';
|
|
4
|
+
import type * as misc from './misc';
|
|
5
|
+
import type * as opts from './options';
|
|
6
|
+
export interface FsSynchronousApi {
|
|
7
|
+
openSync(path: PathLike, flags: misc.TFlags, mode?: misc.TMode): number;
|
|
8
|
+
closeSync(fd: number): void;
|
|
9
|
+
readSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number): number;
|
|
10
|
+
readFileSync(file: misc.TFileId, options?: opts.IReadFileOptions | string): misc.TDataOut;
|
|
11
|
+
writeSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): number;
|
|
12
|
+
writeSync(fd: number, str: string, position?: number, encoding?: BufferEncoding): number;
|
|
13
|
+
writeFileSync(id: misc.TFileId, data: misc.TData, options?: opts.IWriteFileOptions): void;
|
|
14
|
+
copyFileSync(src: PathLike, dest: PathLike, flags?: misc.TFlagsCopy): void;
|
|
15
|
+
linkSync(existingPath: PathLike, newPath: PathLike): void;
|
|
16
|
+
unlinkSync(path: PathLike): void;
|
|
17
|
+
symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type): void;
|
|
18
|
+
realpathSync(path: PathLike, options?: opts.IRealpathOptions | string): misc.TDataOut;
|
|
19
|
+
lstatSync(path: PathLike): misc.IStats<number>;
|
|
20
|
+
lstatSync(path: PathLike, options: {
|
|
21
|
+
throwIfNoEntry?: true | undefined;
|
|
22
|
+
}): misc.IStats<number>;
|
|
23
|
+
lstatSync(path: PathLike, options: {
|
|
24
|
+
bigint: false;
|
|
25
|
+
throwIfNoEntry?: true | undefined;
|
|
26
|
+
}): misc.IStats<number>;
|
|
27
|
+
lstatSync(path: PathLike, options: {
|
|
28
|
+
bigint: true;
|
|
29
|
+
throwIfNoEntry?: true | undefined;
|
|
30
|
+
}): misc.IStats<bigint>;
|
|
31
|
+
lstatSync(path: PathLike, options: {
|
|
32
|
+
throwIfNoEntry: false;
|
|
33
|
+
}): misc.IStats<number> | undefined;
|
|
34
|
+
lstatSync(path: PathLike, options: {
|
|
35
|
+
bigint: false;
|
|
36
|
+
throwIfNoEntry: false;
|
|
37
|
+
}): misc.IStats<number> | undefined;
|
|
38
|
+
lstatSync(path: PathLike, options: {
|
|
39
|
+
bigint: true;
|
|
40
|
+
throwIfNoEntry: false;
|
|
41
|
+
}): misc.IStats<bigint> | undefined;
|
|
42
|
+
statSync(path: PathLike): misc.IStats<number>;
|
|
43
|
+
statSync(path: PathLike, options: {
|
|
44
|
+
throwIfNoEntry?: true;
|
|
45
|
+
}): misc.IStats<number>;
|
|
46
|
+
statSync(path: PathLike, options: {
|
|
47
|
+
throwIfNoEntry: false;
|
|
48
|
+
}): misc.IStats<number> | undefined;
|
|
49
|
+
statSync(path: PathLike, options: {
|
|
50
|
+
bigint: false;
|
|
51
|
+
throwIfNoEntry?: true;
|
|
52
|
+
}): misc.IStats<number>;
|
|
53
|
+
statSync(path: PathLike, options: {
|
|
54
|
+
bigint: true;
|
|
55
|
+
throwIfNoEntry?: true;
|
|
56
|
+
}): misc.IStats<bigint>;
|
|
57
|
+
statSync(path: PathLike, options: {
|
|
58
|
+
bigint: false;
|
|
59
|
+
throwIfNoEntry: false;
|
|
60
|
+
}): misc.IStats<number> | undefined;
|
|
61
|
+
statSync(path: PathLike, options: {
|
|
62
|
+
bigint: true;
|
|
63
|
+
throwIfNoEntry: false;
|
|
64
|
+
}): misc.IStats<bigint> | undefined;
|
|
65
|
+
fstatSync(fd: number): misc.IStats<number>;
|
|
66
|
+
fstatSync(fd: number, options: {
|
|
67
|
+
bigint: false;
|
|
68
|
+
}): misc.IStats<number>;
|
|
69
|
+
fstatSync(fd: number, options: {
|
|
70
|
+
bigint: true;
|
|
71
|
+
}): misc.IStats<bigint>;
|
|
72
|
+
renameSync(oldPath: PathLike, newPath: PathLike): void;
|
|
73
|
+
existsSync(path: PathLike): boolean;
|
|
74
|
+
accessSync(path: PathLike, mode?: number): void;
|
|
75
|
+
appendFileSync(id: misc.TFileId, data: misc.TData, options?: opts.IAppendFileOptions | string): void;
|
|
76
|
+
readdirSync(path: PathLike, options?: opts.IReaddirOptions | string): misc.TDataOut[] | misc.IDirent[];
|
|
77
|
+
readlinkSync(path: PathLike, options?: opts.IOptions): misc.TDataOut;
|
|
78
|
+
fdatasyncSync(fd: number): void;
|
|
79
|
+
ftruncateSync(fd: number, len?: number): void;
|
|
80
|
+
truncateSync(id: misc.TFileId, len?: number): void;
|
|
81
|
+
futimesSync(fd: number, atime: misc.TTime, mtime: misc.TTime): void;
|
|
82
|
+
utimesSync(path: PathLike, atime: misc.TTime, mtime: misc.TTime): void;
|
|
83
|
+
mkdirSync(path: PathLike, options: opts.IMkdirOptions & {
|
|
84
|
+
recursive: true;
|
|
85
|
+
}): string | undefined;
|
|
86
|
+
mkdirSync(path: PathLike, options?: misc.TMode | (opts.IMkdirOptions & {
|
|
87
|
+
recursive?: false;
|
|
88
|
+
})): void;
|
|
89
|
+
mkdirSync(path: PathLike, options?: misc.TMode | opts.IMkdirOptions): string | undefined;
|
|
90
|
+
mkdirpSync(path: PathLike, mode?: misc.TMode): void;
|
|
91
|
+
mkdtempSync(prefix: string, options?: opts.IOptions): misc.TDataOut;
|
|
92
|
+
rmdirSync(path: PathLike, options?: opts.IRmdirOptions): void;
|
|
93
|
+
rmSync(path: PathLike, options?: opts.IRmOptions): void;
|
|
94
|
+
fchmodSync(fd: number, mode: misc.TMode): void;
|
|
95
|
+
chmodSync(path: PathLike, mode: misc.TMode): void;
|
|
96
|
+
lchmodSync(path: PathLike, mode: misc.TMode): void;
|
|
97
|
+
fchownSync(fd: number, uid: number, gid: number): void;
|
|
98
|
+
chownSync(path: PathLike, uid: number, gid: number): void;
|
|
99
|
+
lchownSync(path: PathLike, uid: number, gid: number): void;
|
|
100
|
+
}
|
package/lib/node/util.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promisify = void 0;
|
|
4
|
+
function promisify(fs, fn, getResult = input => input) {
|
|
5
|
+
return (...args) => new Promise((resolve, reject) => {
|
|
6
|
+
fs[fn].bind(fs)(...args, (error, result) => {
|
|
7
|
+
if (error)
|
|
8
|
+
return reject(error);
|
|
9
|
+
return resolve(getResult(result));
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
exports.promisify = promisify;
|
package/lib/node.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare class Node extends EventEmitter {
|
|
|
48
48
|
isSymlink(): boolean;
|
|
49
49
|
makeSymlink(steps: string[]): void;
|
|
50
50
|
write(buf: Buffer, off?: number, len?: number, pos?: number): number;
|
|
51
|
-
read(buf: Buffer |
|
|
51
|
+
read(buf: Buffer | ArrayBufferView | DataView, off?: number, len?: number, pos?: number): number;
|
|
52
52
|
truncate(len?: number): void;
|
|
53
53
|
chmod(perm: number): void;
|
|
54
54
|
chown(uid: number, gid: number): void;
|
|
@@ -150,7 +150,7 @@ export declare class File {
|
|
|
150
150
|
seekTo(position: number): void;
|
|
151
151
|
stats(): Stats<number>;
|
|
152
152
|
write(buf: Buffer, offset?: number, length?: number, position?: number): number;
|
|
153
|
-
read(buf: Buffer |
|
|
153
|
+
read(buf: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): number;
|
|
154
154
|
chmod(perm: number): void;
|
|
155
155
|
chown(uid: number, gid: number): void;
|
|
156
156
|
}
|