@zenfs/core 0.9.6 → 0.9.7
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/dist/ApiError.d.ts +4 -3
- package/dist/ApiError.js +1 -1
- package/dist/backends/AsyncStore.d.ts +3 -2
- package/dist/backends/AsyncStore.js +12 -5
- package/dist/backends/InMemory.d.ts +1 -1
- package/dist/backends/Index.d.ts +7 -10
- package/dist/backends/Index.js +7 -5
- package/dist/backends/Overlay.js +1 -1
- package/dist/backends/SyncStore.d.ts +6 -6
- package/dist/backends/SyncStore.js +4 -4
- package/dist/backends/backend.d.ts +5 -4
- package/dist/backends/backend.js +2 -2
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +3 -3
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -2
- package/dist/emulation/async.d.ts +76 -77
- package/dist/emulation/async.js +42 -42
- package/dist/emulation/dir.js +6 -5
- package/dist/emulation/promises.d.ts +106 -102
- package/dist/emulation/promises.js +61 -65
- package/dist/emulation/shared.d.ts +1 -7
- package/dist/emulation/shared.js +1 -1
- package/dist/emulation/streams.js +3 -2
- package/dist/emulation/sync.d.ts +71 -64
- package/dist/emulation/sync.js +39 -40
- package/dist/file.d.ts +4 -4
- package/dist/file.js +7 -5
- package/dist/filesystem.d.ts +1 -1
- package/dist/filesystem.js +3 -0
- package/dist/mutex.js +2 -2
- package/dist/stats.d.ts +7 -7
- package/dist/stats.js +50 -10
- package/dist/utils.d.ts +5 -5
- package/dist/utils.js +4 -3
- package/package.json +3 -3
- package/readme.md +2 -2
- package/src/ApiError.ts +3 -1
- package/src/backends/AsyncStore.ts +14 -8
- package/src/backends/Index.ts +14 -10
- package/src/backends/Overlay.ts +3 -3
- package/src/backends/SyncStore.ts +8 -8
- package/src/backends/backend.ts +7 -5
- package/src/config.ts +5 -5
- package/src/emulation/async.ts +188 -196
- package/src/emulation/dir.ts +6 -6
- package/src/emulation/promises.ts +181 -173
- package/src/emulation/shared.ts +2 -9
- package/src/emulation/streams.ts +9 -8
- package/src/emulation/sync.ts +159 -159
- package/src/file.ts +11 -9
- package/src/filesystem.ts +11 -7
- package/src/mutex.ts +3 -3
- package/src/stats.ts +32 -23
- package/src/utils.ts +10 -9
- package/tsconfig.json +2 -1
package/src/emulation/async.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as
|
|
1
|
+
import type * as fs from 'node:fs';
|
|
2
2
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
3
3
|
import type { FileContents } from '../filesystem.js';
|
|
4
4
|
import { BigIntStats, type BigIntStatsFs, type Stats, type StatsFs } from '../stats.js';
|
|
@@ -6,7 +6,7 @@ import { nop, normalizeMode, type Callback } from '../utils.js';
|
|
|
6
6
|
import { R_OK } from './constants.js';
|
|
7
7
|
import { Dirent, type Dir } from './dir.js';
|
|
8
8
|
import * as promises from './promises.js';
|
|
9
|
-
import {
|
|
9
|
+
import { fd2file } from './shared.js';
|
|
10
10
|
import { ReadStream, WriteStream } from './streams.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -16,13 +16,13 @@ import { ReadStream, WriteStream } from './streams.js';
|
|
|
16
16
|
* @param newPath
|
|
17
17
|
* @param callback
|
|
18
18
|
*/
|
|
19
|
-
export function rename(oldPath: PathLike, newPath: PathLike, cb: Callback = nop): void {
|
|
19
|
+
export function rename(oldPath: fs.PathLike, newPath: fs.PathLike, cb: Callback = nop): void {
|
|
20
20
|
promises
|
|
21
21
|
.rename(oldPath, newPath)
|
|
22
22
|
.then(() => cb())
|
|
23
23
|
.catch(cb);
|
|
24
24
|
}
|
|
25
|
-
rename satisfies Omit<typeof
|
|
25
|
+
rename satisfies Omit<typeof fs.rename, '__promisify__'>;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Test whether or not the given path exists by checking with the file system.
|
|
@@ -31,31 +31,31 @@ rename satisfies Omit<typeof Node.rename, '__promisify__'>;
|
|
|
31
31
|
* @param callback
|
|
32
32
|
* @deprecated Use {@link stat} or {@link access} instead.
|
|
33
33
|
*/
|
|
34
|
-
export function exists(path: PathLike, cb: (exists: boolean) => unknown = nop): void {
|
|
34
|
+
export function exists(path: fs.PathLike, cb: (exists: boolean) => unknown = nop): void {
|
|
35
35
|
promises
|
|
36
36
|
.exists(path)
|
|
37
37
|
.then(cb)
|
|
38
38
|
.catch(() => cb(false));
|
|
39
39
|
}
|
|
40
|
-
exists satisfies Omit<typeof
|
|
40
|
+
exists satisfies Omit<typeof fs.exists, '__promisify__'>;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Asynchronous `stat`.
|
|
44
44
|
* @param path
|
|
45
45
|
* @param callback
|
|
46
46
|
*/
|
|
47
|
-
export function stat(path: PathLike, callback: Callback<[Stats]>): void;
|
|
48
|
-
export function stat(path: PathLike, options: { bigint?: false }, callback: Callback<[Stats]>): void;
|
|
49
|
-
export function stat(path: PathLike, options: { bigint: true }, callback: Callback<[BigIntStats]>): void;
|
|
50
|
-
export function stat(path: PathLike, options:
|
|
51
|
-
export function stat(path: PathLike, options?:
|
|
47
|
+
export function stat(path: fs.PathLike, callback: Callback<[Stats]>): void;
|
|
48
|
+
export function stat(path: fs.PathLike, options: { bigint?: false }, callback: Callback<[Stats]>): void;
|
|
49
|
+
export function stat(path: fs.PathLike, options: { bigint: true }, callback: Callback<[BigIntStats]>): void;
|
|
50
|
+
export function stat(path: fs.PathLike, options: fs.StatOptions, callback: Callback<[Stats] | [BigIntStats]>): void;
|
|
51
|
+
export function stat(path: fs.PathLike, options?: fs.StatOptions | Callback<[Stats]>, callback: Callback<[Stats]> | Callback<[BigIntStats]> = nop): void {
|
|
52
52
|
callback = typeof options == 'function' ? options : callback;
|
|
53
53
|
promises
|
|
54
54
|
.stat(path, typeof options != 'function' ? options : {})
|
|
55
|
-
.then(
|
|
55
|
+
.then(stats => (<Callback<[Stats] | [BigIntStats]>>callback)(undefined, <any>stats))
|
|
56
56
|
.catch(callback);
|
|
57
57
|
}
|
|
58
|
-
stat satisfies Omit<typeof
|
|
58
|
+
stat satisfies Omit<typeof fs.stat, '__promisify__'>;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* Asynchronous `lstat`.
|
|
@@ -64,18 +64,18 @@ stat satisfies Omit<typeof Node.stat, '__promisify__'>;
|
|
|
64
64
|
* @param path
|
|
65
65
|
* @param callback
|
|
66
66
|
*/
|
|
67
|
-
export function lstat(path: PathLike, callback: Callback<[Stats]>): void;
|
|
68
|
-
export function lstat(path: PathLike, options:
|
|
69
|
-
export function lstat(path: PathLike, options:
|
|
70
|
-
export function lstat(path: PathLike, options:
|
|
71
|
-
export function lstat(path: PathLike, options?:
|
|
67
|
+
export function lstat(path: fs.PathLike, callback: Callback<[Stats]>): void;
|
|
68
|
+
export function lstat(path: fs.PathLike, options: fs.StatOptions & { bigint?: false }, callback: Callback<[Stats]>): void;
|
|
69
|
+
export function lstat(path: fs.PathLike, options: fs.StatOptions & { bigint: true }, callback: Callback<[BigIntStats]>): void;
|
|
70
|
+
export function lstat(path: fs.PathLike, options: fs.StatOptions, callback: Callback<[Stats | BigIntStats]>): void;
|
|
71
|
+
export function lstat(path: fs.PathLike, options?: fs.StatOptions | Callback<[Stats]>, callback: Callback<[Stats]> | Callback<[BigIntStats]> = nop): void {
|
|
72
72
|
callback = typeof options == 'function' ? options : callback;
|
|
73
73
|
promises
|
|
74
74
|
.lstat(path, typeof options != 'function' ? options : <object>{})
|
|
75
|
-
.then(stats => (<Callback<[Stats] | [BigIntStats]>>callback)(
|
|
75
|
+
.then(stats => (<Callback<[Stats] | [BigIntStats]>>callback)(undefined, stats))
|
|
76
76
|
.catch(callback);
|
|
77
77
|
}
|
|
78
|
-
lstat satisfies Omit<typeof
|
|
78
|
+
lstat satisfies Omit<typeof fs.lstat, '__promisify__'>;
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* Asynchronous `truncate`.
|
|
@@ -83,9 +83,9 @@ lstat satisfies Omit<typeof Node.lstat, '__promisify__'>;
|
|
|
83
83
|
* @param len
|
|
84
84
|
* @param callback
|
|
85
85
|
*/
|
|
86
|
-
export function truncate(path: PathLike, cb?: Callback): void;
|
|
87
|
-
export function truncate(path: PathLike, len: number, cb?: Callback): void;
|
|
88
|
-
export function truncate(path: PathLike, cbLen: number | Callback = 0, cb: Callback = nop): void {
|
|
86
|
+
export function truncate(path: fs.PathLike, cb?: Callback): void;
|
|
87
|
+
export function truncate(path: fs.PathLike, len: number, cb?: Callback): void;
|
|
88
|
+
export function truncate(path: fs.PathLike, cbLen: number | Callback = 0, cb: Callback = nop): void {
|
|
89
89
|
cb = typeof cbLen === 'function' ? cbLen : cb;
|
|
90
90
|
const len = typeof cbLen === 'number' ? cbLen : 0;
|
|
91
91
|
promises
|
|
@@ -93,20 +93,20 @@ export function truncate(path: PathLike, cbLen: number | Callback = 0, cb: Callb
|
|
|
93
93
|
.then(() => cb())
|
|
94
94
|
.catch(cb);
|
|
95
95
|
}
|
|
96
|
-
truncate satisfies Omit<typeof
|
|
96
|
+
truncate satisfies Omit<typeof fs.truncate, '__promisify__'>;
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* Asynchronous `unlink`.
|
|
100
100
|
* @param path
|
|
101
101
|
* @param callback
|
|
102
102
|
*/
|
|
103
|
-
export function unlink(path: PathLike, cb: Callback = nop): void {
|
|
103
|
+
export function unlink(path: fs.PathLike, cb: Callback = nop): void {
|
|
104
104
|
promises
|
|
105
105
|
.unlink(path)
|
|
106
106
|
.then(() => cb())
|
|
107
107
|
.catch(cb);
|
|
108
108
|
}
|
|
109
|
-
unlink satisfies Omit<typeof
|
|
109
|
+
unlink satisfies Omit<typeof fs.unlink, '__promisify__'>;
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* Asynchronous file open.
|
|
@@ -133,17 +133,17 @@ unlink satisfies Omit<typeof Node.unlink, '__promisify__'>;
|
|
|
133
133
|
* @param mode defaults to `0644`
|
|
134
134
|
* @param callback
|
|
135
135
|
*/
|
|
136
|
-
export function open(path: PathLike, flag: string, cb?: Callback<[number]>): void;
|
|
137
|
-
export function open(path: PathLike, flag: string, mode: number | string, cb?: Callback<[number]>): void;
|
|
138
|
-
export function open(path: PathLike, flag: string, cbMode?: number | string | Callback<[number]>, cb: Callback<[number]> = nop): void {
|
|
136
|
+
export function open(path: fs.PathLike, flag: string, cb?: Callback<[number]>): void;
|
|
137
|
+
export function open(path: fs.PathLike, flag: string, mode: number | string, cb?: Callback<[number]>): void;
|
|
138
|
+
export function open(path: fs.PathLike, flag: string, cbMode?: number | string | Callback<[number]>, cb: Callback<[number]> = nop): void {
|
|
139
139
|
const mode = normalizeMode(cbMode, 0o644);
|
|
140
140
|
cb = typeof cbMode === 'function' ? cbMode : cb;
|
|
141
141
|
promises
|
|
142
142
|
.open(path, flag, mode)
|
|
143
|
-
.then(handle => cb(
|
|
143
|
+
.then(handle => cb(undefined, handle.fd))
|
|
144
144
|
.catch(cb);
|
|
145
145
|
}
|
|
146
|
-
open satisfies Omit<typeof
|
|
146
|
+
open satisfies Omit<typeof fs.open, '__promisify__'>;
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
149
|
* Asynchronously reads the entire contents of a file.
|
|
@@ -153,18 +153,18 @@ open satisfies Omit<typeof Node.open, '__promisify__'>;
|
|
|
153
153
|
* @option options flag Defaults to `'r'`.
|
|
154
154
|
* @param callback If no encoding is specified, then the raw buffer is returned.
|
|
155
155
|
*/
|
|
156
|
-
export function readFile(filename: PathLike, cb: Callback<[Uint8Array]>): void;
|
|
157
|
-
export function readFile(filename: PathLike, options: { flag?: string }, callback?: Callback<[Uint8Array]>): void;
|
|
158
|
-
export function readFile(filename: PathLike, options: { encoding: BufferEncoding; flag?: string } | BufferEncoding, cb: Callback<[string]>): void;
|
|
159
|
-
export function readFile(filename: PathLike, options?:
|
|
156
|
+
export function readFile(filename: fs.PathLike, cb: Callback<[Uint8Array]>): void;
|
|
157
|
+
export function readFile(filename: fs.PathLike, options: { flag?: string }, callback?: Callback<[Uint8Array]>): void;
|
|
158
|
+
export function readFile(filename: fs.PathLike, options: { encoding: BufferEncoding; flag?: string } | BufferEncoding, cb: Callback<[string]>): void;
|
|
159
|
+
export function readFile(filename: fs.PathLike, options?: fs.WriteFileOptions | BufferEncoding | Callback<[Uint8Array]>, cb: Callback<[string]> | Callback<[Uint8Array]> = nop) {
|
|
160
160
|
cb = typeof options === 'function' ? options : cb;
|
|
161
161
|
|
|
162
162
|
promises
|
|
163
163
|
.readFile(filename, typeof options === 'function' ? null : options)
|
|
164
|
-
.then(data => (<Callback<[string | Uint8Array]>>cb)(
|
|
164
|
+
.then(data => (<Callback<[string | Uint8Array]>>cb)(undefined, data))
|
|
165
165
|
.catch(cb);
|
|
166
166
|
}
|
|
167
|
-
readFile satisfies Omit<typeof
|
|
167
|
+
readFile satisfies Omit<typeof fs.readFile, '__promisify__'>;
|
|
168
168
|
|
|
169
169
|
/**
|
|
170
170
|
* Asynchronously writes data to a file, replacing the file if it already
|
|
@@ -180,17 +180,17 @@ readFile satisfies Omit<typeof Node.readFile, '__promisify__'>;
|
|
|
180
180
|
* @option flag Defaults to `'w'`.
|
|
181
181
|
* @param callback
|
|
182
182
|
*/
|
|
183
|
-
export function writeFile(filename: PathLike, data: FileContents, cb?: Callback): void;
|
|
184
|
-
export function writeFile(filename: PathLike, data: FileContents, encoding?: BufferEncoding, cb?: Callback): void;
|
|
185
|
-
export function writeFile(filename: PathLike, data: FileContents, options?:
|
|
186
|
-
export function writeFile(filename: PathLike, data: FileContents, cbEncOpts?:
|
|
183
|
+
export function writeFile(filename: fs.PathLike, data: FileContents, cb?: Callback): void;
|
|
184
|
+
export function writeFile(filename: fs.PathLike, data: FileContents, encoding?: BufferEncoding, cb?: Callback): void;
|
|
185
|
+
export function writeFile(filename: fs.PathLike, data: FileContents, options?: fs.WriteFileOptions, cb?: Callback): void;
|
|
186
|
+
export function writeFile(filename: fs.PathLike, data: FileContents, cbEncOpts?: fs.WriteFileOptions | Callback, cb: Callback = nop): void {
|
|
187
187
|
cb = typeof cbEncOpts === 'function' ? cbEncOpts : cb;
|
|
188
188
|
promises
|
|
189
189
|
.writeFile(filename, data, typeof cbEncOpts != 'function' ? cbEncOpts : null)
|
|
190
|
-
.then(() => cb(
|
|
190
|
+
.then(() => cb(undefined))
|
|
191
191
|
.catch(cb);
|
|
192
192
|
}
|
|
193
|
-
writeFile satisfies Omit<typeof
|
|
193
|
+
writeFile satisfies Omit<typeof fs.writeFile, '__promisify__'>;
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
196
|
* Asynchronously append data to a file, creating the file if it not yet
|
|
@@ -204,17 +204,17 @@ writeFile satisfies Omit<typeof Node.writeFile, '__promisify__'>;
|
|
|
204
204
|
* @option flag Defaults to `'a'`.
|
|
205
205
|
* @param callback
|
|
206
206
|
*/
|
|
207
|
-
export function appendFile(filename: PathLike, data: FileContents, cb?: Callback): void;
|
|
208
|
-
export function appendFile(filename: PathLike, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }, cb?: Callback): void;
|
|
209
|
-
export function appendFile(filename: PathLike, data: FileContents, encoding?: string, cb?: Callback): void;
|
|
210
|
-
export function appendFile(filename: PathLike, data: FileContents, cbEncOpts
|
|
207
|
+
export function appendFile(filename: fs.PathLike, data: FileContents, cb?: Callback): void;
|
|
208
|
+
export function appendFile(filename: fs.PathLike, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }, cb?: Callback): void;
|
|
209
|
+
export function appendFile(filename: fs.PathLike, data: FileContents, encoding?: string, cb?: Callback): void;
|
|
210
|
+
export function appendFile(filename: fs.PathLike, data: FileContents, cbEncOpts?: any, cb: Callback = nop): void {
|
|
211
211
|
cb = typeof cbEncOpts === 'function' ? cbEncOpts : cb;
|
|
212
212
|
promises
|
|
213
213
|
.appendFile(filename, data, typeof cbEncOpts === 'function' ? null : cbEncOpts)
|
|
214
214
|
.then(() => cb())
|
|
215
215
|
.catch(cb);
|
|
216
216
|
}
|
|
217
|
-
appendFile satisfies Omit<typeof
|
|
217
|
+
appendFile satisfies Omit<typeof fs.appendFile, '__promisify__'>;
|
|
218
218
|
|
|
219
219
|
/**
|
|
220
220
|
* Asynchronous `fstat`.
|
|
@@ -224,17 +224,17 @@ appendFile satisfies Omit<typeof Node.appendFile, '__promisify__'>;
|
|
|
224
224
|
* @param callback
|
|
225
225
|
*/
|
|
226
226
|
export function fstat(fd: number, cb: Callback<[Stats]>): void;
|
|
227
|
-
export function fstat(fd: number, options:
|
|
228
|
-
export function fstat(fd: number, options:
|
|
229
|
-
export function fstat(fd: number, options?:
|
|
227
|
+
export function fstat(fd: number, options: fs.StatOptions & { bigint?: false }, cb: Callback<[Stats]>): void;
|
|
228
|
+
export function fstat(fd: number, options: fs.StatOptions & { bigint: true }, cb: Callback<[BigIntStats]>): void;
|
|
229
|
+
export function fstat(fd: number, options?: fs.StatOptions | Callback<[Stats]>, cb: Callback<[Stats]> | Callback<[BigIntStats]> = nop): void {
|
|
230
230
|
cb = typeof options == 'function' ? options : cb;
|
|
231
231
|
|
|
232
232
|
fd2file(fd)
|
|
233
233
|
.stat()
|
|
234
|
-
.then(stats => (<Callback<[Stats | BigIntStats]>>cb)(
|
|
234
|
+
.then(stats => (<Callback<[Stats | BigIntStats]>>cb)(undefined, typeof options == 'object' && options?.bigint ? new BigIntStats(stats) : stats))
|
|
235
235
|
.catch(cb);
|
|
236
236
|
}
|
|
237
|
-
fstat satisfies Omit<typeof
|
|
237
|
+
fstat satisfies Omit<typeof fs.fstat, '__promisify__'>;
|
|
238
238
|
|
|
239
239
|
/**
|
|
240
240
|
* Asynchronous close.
|
|
@@ -247,7 +247,7 @@ export function close(fd: number, cb: Callback = nop): void {
|
|
|
247
247
|
.then(() => cb())
|
|
248
248
|
.catch(cb);
|
|
249
249
|
}
|
|
250
|
-
close satisfies Omit<typeof
|
|
250
|
+
close satisfies Omit<typeof fs.close, '__promisify__'>;
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
253
|
* Asynchronous ftruncate.
|
|
@@ -257,7 +257,7 @@ close satisfies Omit<typeof Node.close, '__promisify__'>;
|
|
|
257
257
|
*/
|
|
258
258
|
export function ftruncate(fd: number, cb?: Callback): void;
|
|
259
259
|
export function ftruncate(fd: number, len?: number, cb?: Callback): void;
|
|
260
|
-
export function ftruncate(fd: number, lenOrCB
|
|
260
|
+
export function ftruncate(fd: number, lenOrCB?: any, cb: Callback = nop): void {
|
|
261
261
|
const length = typeof lenOrCB === 'number' ? lenOrCB : 0;
|
|
262
262
|
cb = typeof lenOrCB === 'function' ? lenOrCB : cb;
|
|
263
263
|
const file = fd2file(fd);
|
|
@@ -268,7 +268,7 @@ export function ftruncate(fd: number, lenOrCB?, cb: Callback = nop): void {
|
|
|
268
268
|
.then(() => cb())
|
|
269
269
|
.catch(cb);
|
|
270
270
|
}
|
|
271
|
-
ftruncate satisfies Omit<typeof
|
|
271
|
+
ftruncate satisfies Omit<typeof fs.ftruncate, '__promisify__'>;
|
|
272
272
|
|
|
273
273
|
/**
|
|
274
274
|
* Asynchronous fsync.
|
|
@@ -281,7 +281,7 @@ export function fsync(fd: number, cb: Callback = nop): void {
|
|
|
281
281
|
.then(() => cb())
|
|
282
282
|
.catch(cb);
|
|
283
283
|
}
|
|
284
|
-
fsync satisfies Omit<typeof
|
|
284
|
+
fsync satisfies Omit<typeof fs.fsync, '__promisify__'>;
|
|
285
285
|
|
|
286
286
|
/**
|
|
287
287
|
* Asynchronous fdatasync.
|
|
@@ -294,7 +294,7 @@ export function fdatasync(fd: number, cb: Callback = nop): void {
|
|
|
294
294
|
.then(() => cb())
|
|
295
295
|
.catch(cb);
|
|
296
296
|
}
|
|
297
|
-
fdatasync satisfies Omit<typeof
|
|
297
|
+
fdatasync satisfies Omit<typeof fs.fdatasync, '__promisify__'>;
|
|
298
298
|
|
|
299
299
|
/**
|
|
300
300
|
* Write buffer to the file specified by `fd`.
|
|
@@ -315,12 +315,8 @@ export function write(fd: number, buffer: Uint8Array, offset: number, length: nu
|
|
|
315
315
|
export function write(fd: number, data: FileContents, cb?: Callback<[number, string]>): void;
|
|
316
316
|
export function write(fd: number, data: FileContents, position?: number, cb?: Callback<[number, string]>): void;
|
|
317
317
|
export function write(fd: number, data: FileContents, position: number | null, encoding: BufferEncoding, cb?: Callback<[number, string]>): void;
|
|
318
|
-
export function write(fd: number, data: FileContents, cbPosOff
|
|
319
|
-
let buffer: Buffer,
|
|
320
|
-
offset: number,
|
|
321
|
-
length: number,
|
|
322
|
-
position: number | null = null,
|
|
323
|
-
encoding: BufferEncoding;
|
|
318
|
+
export function write(fd: number, data: FileContents, cbPosOff?: any, cbLenEnc?: any, cbPos?: any, cb: Callback<[number, Uint8Array]> | Callback<[number, string]> = nop): void {
|
|
319
|
+
let buffer: Buffer, offset: number, length: number, position: number | undefined | null, encoding: BufferEncoding;
|
|
324
320
|
const handle = new promises.FileHandle(fd);
|
|
325
321
|
if (typeof data === 'string') {
|
|
326
322
|
// Signature 1: (fd, string, [position?, [encoding?]], cb?)
|
|
@@ -350,22 +346,22 @@ export function write(fd: number, data: FileContents, cbPosOff?, cbLenEnc?, cbPo
|
|
|
350
346
|
|
|
351
347
|
handle
|
|
352
348
|
.write(buffer, offset, length, position)
|
|
353
|
-
.then(({ bytesWritten }) => _cb(
|
|
349
|
+
.then(({ bytesWritten }) => _cb(undefined, bytesWritten, buffer.toString(encoding)))
|
|
354
350
|
.catch(_cb);
|
|
355
351
|
} else {
|
|
356
352
|
// Signature 2: (fd, buffer, offset, length, position?, cb?)
|
|
357
|
-
buffer = Buffer.from(data);
|
|
353
|
+
buffer = Buffer.from(data.buffer);
|
|
358
354
|
offset = cbPosOff;
|
|
359
355
|
length = cbLenEnc;
|
|
360
356
|
position = typeof cbPos === 'number' ? cbPos : null;
|
|
361
357
|
const _cb = <Callback<[number, Uint8Array]>>(typeof cbPos === 'function' ? cbPos : cb);
|
|
362
358
|
handle
|
|
363
359
|
.write(buffer, offset, length, position)
|
|
364
|
-
.then(({ bytesWritten }) => _cb(
|
|
360
|
+
.then(({ bytesWritten }) => _cb(undefined, bytesWritten, buffer))
|
|
365
361
|
.catch(_cb);
|
|
366
362
|
}
|
|
367
363
|
}
|
|
368
|
-
write satisfies Omit<typeof
|
|
364
|
+
write satisfies Omit<typeof fs.write, '__promisify__'>;
|
|
369
365
|
|
|
370
366
|
/**
|
|
371
367
|
* Read data from the file specified by `fd`.
|
|
@@ -382,10 +378,10 @@ write satisfies Omit<typeof Node.write, '__promisify__'>;
|
|
|
382
378
|
export function read(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number, cb: Callback<[number, Uint8Array]> = nop): void {
|
|
383
379
|
new promises.FileHandle(fd)
|
|
384
380
|
.read(buffer, offset, length, position)
|
|
385
|
-
.then(({ bytesRead, buffer }) => cb(
|
|
381
|
+
.then(({ bytesRead, buffer }) => cb(undefined, bytesRead, buffer))
|
|
386
382
|
.catch(cb);
|
|
387
383
|
}
|
|
388
|
-
read satisfies Omit<typeof
|
|
384
|
+
read satisfies Omit<typeof fs.read, '__promisify__'>;
|
|
389
385
|
|
|
390
386
|
/**
|
|
391
387
|
* Asynchronous `fchown`.
|
|
@@ -400,7 +396,7 @@ export function fchown(fd: number, uid: number, gid: number, cb: Callback = nop)
|
|
|
400
396
|
.then(() => cb())
|
|
401
397
|
.catch(cb);
|
|
402
398
|
}
|
|
403
|
-
fchown satisfies Omit<typeof
|
|
399
|
+
fchown satisfies Omit<typeof fs.fchown, '__promisify__'>;
|
|
404
400
|
|
|
405
401
|
/**
|
|
406
402
|
* Asynchronous `fchmod`.
|
|
@@ -414,7 +410,7 @@ export function fchmod(fd: number, mode: string | number, cb: Callback): void {
|
|
|
414
410
|
.then(() => cb())
|
|
415
411
|
.catch(cb);
|
|
416
412
|
}
|
|
417
|
-
fchmod satisfies Omit<typeof
|
|
413
|
+
fchmod satisfies Omit<typeof fs.fchmod, '__promisify__'>;
|
|
418
414
|
|
|
419
415
|
/**
|
|
420
416
|
* Change the file timestamps of a file referenced by the supplied file
|
|
@@ -430,20 +426,20 @@ export function futimes(fd: number, atime: number | Date, mtime: number | Date,
|
|
|
430
426
|
.then(() => cb())
|
|
431
427
|
.catch(cb);
|
|
432
428
|
}
|
|
433
|
-
futimes satisfies Omit<typeof
|
|
429
|
+
futimes satisfies Omit<typeof fs.futimes, '__promisify__'>;
|
|
434
430
|
|
|
435
431
|
/**
|
|
436
432
|
* Asynchronous `rmdir`.
|
|
437
433
|
* @param path
|
|
438
434
|
* @param callback
|
|
439
435
|
*/
|
|
440
|
-
export function rmdir(path: PathLike, cb: Callback = nop): void {
|
|
436
|
+
export function rmdir(path: fs.PathLike, cb: Callback = nop): void {
|
|
441
437
|
promises
|
|
442
438
|
.rmdir(path)
|
|
443
439
|
.then(() => cb())
|
|
444
440
|
.catch(cb);
|
|
445
441
|
}
|
|
446
|
-
rmdir satisfies Omit<typeof
|
|
442
|
+
rmdir satisfies Omit<typeof fs.rmdir, '__promisify__'>;
|
|
447
443
|
|
|
448
444
|
/**
|
|
449
445
|
* Asynchronous `mkdir`.
|
|
@@ -451,13 +447,13 @@ rmdir satisfies Omit<typeof Node.rmdir, '__promisify__'>;
|
|
|
451
447
|
* @param mode defaults to `0777`
|
|
452
448
|
* @param callback
|
|
453
449
|
*/
|
|
454
|
-
export function mkdir(path: PathLike, mode?:
|
|
450
|
+
export function mkdir(path: fs.PathLike, mode?: fs.Mode, cb: Callback = nop): void {
|
|
455
451
|
promises
|
|
456
452
|
.mkdir(path, mode)
|
|
457
453
|
.then(() => cb())
|
|
458
454
|
.catch(cb);
|
|
459
455
|
}
|
|
460
|
-
mkdir satisfies Omit<typeof
|
|
456
|
+
mkdir satisfies Omit<typeof fs.mkdir, '__promisify__'>;
|
|
461
457
|
|
|
462
458
|
/**
|
|
463
459
|
* Asynchronous `readdir`. Reads the contents of a directory.
|
|
@@ -466,19 +462,19 @@ mkdir satisfies Omit<typeof Node.mkdir, '__promisify__'>;
|
|
|
466
462
|
* @param path
|
|
467
463
|
* @param callback
|
|
468
464
|
*/
|
|
469
|
-
export function readdir(path: PathLike, cb: Callback<[string[]]>): void;
|
|
470
|
-
export function readdir(path: PathLike, options: { withFileTypes?: false }, cb: Callback<[string[]]>): void;
|
|
471
|
-
export function readdir(path: PathLike, options: { withFileTypes: true }, cb: Callback<[Dirent[]]>): void;
|
|
472
|
-
export function readdir(path: PathLike, _options: { withFileTypes?: boolean } | Callback<[string[]]>, cb: Callback<[string[]]> | Callback<[Dirent[]]> = nop): void {
|
|
465
|
+
export function readdir(path: fs.PathLike, cb: Callback<[string[]]>): void;
|
|
466
|
+
export function readdir(path: fs.PathLike, options: { withFileTypes?: false }, cb: Callback<[string[]]>): void;
|
|
467
|
+
export function readdir(path: fs.PathLike, options: { withFileTypes: true }, cb: Callback<[Dirent[]]>): void;
|
|
468
|
+
export function readdir(path: fs.PathLike, _options: { withFileTypes?: boolean } | Callback<[string[]]>, cb: Callback<[string[]]> | Callback<[Dirent[]]> = nop): void {
|
|
473
469
|
cb = typeof _options == 'function' ? _options : cb;
|
|
474
470
|
const options = typeof _options != 'function' ? _options : {};
|
|
475
471
|
promises
|
|
476
472
|
.readdir(path, options as object)
|
|
477
473
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
478
|
-
.then(entries => cb(
|
|
474
|
+
.then(entries => cb(undefined, entries as any))
|
|
479
475
|
.catch(cb);
|
|
480
476
|
}
|
|
481
|
-
readdir satisfies Omit<typeof
|
|
477
|
+
readdir satisfies Omit<typeof fs.readdir, '__promisify__'>;
|
|
482
478
|
|
|
483
479
|
/**
|
|
484
480
|
* Asynchronous `link`.
|
|
@@ -486,13 +482,13 @@ readdir satisfies Omit<typeof Node.readdir, '__promisify__'>;
|
|
|
486
482
|
* @param newpath
|
|
487
483
|
* @param callback
|
|
488
484
|
*/
|
|
489
|
-
export function link(existing: PathLike, newpath: PathLike, cb: Callback = nop): void {
|
|
485
|
+
export function link(existing: fs.PathLike, newpath: fs.PathLike, cb: Callback = nop): void {
|
|
490
486
|
promises
|
|
491
487
|
.link(existing, newpath)
|
|
492
488
|
.then(() => cb())
|
|
493
489
|
.catch(cb);
|
|
494
490
|
}
|
|
495
|
-
link satisfies Omit<typeof
|
|
491
|
+
link satisfies Omit<typeof fs.link, '__promisify__'>;
|
|
496
492
|
|
|
497
493
|
/**
|
|
498
494
|
* Asynchronous `symlink`.
|
|
@@ -501,9 +497,9 @@ link satisfies Omit<typeof Node.link, '__promisify__'>;
|
|
|
501
497
|
* @param type can be either `'dir'` or `'file'` (default is `'file'`)
|
|
502
498
|
* @param callback
|
|
503
499
|
*/
|
|
504
|
-
export function symlink(target: PathLike, path: PathLike, cb?: Callback): void;
|
|
505
|
-
export function symlink(target: PathLike, path: PathLike, type?:
|
|
506
|
-
export function symlink(target: PathLike, path: PathLike, typeOrCB?:
|
|
500
|
+
export function symlink(target: fs.PathLike, path: fs.PathLike, cb?: Callback): void;
|
|
501
|
+
export function symlink(target: fs.PathLike, path: fs.PathLike, type?: fs.symlink.Type, cb?: Callback): void;
|
|
502
|
+
export function symlink(target: fs.PathLike, path: fs.PathLike, typeOrCB?: fs.symlink.Type | Callback, cb: Callback = nop): void {
|
|
507
503
|
const type = typeof typeOrCB === 'string' ? typeOrCB : 'file';
|
|
508
504
|
cb = typeof typeOrCB === 'function' ? typeOrCB : cb;
|
|
509
505
|
promises
|
|
@@ -511,29 +507,29 @@ export function symlink(target: PathLike, path: PathLike, typeOrCB?: Node.symlin
|
|
|
511
507
|
.then(() => cb())
|
|
512
508
|
.catch(cb);
|
|
513
509
|
}
|
|
514
|
-
symlink satisfies Omit<typeof
|
|
510
|
+
symlink satisfies Omit<typeof fs.symlink, '__promisify__'>;
|
|
515
511
|
|
|
516
512
|
/**
|
|
517
513
|
* Asynchronous readlink.
|
|
518
514
|
* @param path
|
|
519
515
|
* @param callback
|
|
520
516
|
*/
|
|
521
|
-
export function readlink(path: PathLike, callback: Callback<[string]> & any): void;
|
|
522
|
-
export function readlink(path: PathLike, options:
|
|
523
|
-
export function readlink(path: PathLike, options:
|
|
524
|
-
export function readlink(path: PathLike, options:
|
|
517
|
+
export function readlink(path: fs.PathLike, callback: Callback<[string]> & any): void;
|
|
518
|
+
export function readlink(path: fs.PathLike, options: fs.BufferEncodingOption, callback: Callback<[Uint8Array]>): void;
|
|
519
|
+
export function readlink(path: fs.PathLike, options: fs.EncodingOption, callback: Callback<[string | Uint8Array]>): void;
|
|
520
|
+
export function readlink(path: fs.PathLike, options: fs.EncodingOption, callback: Callback<[string]>): void;
|
|
525
521
|
export function readlink(
|
|
526
|
-
path: PathLike,
|
|
527
|
-
options:
|
|
522
|
+
path: fs.PathLike,
|
|
523
|
+
options: fs.BufferEncodingOption | fs.EncodingOption | Callback<[string]>,
|
|
528
524
|
callback: Callback<[string]> | Callback<[Uint8Array]> = nop
|
|
529
525
|
): void {
|
|
530
526
|
callback = typeof options == 'function' ? options : callback;
|
|
531
527
|
promises
|
|
532
528
|
.readlink(path)
|
|
533
|
-
.then(result => (<Callback<[string | Uint8Array]>>callback)(
|
|
529
|
+
.then(result => (<Callback<[string | Uint8Array]>>callback)(undefined, result))
|
|
534
530
|
.catch(callback);
|
|
535
531
|
}
|
|
536
|
-
readlink satisfies Omit<typeof
|
|
532
|
+
readlink satisfies Omit<typeof fs.readlink, '__promisify__'>;
|
|
537
533
|
|
|
538
534
|
/**
|
|
539
535
|
* Asynchronous `chown`.
|
|
@@ -542,13 +538,13 @@ readlink satisfies Omit<typeof Node.readlink, '__promisify__'>;
|
|
|
542
538
|
* @param gid
|
|
543
539
|
* @param callback
|
|
544
540
|
*/
|
|
545
|
-
export function chown(path: PathLike, uid: number, gid: number, cb: Callback = nop): void {
|
|
541
|
+
export function chown(path: fs.PathLike, uid: number, gid: number, cb: Callback = nop): void {
|
|
546
542
|
promises
|
|
547
543
|
.chown(path, uid, gid)
|
|
548
544
|
.then(() => cb())
|
|
549
545
|
.catch(cb);
|
|
550
546
|
}
|
|
551
|
-
chown satisfies Omit<typeof
|
|
547
|
+
chown satisfies Omit<typeof fs.chown, '__promisify__'>;
|
|
552
548
|
|
|
553
549
|
/**
|
|
554
550
|
* Asynchronous `lchown`.
|
|
@@ -557,13 +553,13 @@ chown satisfies Omit<typeof Node.chown, '__promisify__'>;
|
|
|
557
553
|
* @param gid
|
|
558
554
|
* @param callback
|
|
559
555
|
*/
|
|
560
|
-
export function lchown(path: PathLike, uid: number, gid: number, cb: Callback = nop): void {
|
|
556
|
+
export function lchown(path: fs.PathLike, uid: number, gid: number, cb: Callback = nop): void {
|
|
561
557
|
promises
|
|
562
558
|
.lchown(path, uid, gid)
|
|
563
559
|
.then(() => cb())
|
|
564
560
|
.catch(cb);
|
|
565
561
|
}
|
|
566
|
-
lchown satisfies Omit<typeof
|
|
562
|
+
lchown satisfies Omit<typeof fs.lchown, '__promisify__'>;
|
|
567
563
|
|
|
568
564
|
/**
|
|
569
565
|
* Asynchronous `chmod`.
|
|
@@ -571,13 +567,13 @@ lchown satisfies Omit<typeof Node.lchown, '__promisify__'>;
|
|
|
571
567
|
* @param mode
|
|
572
568
|
* @param callback
|
|
573
569
|
*/
|
|
574
|
-
export function chmod(path: PathLike, mode: number | string, cb: Callback = nop): void {
|
|
570
|
+
export function chmod(path: fs.PathLike, mode: number | string, cb: Callback = nop): void {
|
|
575
571
|
promises
|
|
576
572
|
.chmod(path, mode)
|
|
577
573
|
.then(() => cb())
|
|
578
574
|
.catch(cb);
|
|
579
575
|
}
|
|
580
|
-
chmod satisfies Omit<typeof
|
|
576
|
+
chmod satisfies Omit<typeof fs.chmod, '__promisify__'>;
|
|
581
577
|
|
|
582
578
|
/**
|
|
583
579
|
* Asynchronous `lchmod`.
|
|
@@ -585,13 +581,13 @@ chmod satisfies Omit<typeof Node.chmod, '__promisify__'>;
|
|
|
585
581
|
* @param mode
|
|
586
582
|
* @param callback
|
|
587
583
|
*/
|
|
588
|
-
export function lchmod(path: PathLike, mode: number | string, cb: Callback = nop): void {
|
|
584
|
+
export function lchmod(path: fs.PathLike, mode: number | string, cb: Callback = nop): void {
|
|
589
585
|
promises
|
|
590
586
|
.lchmod(path, mode)
|
|
591
587
|
.then(() => cb())
|
|
592
588
|
.catch(cb);
|
|
593
589
|
}
|
|
594
|
-
lchmod satisfies Omit<typeof
|
|
590
|
+
lchmod satisfies Omit<typeof fs.lchmod, '__promisify__'>;
|
|
595
591
|
|
|
596
592
|
/**
|
|
597
593
|
* Change file timestamps of the file referenced by the supplied path.
|
|
@@ -600,13 +596,13 @@ lchmod satisfies Omit<typeof Node.lchmod, '__promisify__'>;
|
|
|
600
596
|
* @param mtime
|
|
601
597
|
* @param callback
|
|
602
598
|
*/
|
|
603
|
-
export function utimes(path: PathLike, atime: number | Date, mtime: number | Date, cb: Callback = nop): void {
|
|
599
|
+
export function utimes(path: fs.PathLike, atime: number | Date, mtime: number | Date, cb: Callback = nop): void {
|
|
604
600
|
promises
|
|
605
601
|
.utimes(path, atime, mtime)
|
|
606
602
|
.then(() => cb())
|
|
607
603
|
.catch(cb);
|
|
608
604
|
}
|
|
609
|
-
utimes satisfies Omit<typeof
|
|
605
|
+
utimes satisfies Omit<typeof fs.utimes, '__promisify__'>;
|
|
610
606
|
|
|
611
607
|
/**
|
|
612
608
|
* Change file timestamps of the file referenced by the supplied path.
|
|
@@ -615,13 +611,13 @@ utimes satisfies Omit<typeof Node.utimes, '__promisify__'>;
|
|
|
615
611
|
* @param mtime
|
|
616
612
|
* @param callback
|
|
617
613
|
*/
|
|
618
|
-
export function lutimes(path: PathLike, atime: number | Date, mtime: number | Date, cb: Callback = nop): void {
|
|
614
|
+
export function lutimes(path: fs.PathLike, atime: number | Date, mtime: number | Date, cb: Callback = nop): void {
|
|
619
615
|
promises
|
|
620
616
|
.lutimes(path, atime, mtime)
|
|
621
617
|
.then(() => cb())
|
|
622
618
|
.catch(cb);
|
|
623
619
|
}
|
|
624
|
-
lutimes satisfies Omit<typeof
|
|
620
|
+
lutimes satisfies Omit<typeof fs.lutimes, '__promisify__'>;
|
|
625
621
|
|
|
626
622
|
/**
|
|
627
623
|
* Asynchronous `realpath`. The callback gets two arguments
|
|
@@ -630,16 +626,16 @@ lutimes satisfies Omit<typeof Node.lutimes, '__promisify__'>;
|
|
|
630
626
|
* @param path
|
|
631
627
|
* @param callback
|
|
632
628
|
*/
|
|
633
|
-
export function realpath(path: PathLike, cb?: Callback<[string]>): void;
|
|
634
|
-
export function realpath(path: PathLike, options:
|
|
635
|
-
export function realpath(path: PathLike, arg2?: Callback<[string]> |
|
|
629
|
+
export function realpath(path: fs.PathLike, cb?: Callback<[string]>): void;
|
|
630
|
+
export function realpath(path: fs.PathLike, options: fs.EncodingOption, cb: Callback<[string]>): void;
|
|
631
|
+
export function realpath(path: fs.PathLike, arg2?: Callback<[string]> | fs.EncodingOption, cb: Callback<[string]> = nop): void {
|
|
636
632
|
cb = typeof arg2 === 'function' ? arg2 : cb;
|
|
637
633
|
promises
|
|
638
634
|
.realpath(path, typeof arg2 === 'function' ? null : arg2)
|
|
639
|
-
.then(result => cb(
|
|
635
|
+
.then(result => cb(undefined, result))
|
|
640
636
|
.catch(cb);
|
|
641
637
|
}
|
|
642
|
-
realpath satisfies Omit<typeof
|
|
638
|
+
realpath satisfies Omit<typeof fs.realpath, '__promisify__' | 'native'>;
|
|
643
639
|
|
|
644
640
|
/**
|
|
645
641
|
* Asynchronous `access`.
|
|
@@ -647,9 +643,9 @@ realpath satisfies Omit<typeof Node.realpath, '__promisify__' | 'native'>;
|
|
|
647
643
|
* @param mode
|
|
648
644
|
* @param callback
|
|
649
645
|
*/
|
|
650
|
-
export function access(path: PathLike, cb: Callback): void;
|
|
651
|
-
export function access(path: PathLike, mode: number, cb: Callback): void;
|
|
652
|
-
export function access(path: PathLike, cbMode, cb: Callback = nop): void {
|
|
646
|
+
export function access(path: fs.PathLike, cb: Callback): void;
|
|
647
|
+
export function access(path: fs.PathLike, mode: number, cb: Callback): void;
|
|
648
|
+
export function access(path: fs.PathLike, cbMode: any, cb: Callback = nop): void {
|
|
653
649
|
const mode = typeof cbMode === 'number' ? cbMode : R_OK;
|
|
654
650
|
cb = typeof cbMode === 'function' ? cbMode : cb;
|
|
655
651
|
promises
|
|
@@ -657,35 +653,35 @@ export function access(path: PathLike, cbMode, cb: Callback = nop): void {
|
|
|
657
653
|
.then(() => cb())
|
|
658
654
|
.catch(cb);
|
|
659
655
|
}
|
|
660
|
-
access satisfies Omit<typeof
|
|
656
|
+
access satisfies Omit<typeof fs.access, '__promisify__'>;
|
|
661
657
|
|
|
662
658
|
/**
|
|
663
659
|
* @todo Implement
|
|
664
660
|
*/
|
|
665
|
-
export function watchFile(
|
|
666
|
-
export function watchFile(
|
|
667
|
-
export function watchFile(
|
|
668
|
-
throw ApiError.With('ENOSYS',
|
|
661
|
+
export function watchFile(path: fs.PathLike, listener: (curr: Stats, prev: Stats) => void): void;
|
|
662
|
+
export function watchFile(path: fs.PathLike, options: { persistent?: boolean; interval?: number }, listener: (curr: Stats, prev: Stats) => void): void;
|
|
663
|
+
export function watchFile(path: fs.PathLike, optsListener: any, listener: (curr: Stats, prev: Stats) => void = nop): void {
|
|
664
|
+
throw ApiError.With('ENOSYS', path.toString(), 'watchFile');
|
|
669
665
|
}
|
|
670
|
-
watchFile satisfies Omit<typeof
|
|
666
|
+
watchFile satisfies Omit<typeof fs.watchFile, '__promisify__'>;
|
|
671
667
|
|
|
672
668
|
/**
|
|
673
669
|
* @todo Implement
|
|
674
670
|
*/
|
|
675
|
-
export function unwatchFile(
|
|
676
|
-
throw ApiError.With('ENOSYS',
|
|
671
|
+
export function unwatchFile(path: fs.PathLike, listener: (curr: Stats, prev: Stats) => void = nop): void {
|
|
672
|
+
throw ApiError.With('ENOSYS', path.toString(), 'unwatchFile');
|
|
677
673
|
}
|
|
678
|
-
unwatchFile satisfies Omit<typeof
|
|
674
|
+
unwatchFile satisfies Omit<typeof fs.unwatchFile, '__promisify__'>;
|
|
679
675
|
|
|
680
676
|
/**
|
|
681
677
|
* @todo Implement
|
|
682
678
|
*/
|
|
683
|
-
export function watch(
|
|
684
|
-
export function watch(
|
|
685
|
-
export function watch(
|
|
686
|
-
throw ApiError.With('ENOSYS',
|
|
679
|
+
export function watch(path: fs.PathLike, listener?: (event: string, filename: string) => any): fs.FSWatcher;
|
|
680
|
+
export function watch(path: fs.PathLike, options: { persistent?: boolean }, listener?: (event: string, filename: string) => any): fs.FSWatcher;
|
|
681
|
+
export function watch(path: fs.PathLike, options: any, listener: (event: string, filename: string) => any = nop): fs.FSWatcher {
|
|
682
|
+
throw ApiError.With('ENOSYS', path.toString(), 'watch');
|
|
687
683
|
}
|
|
688
|
-
watch satisfies Omit<typeof
|
|
684
|
+
watch satisfies Omit<typeof fs.watch, '__promisify__'>;
|
|
689
685
|
|
|
690
686
|
// From @types/node/fs (these types are not exported)
|
|
691
687
|
interface StreamOptions {
|
|
@@ -700,19 +696,19 @@ interface StreamOptions {
|
|
|
700
696
|
highWaterMark?: number;
|
|
701
697
|
}
|
|
702
698
|
interface FSImplementation {
|
|
703
|
-
open?: (...args) => unknown;
|
|
704
|
-
close?: (...args) => unknown;
|
|
699
|
+
open?: (...args: unknown[]) => unknown;
|
|
700
|
+
close?: (...args: unknown[]) => unknown;
|
|
705
701
|
}
|
|
706
702
|
interface ReadStreamOptions extends StreamOptions {
|
|
707
703
|
fs?: FSImplementation & {
|
|
708
|
-
read: (...args) => unknown;
|
|
704
|
+
read: (...args: unknown[]) => unknown;
|
|
709
705
|
};
|
|
710
706
|
end?: number;
|
|
711
707
|
}
|
|
712
708
|
interface WriteStreamOptions extends StreamOptions {
|
|
713
709
|
fs?: FSImplementation & {
|
|
714
|
-
write: (...args) => unknown;
|
|
715
|
-
writev?: (...args) => unknown;
|
|
710
|
+
write: (...args: unknown[]) => unknown;
|
|
711
|
+
writev?: (...args: unknown[]) => unknown;
|
|
716
712
|
};
|
|
717
713
|
flush?: boolean;
|
|
718
714
|
}
|
|
@@ -724,7 +720,7 @@ interface WriteStreamOptions extends StreamOptions {
|
|
|
724
720
|
* @param options Options for the ReadStream and file opening (e.g., `encoding`, `highWaterMark`, `mode`).
|
|
725
721
|
* @returns A ReadStream object for interacting with the file's contents.
|
|
726
722
|
*/
|
|
727
|
-
export function createReadStream(path: PathLike, _options?: BufferEncoding | ReadStreamOptions): ReadStream {
|
|
723
|
+
export function createReadStream(path: fs.PathLike, _options?: BufferEncoding | ReadStreamOptions): ReadStream {
|
|
728
724
|
const options = typeof _options == 'object' ? _options : { encoding: _options };
|
|
729
725
|
let handle: promises.FileHandle;
|
|
730
726
|
const stream = new ReadStream({
|
|
@@ -739,7 +735,7 @@ export function createReadStream(path: PathLike, _options?: BufferEncoding | Rea
|
|
|
739
735
|
if (!result.bytesRead) {
|
|
740
736
|
await handle.close();
|
|
741
737
|
}
|
|
742
|
-
} catch (error) {
|
|
738
|
+
} catch (error: any) {
|
|
743
739
|
await handle?.close();
|
|
744
740
|
stream.destroy(error);
|
|
745
741
|
}
|
|
@@ -752,10 +748,10 @@ export function createReadStream(path: PathLike, _options?: BufferEncoding | Rea
|
|
|
752
748
|
},
|
|
753
749
|
});
|
|
754
750
|
|
|
755
|
-
stream.path = path;
|
|
751
|
+
stream.path = path.toString();
|
|
756
752
|
return stream;
|
|
757
753
|
}
|
|
758
|
-
createReadStream satisfies Omit<typeof
|
|
754
|
+
createReadStream satisfies Omit<typeof fs.createReadStream, '__promisify__'>;
|
|
759
755
|
|
|
760
756
|
/**
|
|
761
757
|
* Opens a file in write mode and creates a Node.js-like WriteStream.
|
|
@@ -764,7 +760,7 @@ createReadStream satisfies Omit<typeof Node.createReadStream, '__promisify__'>;
|
|
|
764
760
|
* @param options Options for the WriteStream and file opening (e.g., `encoding`, `highWaterMark`, `mode`).
|
|
765
761
|
* @returns A WriteStream object for writing to the file.
|
|
766
762
|
*/
|
|
767
|
-
export function createWriteStream(path: PathLike, _options?: BufferEncoding | WriteStreamOptions): WriteStream {
|
|
763
|
+
export function createWriteStream(path: fs.PathLike, _options?: BufferEncoding | WriteStreamOptions): WriteStream {
|
|
768
764
|
const options = typeof _options == 'object' ? _options : { encoding: _options };
|
|
769
765
|
let handle: promises.FileHandle;
|
|
770
766
|
const stream = new WriteStream({
|
|
@@ -772,9 +768,9 @@ export function createWriteStream(path: PathLike, _options?: BufferEncoding | Wr
|
|
|
772
768
|
async write(chunk: Uint8Array, encoding: BufferEncoding, callback: (error?: Error) => void) {
|
|
773
769
|
try {
|
|
774
770
|
handle ||= await promises.open(path, 'w', options?.mode || 0o666);
|
|
775
|
-
await handle.write(chunk,
|
|
776
|
-
callback(
|
|
777
|
-
} catch (error) {
|
|
771
|
+
await handle.write(chunk, 0, encoding);
|
|
772
|
+
callback(undefined);
|
|
773
|
+
} catch (error: any) {
|
|
778
774
|
await handle?.close();
|
|
779
775
|
callback(error);
|
|
780
776
|
}
|
|
@@ -794,52 +790,48 @@ export function createWriteStream(path: PathLike, _options?: BufferEncoding | Wr
|
|
|
794
790
|
},
|
|
795
791
|
});
|
|
796
792
|
|
|
797
|
-
stream.path = path;
|
|
793
|
+
stream.path = path.toString();
|
|
798
794
|
return stream;
|
|
799
795
|
}
|
|
800
|
-
createWriteStream satisfies Omit<typeof
|
|
796
|
+
createWriteStream satisfies Omit<typeof fs.createWriteStream, '__promisify__'>;
|
|
801
797
|
|
|
802
|
-
export function rm(path: PathLike, callback: Callback): void;
|
|
803
|
-
export function rm(path: PathLike, options:
|
|
804
|
-
export function rm(path: PathLike, options:
|
|
798
|
+
export function rm(path: fs.PathLike, callback: Callback): void;
|
|
799
|
+
export function rm(path: fs.PathLike, options: fs.RmOptions, callback: Callback): void;
|
|
800
|
+
export function rm(path: fs.PathLike, options: fs.RmOptions | Callback, callback: Callback = nop): void {
|
|
805
801
|
callback = typeof options === 'function' ? options : callback;
|
|
806
802
|
promises
|
|
807
|
-
.rm(path, typeof options === 'function' ?
|
|
808
|
-
.then(() => callback(
|
|
803
|
+
.rm(path, typeof options === 'function' ? undefined : options)
|
|
804
|
+
.then(() => callback(undefined))
|
|
809
805
|
.catch(callback);
|
|
810
806
|
}
|
|
811
|
-
rm satisfies Omit<typeof
|
|
807
|
+
rm satisfies Omit<typeof fs.rm, '__promisify__'>;
|
|
812
808
|
|
|
813
809
|
/**
|
|
814
810
|
* Asynchronously creates a unique temporary directory.
|
|
815
811
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
816
812
|
*/
|
|
817
813
|
export function mkdtemp(prefix: string, callback: Callback<[string]>): void;
|
|
818
|
-
export function mkdtemp(prefix: string, options:
|
|
819
|
-
export function mkdtemp(prefix: string, options:
|
|
820
|
-
export function mkdtemp(
|
|
821
|
-
prefix: string,
|
|
822
|
-
options: Node.EncodingOption | Node.BufferEncodingOption | Callback<[string]>,
|
|
823
|
-
callback: Callback<[Buffer]> | Callback<[string]> = nop
|
|
824
|
-
): void {
|
|
814
|
+
export function mkdtemp(prefix: string, options: fs.EncodingOption, callback: Callback<[string]>): void;
|
|
815
|
+
export function mkdtemp(prefix: string, options: fs.BufferEncodingOption, callback: Callback<[Buffer]>): void;
|
|
816
|
+
export function mkdtemp(prefix: string, options: fs.EncodingOption | fs.BufferEncodingOption | Callback<[string]>, callback: Callback<[Buffer]> | Callback<[string]> = nop): void {
|
|
825
817
|
callback = typeof options === 'function' ? options : callback;
|
|
826
818
|
promises
|
|
827
|
-
.mkdtemp(prefix, typeof options != 'function' ? <
|
|
828
|
-
.then(result => (<Callback<[string | Buffer]>>callback)(
|
|
819
|
+
.mkdtemp(prefix, typeof options != 'function' ? <fs.EncodingOption>options : null)
|
|
820
|
+
.then(result => (<Callback<[string | Buffer]>>callback)(undefined, result))
|
|
829
821
|
.catch(callback);
|
|
830
822
|
}
|
|
831
|
-
mkdtemp satisfies Omit<typeof
|
|
823
|
+
mkdtemp satisfies Omit<typeof fs.mkdtemp, '__promisify__'>;
|
|
832
824
|
|
|
833
|
-
export function copyFile(src: PathLike, dest: PathLike, callback: Callback): void;
|
|
834
|
-
export function copyFile(src: PathLike, dest: PathLike, flags: number, callback: Callback): void;
|
|
835
|
-
export function copyFile(src: PathLike, dest: PathLike, flags: number | Callback, callback
|
|
825
|
+
export function copyFile(src: fs.PathLike, dest: fs.PathLike, callback: Callback): void;
|
|
826
|
+
export function copyFile(src: fs.PathLike, dest: fs.PathLike, flags: number, callback: Callback): void;
|
|
827
|
+
export function copyFile(src: fs.PathLike, dest: fs.PathLike, flags: number | Callback, callback: Callback = nop): void {
|
|
836
828
|
callback = typeof flags === 'function' ? flags : callback;
|
|
837
829
|
promises
|
|
838
|
-
.copyFile(src, dest, typeof flags === 'function' ?
|
|
839
|
-
.then(() => callback(
|
|
830
|
+
.copyFile(src, dest, typeof flags === 'function' ? undefined : flags)
|
|
831
|
+
.then(() => callback(undefined))
|
|
840
832
|
.catch(callback);
|
|
841
833
|
}
|
|
842
|
-
copyFile satisfies Omit<typeof
|
|
834
|
+
copyFile satisfies Omit<typeof fs.copyFile, '__promisify__'>;
|
|
843
835
|
|
|
844
836
|
type readvCb = Callback<[number, NodeJS.ArrayBufferView[]]>;
|
|
845
837
|
|
|
@@ -848,11 +840,11 @@ export function readv(fd: number, buffers: NodeJS.ArrayBufferView[], position: n
|
|
|
848
840
|
export function readv(fd: number, buffers: NodeJS.ArrayBufferView[], position: number | readvCb, cb: readvCb = nop): void {
|
|
849
841
|
cb = typeof position === 'function' ? position : cb;
|
|
850
842
|
new promises.FileHandle(fd)
|
|
851
|
-
.readv(buffers, typeof position === 'function' ?
|
|
852
|
-
.then(({ buffers, bytesRead }) => cb(
|
|
843
|
+
.readv(buffers, typeof position === 'function' ? undefined : position)
|
|
844
|
+
.then(({ buffers, bytesRead }) => cb(undefined, bytesRead, buffers))
|
|
853
845
|
.catch(cb);
|
|
854
846
|
}
|
|
855
|
-
readv satisfies Omit<typeof
|
|
847
|
+
readv satisfies Omit<typeof fs.readv, '__promisify__'>;
|
|
856
848
|
|
|
857
849
|
type writevCb = Callback<[number, NodeJS.ArrayBufferView[]]>;
|
|
858
850
|
|
|
@@ -861,50 +853,50 @@ export function writev(fd: number, buffers: Uint8Array[], position: number, cb:
|
|
|
861
853
|
export function writev(fd: number, buffers: Uint8Array[], position: number | writevCb, cb: writevCb = nop) {
|
|
862
854
|
cb = typeof position === 'function' ? position : cb;
|
|
863
855
|
new promises.FileHandle(fd)
|
|
864
|
-
.writev(buffers, typeof position === 'function' ?
|
|
865
|
-
.then(({ buffers, bytesWritten }) => cb(
|
|
856
|
+
.writev(buffers, typeof position === 'function' ? undefined : position)
|
|
857
|
+
.then(({ buffers, bytesWritten }) => cb(undefined, bytesWritten, buffers))
|
|
866
858
|
.catch(cb);
|
|
867
859
|
}
|
|
868
|
-
writev satisfies Omit<typeof
|
|
860
|
+
writev satisfies Omit<typeof fs.writev, '__promisify__'>;
|
|
869
861
|
|
|
870
|
-
export function opendir(path: PathLike, cb: Callback<[Dir]>): void;
|
|
871
|
-
export function opendir(path: PathLike, options:
|
|
872
|
-
export function opendir(path: PathLike, options:
|
|
862
|
+
export function opendir(path: fs.PathLike, cb: Callback<[Dir]>): void;
|
|
863
|
+
export function opendir(path: fs.PathLike, options: fs.OpenDirOptions, cb: Callback<[Dir]>): void;
|
|
864
|
+
export function opendir(path: fs.PathLike, options: fs.OpenDirOptions | Callback<[Dir]>, cb: Callback<[Dir]> = nop): void {
|
|
873
865
|
cb = typeof options === 'function' ? options : cb;
|
|
874
866
|
promises
|
|
875
|
-
.opendir(path, typeof options === 'function' ?
|
|
876
|
-
.then(result => cb(
|
|
867
|
+
.opendir(path, typeof options === 'function' ? undefined : options)
|
|
868
|
+
.then(result => cb(undefined, result))
|
|
877
869
|
.catch(cb);
|
|
878
870
|
}
|
|
879
|
-
opendir satisfies Omit<typeof
|
|
871
|
+
opendir satisfies Omit<typeof fs.opendir, '__promisify__'>;
|
|
880
872
|
|
|
881
|
-
export function cp(source: PathLike, destination: PathLike, callback: Callback): void;
|
|
882
|
-
export function cp(source: PathLike, destination: PathLike, opts:
|
|
883
|
-
export function cp(source: PathLike, destination: PathLike, opts:
|
|
873
|
+
export function cp(source: fs.PathLike, destination: fs.PathLike, callback: Callback): void;
|
|
874
|
+
export function cp(source: fs.PathLike, destination: fs.PathLike, opts: fs.CopyOptions, callback: Callback): void;
|
|
875
|
+
export function cp(source: fs.PathLike, destination: fs.PathLike, opts: fs.CopyOptions | Callback, callback: Callback = nop): void {
|
|
884
876
|
callback = typeof opts === 'function' ? opts : callback;
|
|
885
877
|
promises
|
|
886
|
-
.cp(source, destination, typeof opts === 'function' ?
|
|
887
|
-
.then(() => callback(
|
|
878
|
+
.cp(source, destination, typeof opts === 'function' ? undefined : opts)
|
|
879
|
+
.then(() => callback(undefined))
|
|
888
880
|
.catch(callback);
|
|
889
881
|
}
|
|
890
|
-
cp satisfies Omit<typeof
|
|
882
|
+
cp satisfies Omit<typeof fs.cp, '__promisify__'>;
|
|
891
883
|
|
|
892
|
-
export function statfs(path: PathLike, callback: Callback<[StatsFs]>): void;
|
|
893
|
-
export function statfs(path: PathLike, options:
|
|
894
|
-
export function statfs(path: PathLike, options:
|
|
895
|
-
export function statfs(path: PathLike, options?:
|
|
884
|
+
export function statfs(path: fs.PathLike, callback: Callback<[StatsFs]>): void;
|
|
885
|
+
export function statfs(path: fs.PathLike, options: fs.StatFsOptions & { bigint?: false }, callback: Callback<[StatsFs]>): void;
|
|
886
|
+
export function statfs(path: fs.PathLike, options: fs.StatFsOptions & { bigint: true }, callback: Callback<[BigIntStatsFs]>): void;
|
|
887
|
+
export function statfs(path: fs.PathLike, options?: fs.StatFsOptions | Callback<[StatsFs]>, callback: Callback<[StatsFs]> | Callback<[BigIntStatsFs]> = nop): void {
|
|
896
888
|
callback = typeof options === 'function' ? options : callback;
|
|
897
889
|
promises
|
|
898
|
-
.statfs(path, typeof options === 'function' ?
|
|
899
|
-
.then(result => (<Callback<[StatsFs | BigIntStatsFs]>>callback)(
|
|
890
|
+
.statfs(path, typeof options === 'function' ? undefined : options)
|
|
891
|
+
.then(result => (<Callback<[StatsFs | BigIntStatsFs]>>callback)(undefined, result))
|
|
900
892
|
.catch(callback);
|
|
901
893
|
}
|
|
902
|
-
statfs satisfies Omit<typeof
|
|
894
|
+
statfs satisfies Omit<typeof fs.statfs, '__promisify__'>;
|
|
903
895
|
|
|
904
|
-
export async function openAsBlob(path: PathLike, options?:
|
|
905
|
-
const handle = await promises.open(path, 'r');
|
|
896
|
+
export async function openAsBlob(path: fs.PathLike, options?: fs.OpenAsBlobOptions): Promise<Blob> {
|
|
897
|
+
const handle = await promises.open(path.toString(), 'r');
|
|
906
898
|
const buffer = await handle.readFile();
|
|
907
899
|
await handle.close();
|
|
908
900
|
return new Blob([buffer], options);
|
|
909
901
|
}
|
|
910
|
-
openAsBlob satisfies typeof
|
|
902
|
+
openAsBlob satisfies typeof fs.openAsBlob;
|