@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.
Files changed (56) hide show
  1. package/dist/ApiError.d.ts +4 -3
  2. package/dist/ApiError.js +1 -1
  3. package/dist/backends/AsyncStore.d.ts +3 -2
  4. package/dist/backends/AsyncStore.js +12 -5
  5. package/dist/backends/InMemory.d.ts +1 -1
  6. package/dist/backends/Index.d.ts +7 -10
  7. package/dist/backends/Index.js +7 -5
  8. package/dist/backends/Overlay.js +1 -1
  9. package/dist/backends/SyncStore.d.ts +6 -6
  10. package/dist/backends/SyncStore.js +4 -4
  11. package/dist/backends/backend.d.ts +5 -4
  12. package/dist/backends/backend.js +2 -2
  13. package/dist/browser.min.js +4 -4
  14. package/dist/browser.min.js.map +3 -3
  15. package/dist/config.d.ts +1 -1
  16. package/dist/config.js +2 -2
  17. package/dist/emulation/async.d.ts +76 -77
  18. package/dist/emulation/async.js +42 -42
  19. package/dist/emulation/dir.js +6 -5
  20. package/dist/emulation/promises.d.ts +106 -102
  21. package/dist/emulation/promises.js +61 -65
  22. package/dist/emulation/shared.d.ts +1 -7
  23. package/dist/emulation/shared.js +1 -1
  24. package/dist/emulation/streams.js +3 -2
  25. package/dist/emulation/sync.d.ts +71 -64
  26. package/dist/emulation/sync.js +39 -40
  27. package/dist/file.d.ts +4 -4
  28. package/dist/file.js +7 -5
  29. package/dist/filesystem.d.ts +1 -1
  30. package/dist/filesystem.js +3 -0
  31. package/dist/mutex.js +2 -2
  32. package/dist/stats.d.ts +7 -7
  33. package/dist/stats.js +50 -10
  34. package/dist/utils.d.ts +5 -5
  35. package/dist/utils.js +4 -3
  36. package/package.json +3 -3
  37. package/readme.md +2 -2
  38. package/src/ApiError.ts +3 -1
  39. package/src/backends/AsyncStore.ts +14 -8
  40. package/src/backends/Index.ts +14 -10
  41. package/src/backends/Overlay.ts +3 -3
  42. package/src/backends/SyncStore.ts +8 -8
  43. package/src/backends/backend.ts +7 -5
  44. package/src/config.ts +5 -5
  45. package/src/emulation/async.ts +188 -196
  46. package/src/emulation/dir.ts +6 -6
  47. package/src/emulation/promises.ts +181 -173
  48. package/src/emulation/shared.ts +2 -9
  49. package/src/emulation/streams.ts +9 -8
  50. package/src/emulation/sync.ts +159 -159
  51. package/src/file.ts +11 -9
  52. package/src/filesystem.ts +11 -7
  53. package/src/mutex.ts +3 -3
  54. package/src/stats.ts +32 -23
  55. package/src/utils.ts +10 -9
  56. package/tsconfig.json +2 -1
@@ -1,30 +1,29 @@
1
1
  import { Buffer } from 'buffer';
2
- import type * as Node from 'fs';
3
- import type { BufferEncodingOption, EncodingOption, ReadSyncOptions, StatOptions, symlink } from 'fs';
2
+ import type * as fs from 'node:fs';
4
3
  import { ApiError, ErrorCode } from '../ApiError.js';
5
4
  import { ActionType, File, isAppendable, isReadable, isWriteable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
6
5
  import { FileContents, FileSystem } from '../filesystem.js';
7
6
  import { BigIntStats, FileType, type BigIntStatsFs, type Stats, type StatsFs } from '../stats.js';
8
7
  import { normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
9
- import { COPYFILE_EXCL, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } from './constants.js';
8
+ import { COPYFILE_EXCL, F_OK, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } from './constants.js';
10
9
  import { Dir, Dirent } from './dir.js';
11
10
  import { dirname, join, parse } from './path.js';
12
- import { PathLike, cred, fd2file, fdMap, fixError, getFdForFile, mounts, resolveMount } from './shared.js';
11
+ import { cred, fd2file, fdMap, fixError, file2fd, mounts, resolveMount } from './shared.js';
13
12
 
14
13
  type FileSystemMethod = {
15
- [K in keyof FileSystem]: FileSystem[K] extends (...args) => unknown
14
+ [K in keyof FileSystem]: FileSystem[K] extends (...args: any[]) => unknown
16
15
  ? (name: K, resolveSymlinks: boolean, ...args: Parameters<FileSystem[K]>) => ReturnType<FileSystem[K]>
17
16
  : never;
18
17
  }[keyof FileSystem]; // https://stackoverflow.com/a/76335220/17637456
19
18
 
20
19
  function doOp<M extends FileSystemMethod, RT extends ReturnType<M>>(...[name, resolveSymlinks, path, ...args]: Parameters<M>): RT {
21
- path = normalizePath(path);
20
+ path = normalizePath(path!);
22
21
  const { fs, path: resolvedPath } = resolveMount(resolveSymlinks && existsSync(path) ? realpathSync(path) : path);
23
22
  try {
24
23
  // @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)
25
24
  return fs[name](resolvedPath, ...args) as RT;
26
25
  } catch (e) {
27
- throw fixError(e, { [resolvedPath]: path });
26
+ throw fixError(<Error>e, { [resolvedPath]: path });
28
27
  }
29
28
  }
30
29
 
@@ -33,7 +32,7 @@ function doOp<M extends FileSystemMethod, RT extends ReturnType<M>>(...[name, re
33
32
  * @param oldPath
34
33
  * @param newPath
35
34
  */
36
- export function renameSync(oldPath: PathLike, newPath: PathLike): void {
35
+ export function renameSync(oldPath: fs.PathLike, newPath: fs.PathLike): void {
37
36
  oldPath = normalizePath(oldPath);
38
37
  newPath = normalizePath(newPath);
39
38
  const _old = resolveMount(oldPath);
@@ -47,16 +46,16 @@ export function renameSync(oldPath: PathLike, newPath: PathLike): void {
47
46
  writeFileSync(newPath, readFileSync(oldPath));
48
47
  unlinkSync(oldPath);
49
48
  } catch (e) {
50
- throw fixError(e, paths);
49
+ throw fixError(<Error>e, paths);
51
50
  }
52
51
  }
53
- renameSync satisfies typeof Node.renameSync;
52
+ renameSync satisfies typeof fs.renameSync;
54
53
 
55
54
  /**
56
55
  * Test whether or not the given path exists by checking with the file system.
57
56
  * @param path
58
57
  */
59
- export function existsSync(path: PathLike): boolean {
58
+ export function existsSync(path: fs.PathLike): boolean {
60
59
  path = normalizePath(path);
61
60
  try {
62
61
  const { fs, path: resolvedPath } = resolveMount(realpathSync(path));
@@ -69,20 +68,20 @@ export function existsSync(path: PathLike): boolean {
69
68
  throw e;
70
69
  }
71
70
  }
72
- existsSync satisfies typeof Node.existsSync;
71
+ existsSync satisfies typeof fs.existsSync;
73
72
 
74
73
  /**
75
74
  * Synchronous `stat`.
76
75
  * @param path
77
76
  * @returns Stats
78
77
  */
79
- export function statSync(path: PathLike, options?: { bigint?: false }): Stats;
80
- export function statSync(path: PathLike, options: { bigint: true }): BigIntStats;
81
- export function statSync(path: PathLike, options?: StatOptions): Stats | BigIntStats {
82
- const stats: Stats = doOp('statSync', true, path, cred);
78
+ export function statSync(path: fs.PathLike, options?: { bigint?: boolean }): Stats;
79
+ export function statSync(path: fs.PathLike, options: { bigint: true }): BigIntStats;
80
+ export function statSync(path: fs.PathLike, options?: fs.StatOptions): Stats | BigIntStats {
81
+ const stats: Stats = doOp('statSync', true, path.toString(), cred);
83
82
  return options?.bigint ? new BigIntStats(stats) : stats;
84
83
  }
85
- statSync satisfies typeof Node.statSync;
84
+ statSync satisfies typeof fs.statSync;
86
85
 
87
86
  /**
88
87
  * Synchronous `lstat`.
@@ -90,20 +89,20 @@ statSync satisfies typeof Node.statSync;
90
89
  * then the link itself is stat-ed, not the file that it refers to.
91
90
  * @param path
92
91
  */
93
- export function lstatSync(path: PathLike, options?: { bigint?: false }): Stats;
94
- export function lstatSync(path: PathLike, options: { bigint: true }): BigIntStats;
95
- export function lstatSync(path: PathLike, options?: StatOptions): Stats | BigIntStats {
96
- const stats: Stats = doOp('statSync', false, path, cred);
92
+ export function lstatSync(path: fs.PathLike, options?: { bigint?: boolean }): Stats;
93
+ export function lstatSync(path: fs.PathLike, options: { bigint: true }): BigIntStats;
94
+ export function lstatSync(path: fs.PathLike, options?: fs.StatOptions): Stats | BigIntStats {
95
+ const stats: Stats = doOp('statSync', false, path.toString(), cred);
97
96
  return options?.bigint ? new BigIntStats(stats) : stats;
98
97
  }
99
- lstatSync satisfies typeof Node.lstatSync;
98
+ lstatSync satisfies typeof fs.lstatSync;
100
99
 
101
100
  /**
102
101
  * Synchronous `truncate`.
103
102
  * @param path
104
103
  * @param len
105
104
  */
106
- export function truncateSync(path: PathLike, len: number = 0): void {
105
+ export function truncateSync(path: fs.PathLike, len: number | null = 0): void {
107
106
  const fd = openSync(path, 'r+');
108
107
  try {
109
108
  ftruncateSync(fd, len);
@@ -111,18 +110,18 @@ export function truncateSync(path: PathLike, len: number = 0): void {
111
110
  closeSync(fd);
112
111
  }
113
112
  }
114
- truncateSync satisfies typeof Node.truncateSync;
113
+ truncateSync satisfies typeof fs.truncateSync;
115
114
 
116
115
  /**
117
116
  * Synchronous `unlink`.
118
117
  * @param path
119
118
  */
120
- export function unlinkSync(path: PathLike): void {
121
- return doOp('unlinkSync', false, path, cred);
119
+ export function unlinkSync(path: fs.PathLike): void {
120
+ return doOp('unlinkSync', false, path.toString(), cred);
122
121
  }
123
- unlinkSync satisfies typeof Node.unlinkSync;
122
+ unlinkSync satisfies typeof fs.unlinkSync;
124
123
 
125
- function _openSync(_path: PathLike, _flag: string, _mode: Node.Mode, resolveSymlinks: boolean): File {
124
+ function _openSync(_path: fs.PathLike, _flag: fs.OpenMode, _mode?: fs.Mode | null, resolveSymlinks: boolean = true): File {
126
125
  const path = normalizePath(_path),
127
126
  mode = normalizeMode(_mode, 0o644),
128
127
  flag = parseFlag(_flag);
@@ -179,17 +178,17 @@ function _openSync(_path: PathLike, _flag: string, _mode: Node.Mode, resolveSyml
179
178
  * @param mode Mode to use to open the file. Can be ignored if the
180
179
  * filesystem doesn't support permissions.
181
180
  */
182
- export function openSync(path: PathLike, flag: string, mode?: Node.Mode): number {
183
- return getFdForFile(_openSync(path, flag, mode, true));
181
+ export function openSync(path: fs.PathLike, flag: fs.OpenMode, mode: fs.Mode | null = F_OK): number {
182
+ return file2fd(_openSync(path, flag, mode, true));
184
183
  }
185
- openSync satisfies typeof Node.openSync;
184
+ openSync satisfies typeof fs.openSync;
186
185
 
187
186
  /**
188
187
  * Opens a file or symlink
189
188
  * @internal
190
189
  */
191
- export function lopenSync(path: PathLike, flag: string, mode?: Node.Mode): number {
192
- return getFdForFile(_openSync(path, flag, mode, false));
190
+ export function lopenSync(path: fs.PathLike, flag: string, mode?: fs.Mode | null): number {
191
+ return file2fd(_openSync(path, flag, mode, false));
193
192
  }
194
193
 
195
194
  /**
@@ -212,24 +211,24 @@ function _readFileSync(fname: string, flag: string, resolveSymlinks: boolean): U
212
211
 
213
212
  /**
214
213
  * Synchronously reads the entire contents of a file.
215
- * @param filename
214
+ * @param path
216
215
  * @param options
217
216
  * @option options encoding The string encoding for the file contents. Defaults to `null`.
218
217
  * @option options flag Defaults to `'r'`.
219
218
  * @returns file contents
220
219
  */
221
- export function readFileSync(filename: string, options?: { flag?: string }): Buffer;
222
- export function readFileSync(filename: string, options: (Node.EncodingOption & { flag?: string }) | BufferEncoding): string;
223
- export function readFileSync(filename: string, arg2: Node.WriteFileOptions = {}): FileContents {
224
- const options = normalizeOptions(arg2, null, 'r', 0o644);
220
+ export function readFileSync(path: fs.PathOrFileDescriptor, options?: { flag?: string } | null): Buffer;
221
+ export function readFileSync(path: fs.PathOrFileDescriptor, options?: (fs.EncodingOption & { flag?: string }) | BufferEncoding | null): string;
222
+ export function readFileSync(path: fs.PathOrFileDescriptor, _options: fs.WriteFileOptions | null = {}): FileContents {
223
+ const options = normalizeOptions(_options, null, 'r', 0o644);
225
224
  const flag = parseFlag(options.flag);
226
225
  if (!isReadable(flag)) {
227
226
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
228
227
  }
229
- const data: Buffer = Buffer.from(_readFileSync(filename, options.flag, true));
228
+ const data: Buffer = Buffer.from(_readFileSync(typeof path == 'number' ? fd2file(path).path! : path.toString(), options.flag, true));
230
229
  return options.encoding ? data.toString(options.encoding) : data;
231
230
  }
232
- readFileSync satisfies typeof Node.readFileSync;
231
+ readFileSync satisfies typeof fs.readFileSync;
233
232
 
234
233
  /**
235
234
  * Synchronously writes data to a file, replacing the file
@@ -240,7 +239,7 @@ readFileSync satisfies typeof Node.readFileSync;
240
239
  function _writeFileSync(fname: string, data: Uint8Array, flag: string, mode: number, resolveSymlinks: boolean): void {
241
240
  const file = _openSync(fname, flag, mode, resolveSymlinks);
242
241
  try {
243
- file.writeSync(data, 0, data.length, 0);
242
+ file.writeSync(data, 0, data.byteLength, 0);
244
243
  } finally {
245
244
  file.closeSync();
246
245
  }
@@ -251,16 +250,16 @@ function _writeFileSync(fname: string, data: Uint8Array, flag: string, mode: num
251
250
  * exists.
252
251
  *
253
252
  * The encoding option is ignored if data is a buffer.
254
- * @param filename
253
+ * @param path
255
254
  * @param data
256
255
  * @param options
257
256
  * @option options encoding Defaults to `'utf8'`.
258
257
  * @option options mode Defaults to `0644`.
259
258
  * @option options flag Defaults to `'w'`.
260
259
  */
261
- export function writeFileSync(filename: string, data: FileContents, options?: Node.WriteFileOptions): void;
262
- export function writeFileSync(filename: string, data: FileContents, encoding?: BufferEncoding): void;
263
- export function writeFileSync(filename: string, data: FileContents, _options?: Node.WriteFileOptions | BufferEncoding): void {
260
+ export function writeFileSync(path: fs.PathOrFileDescriptor, data: FileContents, options?: fs.WriteFileOptions): void;
261
+ export function writeFileSync(path: fs.PathOrFileDescriptor, data: FileContents, encoding?: BufferEncoding): void;
262
+ export function writeFileSync(path: fs.PathOrFileDescriptor, data: FileContents, _options: fs.WriteFileOptions | BufferEncoding = {}): void {
264
263
  const options = normalizeOptions(_options, 'utf8', 'w+', 0o644);
265
264
  const flag = parseFlag(options.flag);
266
265
  if (!isWriteable(flag)) {
@@ -269,13 +268,13 @@ export function writeFileSync(filename: string, data: FileContents, _options?: N
269
268
  if (typeof data != 'string' && !options.encoding) {
270
269
  throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
271
270
  }
272
- const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
273
- if (encodedData === undefined) {
271
+ const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding!) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
272
+ if (!encodedData) {
274
273
  throw new ApiError(ErrorCode.EINVAL, 'Data not specified');
275
274
  }
276
- _writeFileSync(filename, encodedData, options.flag, options.mode, true);
275
+ _writeFileSync(typeof path == 'number' ? fd2file(path).path! : path.toString(), encodedData, options.flag, options.mode, true);
277
276
  }
278
- writeFileSync satisfies typeof Node.writeFileSync;
277
+ writeFileSync satisfies typeof fs.writeFileSync;
279
278
 
280
279
  /**
281
280
  * Synchronously append data to a file, creating the file if
@@ -284,7 +283,7 @@ writeFileSync satisfies typeof Node.writeFileSync;
284
283
  function _appendFileSync(fname: string, data: Uint8Array, flag: string, mode: number, resolveSymlinks: boolean): void {
285
284
  const file = _openSync(fname, flag, mode, resolveSymlinks);
286
285
  try {
287
- file.writeSync(data, 0, data.length, null);
286
+ file.writeSync(data, 0, data.byteLength, null);
288
287
  } finally {
289
288
  file.closeSync();
290
289
  }
@@ -301,7 +300,7 @@ function _appendFileSync(fname: string, data: Uint8Array, flag: string, mode: nu
301
300
  * @option options mode Defaults to `0644`.
302
301
  * @option options flag Defaults to `'a'`.
303
302
  */
304
- export function appendFileSync(filename: string, data: FileContents, _options?: Node.WriteFileOptions): void {
303
+ export function appendFileSync(filename: fs.PathOrFileDescriptor, data: FileContents, _options: fs.WriteFileOptions = {}): void {
305
304
  const options = normalizeOptions(_options, 'utf8', 'a', 0o644);
306
305
  const flag = parseFlag(options.flag);
307
306
  if (!isAppendable(flag)) {
@@ -310,10 +309,10 @@ export function appendFileSync(filename: string, data: FileContents, _options?:
310
309
  if (typeof data != 'string' && !options.encoding) {
311
310
  throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
312
311
  }
313
- const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
314
- _appendFileSync(filename, encodedData, options.flag, options.mode, true);
312
+ const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding!) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
313
+ _appendFileSync(typeof filename == 'number' ? fd2file(filename).path! : filename.toString(), encodedData, options.flag, options.mode, true);
315
314
  }
316
- appendFileSync satisfies typeof Node.appendFileSync;
315
+ appendFileSync satisfies typeof fs.appendFileSync;
317
316
 
318
317
  /**
319
318
  * Synchronous `fstat`.
@@ -321,13 +320,13 @@ appendFileSync satisfies typeof Node.appendFileSync;
321
320
  * specified by the file descriptor `fd`.
322
321
  * @param fd
323
322
  */
324
- export function fstatSync(fd: number, options?: { bigint?: false }): Stats;
323
+ export function fstatSync(fd: number, options?: { bigint?: boolean }): Stats;
325
324
  export function fstatSync(fd: number, options: { bigint: true }): BigIntStats;
326
- export function fstatSync(fd: number, options?: StatOptions): Stats | BigIntStats {
325
+ export function fstatSync(fd: number, options?: fs.StatOptions): Stats | BigIntStats {
327
326
  const stats: Stats = fd2file(fd).statSync();
328
327
  return options?.bigint ? new BigIntStats(stats) : stats;
329
328
  }
330
- fstatSync satisfies typeof Node.fstatSync;
329
+ fstatSync satisfies typeof fs.fstatSync;
331
330
 
332
331
  /**
333
332
  * Synchronous close.
@@ -337,20 +336,21 @@ export function closeSync(fd: number): void {
337
336
  fd2file(fd).closeSync();
338
337
  fdMap.delete(fd);
339
338
  }
340
- closeSync satisfies typeof Node.closeSync;
339
+ closeSync satisfies typeof fs.closeSync;
341
340
 
342
341
  /**
343
342
  * Synchronous ftruncate.
344
343
  * @param fd
345
344
  * @param len
346
345
  */
347
- export function ftruncateSync(fd: number, len: number = 0): void {
346
+ export function ftruncateSync(fd: number, len: number | null = 0): void {
347
+ len ||= 0;
348
348
  if (len < 0) {
349
349
  throw new ApiError(ErrorCode.EINVAL);
350
350
  }
351
351
  fd2file(fd).truncateSync(len);
352
352
  }
353
- ftruncateSync satisfies typeof Node.ftruncateSync;
353
+ ftruncateSync satisfies typeof fs.ftruncateSync;
354
354
 
355
355
  /**
356
356
  * Synchronous fsync.
@@ -359,7 +359,7 @@ ftruncateSync satisfies typeof Node.ftruncateSync;
359
359
  export function fsyncSync(fd: number): void {
360
360
  fd2file(fd).syncSync();
361
361
  }
362
- fsyncSync satisfies typeof Node.fsyncSync;
362
+ fsyncSync satisfies typeof fs.fsyncSync;
363
363
 
364
364
  /**
365
365
  * Synchronous fdatasync.
@@ -368,7 +368,7 @@ fsyncSync satisfies typeof Node.fsyncSync;
368
368
  export function fdatasyncSync(fd: number): void {
369
369
  fd2file(fd).datasyncSync();
370
370
  }
371
- fdatasyncSync satisfies typeof Node.fdatasyncSync;
371
+ fdatasyncSync satisfies typeof fs.fdatasyncSync;
372
372
 
373
373
  /**
374
374
  * Write buffer to the file specified by `fd`.
@@ -383,35 +383,30 @@ fdatasyncSync satisfies typeof Node.fdatasyncSync;
383
383
  * data should be written. If position is null, the data will be written at
384
384
  * the current position.
385
385
  */
386
- export function writeSync(fd: number, data: Uint8Array, offset: number, length: number, position?: number): number;
387
- export function writeSync(fd: number, data: string, position?: number, encoding?: BufferEncoding): number;
388
- export function writeSync(fd: number, data: FileContents, posOrOff?: number, lenOrEnc?: BufferEncoding | number, pos?: number): number {
389
- let buffer: Uint8Array,
390
- offset: number = 0,
391
- length: number,
392
- position: number;
386
+ export function writeSync(fd: number, data: ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
387
+ export function writeSync(fd: number, data: string, position?: number | null, encoding?: BufferEncoding | null): number;
388
+ export function writeSync(fd: number, data: FileContents, posOrOff?: number | null, lenOrEnc?: BufferEncoding | number | null, pos?: number | null): number {
389
+ let buffer: Uint8Array, offset: number | undefined, length: number, position: number | null;
393
390
  if (typeof data === 'string') {
394
391
  // Signature 1: (fd, string, [position?, [encoding?]])
395
392
  position = typeof posOrOff === 'number' ? posOrOff : null;
396
393
  const encoding = <BufferEncoding>(typeof lenOrEnc === 'string' ? lenOrEnc : 'utf8');
397
394
  offset = 0;
398
395
  buffer = Buffer.from(data, encoding);
399
- length = buffer.length;
396
+ length = buffer.byteLength;
400
397
  } else {
401
398
  // Signature 2: (fd, buffer, offset, length, position?)
402
- buffer = data;
403
- offset = posOrOff;
404
- length = lenOrEnc as number;
399
+ buffer = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
400
+ offset = posOrOff!;
401
+ length = <number>lenOrEnc;
405
402
  position = typeof pos === 'number' ? pos : null;
406
403
  }
407
404
 
408
405
  const file = fd2file(fd);
409
- if (position === undefined || position === null) {
410
- position = file.position!;
411
- }
406
+ position ??= file.position;
412
407
  return file.writeSync(buffer, offset, length, position);
413
408
  }
414
- writeSync satisfies typeof Node.writeSync;
409
+ writeSync satisfies typeof fs.writeSync;
415
410
 
416
411
  /**
417
412
  * Read data from the file specified by `fd`.
@@ -425,9 +420,9 @@ writeSync satisfies typeof Node.writeSync;
425
420
  * in the file. If position is null, data will be read from the current file
426
421
  * position.
427
422
  */
428
- export function readSync(fd: number, buffer: Uint8Array, opts?: ReadSyncOptions): number;
429
- export function readSync(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number): number;
430
- export function readSync(fd: number, buffer: Uint8Array, opts?: ReadSyncOptions | number, length?: number, position?: number | bigint): number {
423
+ export function readSync(fd: number, buffer: ArrayBufferView, opts?: fs.ReadSyncOptions): number;
424
+ export function readSync(fd: number, buffer: ArrayBufferView, offset: number, length: number, position?: fs.ReadPosition | null): number;
425
+ export function readSync(fd: number, buffer: ArrayBufferView, opts?: fs.ReadSyncOptions | number, length?: number, position?: fs.ReadPosition | null): number {
431
426
  const file = fd2file(fd);
432
427
  const offset = typeof opts == 'object' ? opts.offset : opts;
433
428
  if (typeof opts == 'object') {
@@ -442,7 +437,7 @@ export function readSync(fd: number, buffer: Uint8Array, opts?: ReadSyncOptions
442
437
 
443
438
  return file.readSync(buffer, offset, length, position);
444
439
  }
445
- readSync satisfies typeof Node.readSync;
440
+ readSync satisfies typeof fs.readSync;
446
441
 
447
442
  /**
448
443
  * Synchronous `fchown`.
@@ -453,7 +448,7 @@ readSync satisfies typeof Node.readSync;
453
448
  export function fchownSync(fd: number, uid: number, gid: number): void {
454
449
  fd2file(fd).chownSync(uid, gid);
455
450
  }
456
- fchownSync satisfies typeof Node.fchownSync;
451
+ fchownSync satisfies typeof fs.fchownSync;
457
452
 
458
453
  /**
459
454
  * Synchronous `fchmod`.
@@ -467,7 +462,7 @@ export function fchmodSync(fd: number, mode: number | string): void {
467
462
  }
468
463
  fd2file(fd).chmodSync(numMode);
469
464
  }
470
- fchmodSync satisfies typeof Node.fchmodSync;
465
+ fchmodSync satisfies typeof fs.fchmodSync;
471
466
 
472
467
  /**
473
468
  * Change the file timestamps of a file referenced by the supplied file
@@ -479,16 +474,16 @@ fchmodSync satisfies typeof Node.fchmodSync;
479
474
  export function futimesSync(fd: number, atime: string | number | Date, mtime: string | number | Date): void {
480
475
  fd2file(fd).utimesSync(normalizeTime(atime), normalizeTime(mtime));
481
476
  }
482
- futimesSync satisfies typeof Node.futimesSync;
477
+ futimesSync satisfies typeof fs.futimesSync;
483
478
 
484
479
  /**
485
480
  * Synchronous `rmdir`.
486
481
  * @param path
487
482
  */
488
- export function rmdirSync(path: PathLike): void {
489
- return doOp('rmdirSync', true, path, cred);
483
+ export function rmdirSync(path: fs.PathLike): void {
484
+ return doOp('rmdirSync', true, path.toString(), cred);
490
485
  }
491
- rmdirSync satisfies typeof Node.rmdirSync;
486
+ rmdirSync satisfies typeof fs.rmdirSync;
492
487
 
493
488
  /**
494
489
  * Synchronous `mkdir`.
@@ -496,23 +491,28 @@ rmdirSync satisfies typeof Node.rmdirSync;
496
491
  * @param mode defaults to o777
497
492
  * @todo Implement recursion
498
493
  */
499
- export function mkdirSync(path: PathLike, options: Node.MakeDirectoryOptions & { recursive: true }): string;
500
- export function mkdirSync(path: PathLike, options?: Node.Mode | (Node.MakeDirectoryOptions & { recursive?: false })): void;
501
- export function mkdirSync(path: PathLike, options?: Node.Mode | Node.MakeDirectoryOptions): string | void {
502
- const mode: Node.Mode = typeof options == 'number' || typeof options == 'string' ? options : options?.mode;
494
+ export function mkdirSync(path: fs.PathLike, options: fs.MakeDirectoryOptions & { recursive: true }): string | undefined;
495
+ export function mkdirSync(path: fs.PathLike, options?: fs.Mode | (fs.MakeDirectoryOptions & { recursive?: false }) | null): void;
496
+ export function mkdirSync(path: fs.PathLike, options?: fs.Mode | fs.MakeDirectoryOptions | null): string | undefined;
497
+ export function mkdirSync(path: fs.PathLike, options?: fs.Mode | fs.MakeDirectoryOptions | null): string | undefined | void {
498
+ const mode: fs.Mode | undefined = typeof options == 'number' || typeof options == 'string' ? options : options?.mode;
503
499
  const recursive = typeof options == 'object' && options?.recursive;
504
- doOp('mkdirSync', true, path, normalizeMode(mode, 0o777), cred);
500
+ doOp('mkdirSync', true, path.toString(), normalizeMode(mode, 0o777), cred);
505
501
  }
506
- mkdirSync satisfies typeof Node.mkdirSync;
502
+ mkdirSync satisfies typeof fs.mkdirSync;
507
503
 
508
504
  /**
509
505
  * Synchronous `readdir`. Reads the contents of a directory.
510
506
  * @param path
511
507
  */
512
- export function readdirSync(path: PathLike, options?: { encoding?: BufferEncoding; withFileTypes?: false } | BufferEncoding): string[];
513
- export function readdirSync(path: PathLike, options: { encoding: 'buffer'; withFileTypes?: false } | 'buffer'): Buffer[];
514
- export function readdirSync(path: PathLike, options: { withFileTypes: true }): Dirent[];
515
- export function readdirSync(path: PathLike, options?: { encoding?: BufferEncoding | 'buffer'; withFileTypes?: boolean } | string): string[] | Dirent[] | Buffer[] {
508
+ export function readdirSync(path: fs.PathLike, options?: { recursive?: boolean; encoding?: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | null): string[];
509
+ export function readdirSync(path: fs.PathLike, options: { recursive?: boolean; encoding: 'buffer'; withFileTypes?: false } | 'buffer'): Buffer[];
510
+ export function readdirSync(path: fs.PathLike, options: { recursive?: boolean; withFileTypes: true }): Dirent[];
511
+ export function readdirSync(path: fs.PathLike, options?: (fs.ObjectEncodingOptions & { withFileTypes?: false; recursive?: boolean }) | BufferEncoding | null): string[] | Buffer[];
512
+ export function readdirSync(
513
+ path: fs.PathLike,
514
+ options?: { recursive?: boolean; encoding?: BufferEncoding | 'buffer' | null; withFileTypes?: boolean } | BufferEncoding | 'buffer' | null
515
+ ): string[] | Dirent[] | Buffer[] {
516
516
  path = normalizePath(path);
517
517
  const entries: string[] = doOp('readdirSync', true, path, cred);
518
518
  for (const mount of mounts.keys()) {
@@ -526,19 +526,19 @@ export function readdirSync(path: PathLike, options?: { encoding?: BufferEncodin
526
526
  }
527
527
  entries.push(entry);
528
528
  }
529
- return <string[] | Dirent[] | Buffer[]>entries.map((entry: string): string | Dirent | Buffer => {
529
+ return <string[] | Dirent[] | Buffer[]>entries.map((entry: string) => {
530
530
  if (typeof options == 'object' && options?.withFileTypes) {
531
- return new Dirent(entry, statSync(join(path, entry)));
531
+ return new Dirent(entry, statSync(join(path.toString(), entry)));
532
532
  }
533
533
 
534
- if (options == 'buffer' || (typeof options == 'object' && options.encoding == 'buffer')) {
534
+ if (options == 'buffer' || (typeof options == 'object' && options?.encoding == 'buffer')) {
535
535
  return Buffer.from(entry);
536
536
  }
537
537
 
538
538
  return entry;
539
539
  });
540
540
  }
541
- readdirSync satisfies typeof Node.readdirSync;
541
+ readdirSync satisfies typeof fs.readdirSync;
542
542
 
543
543
  // SYMLINK METHODS
544
544
 
@@ -547,11 +547,11 @@ readdirSync satisfies typeof Node.readdirSync;
547
547
  * @param existing
548
548
  * @param newpath
549
549
  */
550
- export function linkSync(existing: PathLike, newpath: PathLike): void {
550
+ export function linkSync(existing: fs.PathLike, newpath: fs.PathLike): void {
551
551
  newpath = normalizePath(newpath);
552
- return doOp('linkSync', false, existing, newpath, cred);
552
+ return doOp('linkSync', false, existing.toString(), newpath.toString(), cred);
553
553
  }
554
- linkSync satisfies typeof Node.linkSync;
554
+ linkSync satisfies typeof fs.linkSync;
555
555
 
556
556
  /**
557
557
  * Synchronous `symlink`.
@@ -559,35 +559,35 @@ linkSync satisfies typeof Node.linkSync;
559
559
  * @param path link path
560
560
  * @param type can be either `'dir'` or `'file'` (default is `'file'`)
561
561
  */
562
- export function symlinkSync(target: PathLike, path: PathLike, type: symlink.Type = 'file'): void {
563
- if (!['file', 'dir', 'junction'].includes(type)) {
562
+ export function symlinkSync(target: fs.PathLike, path: fs.PathLike, type: fs.symlink.Type | null = 'file'): void {
563
+ if (!['file', 'dir', 'junction'].includes(type!)) {
564
564
  throw new ApiError(ErrorCode.EINVAL, 'Invalid type: ' + type);
565
565
  }
566
566
  if (existsSync(path)) {
567
- throw ApiError.With('EEXIST', path, 'symlink');
567
+ throw ApiError.With('EEXIST', path.toString(), 'symlink');
568
568
  }
569
569
 
570
- writeFileSync(path, target);
570
+ writeFileSync(path, target.toString());
571
571
  const file = _openSync(path, 'r+', 0o644, false);
572
572
  file._setTypeSync(FileType.SYMLINK);
573
573
  }
574
- symlinkSync satisfies typeof Node.symlinkSync;
574
+ symlinkSync satisfies typeof fs.symlinkSync;
575
575
 
576
576
  /**
577
577
  * Synchronous readlink.
578
578
  * @param path
579
579
  */
580
- export function readlinkSync(path: PathLike, options?: BufferEncodingOption): Buffer;
581
- export function readlinkSync(path: PathLike, options: EncodingOption | BufferEncoding): string;
582
- export function readlinkSync(path: PathLike, options?: EncodingOption | BufferEncoding | BufferEncodingOption): Buffer | string {
583
- const value: Buffer = Buffer.from(_readFileSync(path, 'r', false));
584
- const encoding: BufferEncoding | 'buffer' = typeof options == 'object' ? options.encoding : options;
580
+ export function readlinkSync(path: fs.PathLike, options?: fs.BufferEncodingOption): Buffer;
581
+ export function readlinkSync(path: fs.PathLike, options: fs.EncodingOption | BufferEncoding): string;
582
+ export function readlinkSync(path: fs.PathLike, options?: fs.EncodingOption | BufferEncoding | fs.BufferEncodingOption): Buffer | string {
583
+ const value: Buffer = Buffer.from(_readFileSync(path.toString(), 'r', false));
584
+ const encoding = typeof options == 'object' ? options?.encoding : options;
585
585
  if (encoding == 'buffer') {
586
586
  return value;
587
587
  }
588
- return value.toString(encoding);
588
+ return value.toString(encoding!);
589
589
  }
590
- readlinkSync satisfies typeof Node.readlinkSync;
590
+ readlinkSync satisfies typeof fs.readlinkSync;
591
591
 
592
592
  // PROPERTY OPERATIONS
593
593
 
@@ -597,12 +597,12 @@ readlinkSync satisfies typeof Node.readlinkSync;
597
597
  * @param uid
598
598
  * @param gid
599
599
  */
600
- export function chownSync(path: PathLike, uid: number, gid: number): void {
600
+ export function chownSync(path: fs.PathLike, uid: number, gid: number): void {
601
601
  const fd = openSync(path, 'r+');
602
602
  fchownSync(fd, uid, gid);
603
603
  closeSync(fd);
604
604
  }
605
- chownSync satisfies typeof Node.chownSync;
605
+ chownSync satisfies typeof fs.chownSync;
606
606
 
607
607
  /**
608
608
  * Synchronous `lchown`.
@@ -610,36 +610,36 @@ chownSync satisfies typeof Node.chownSync;
610
610
  * @param uid
611
611
  * @param gid
612
612
  */
613
- export function lchownSync(path: PathLike, uid: number, gid: number): void {
613
+ export function lchownSync(path: fs.PathLike, uid: number, gid: number): void {
614
614
  const fd = lopenSync(path, 'r+');
615
615
  fchownSync(fd, uid, gid);
616
616
  closeSync(fd);
617
617
  }
618
- lchownSync satisfies typeof Node.lchownSync;
618
+ lchownSync satisfies typeof fs.lchownSync;
619
619
 
620
620
  /**
621
621
  * Synchronous `chmod`.
622
622
  * @param path
623
623
  * @param mode
624
624
  */
625
- export function chmodSync(path: PathLike, mode: Node.Mode): void {
625
+ export function chmodSync(path: fs.PathLike, mode: fs.Mode): void {
626
626
  const fd = openSync(path, 'r+');
627
627
  fchmodSync(fd, mode);
628
628
  closeSync(fd);
629
629
  }
630
- chmodSync satisfies typeof Node.chmodSync;
630
+ chmodSync satisfies typeof fs.chmodSync;
631
631
 
632
632
  /**
633
633
  * Synchronous `lchmod`.
634
634
  * @param path
635
635
  * @param mode
636
636
  */
637
- export function lchmodSync(path: PathLike, mode: number | string): void {
637
+ export function lchmodSync(path: fs.PathLike, mode: number | string): void {
638
638
  const fd = lopenSync(path, 'r+');
639
639
  fchmodSync(fd, mode);
640
640
  closeSync(fd);
641
641
  }
642
- lchmodSync satisfies typeof Node.lchmodSync;
642
+ lchmodSync satisfies typeof fs.lchmodSync;
643
643
 
644
644
  /**
645
645
  * Change file timestamps of the file referenced by the supplied path.
@@ -647,12 +647,12 @@ lchmodSync satisfies typeof Node.lchmodSync;
647
647
  * @param atime
648
648
  * @param mtime
649
649
  */
650
- export function utimesSync(path: PathLike, atime: string | number | Date, mtime: string | number | Date): void {
650
+ export function utimesSync(path: fs.PathLike, atime: string | number | Date, mtime: string | number | Date): void {
651
651
  const fd = openSync(path, 'r+');
652
652
  futimesSync(fd, atime, mtime);
653
653
  closeSync(fd);
654
654
  }
655
- utimesSync satisfies typeof Node.utimesSync;
655
+ utimesSync satisfies typeof fs.utimesSync;
656
656
 
657
657
  /**
658
658
  * Change file timestamps of the file referenced by the supplied path.
@@ -660,12 +660,12 @@ utimesSync satisfies typeof Node.utimesSync;
660
660
  * @param atime
661
661
  * @param mtime
662
662
  */
663
- export function lutimesSync(path: PathLike, atime: string | number | Date, mtime: string | number | Date): void {
663
+ export function lutimesSync(path: fs.PathLike, atime: string | number | Date, mtime: string | number | Date): void {
664
664
  const fd = lopenSync(path, 'r+');
665
665
  futimesSync(fd, atime, mtime);
666
666
  closeSync(fd);
667
667
  }
668
- lutimesSync satisfies typeof Node.lutimesSync;
668
+ lutimesSync satisfies typeof fs.lutimesSync;
669
669
 
670
670
  /**
671
671
  * Synchronous `realpath`.
@@ -675,9 +675,9 @@ lutimesSync satisfies typeof Node.lutimesSync;
675
675
  * known real paths.
676
676
  * @returns the real path
677
677
  */
678
- export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer;
679
- export function realpathSync(path: PathLike, options?: EncodingOption): string;
680
- export function realpathSync(path: PathLike, options?: EncodingOption | BufferEncodingOption): string | Buffer {
678
+ export function realpathSync(path: fs.PathLike, options: fs.BufferEncodingOption): Buffer;
679
+ export function realpathSync(path: fs.PathLike, options?: fs.EncodingOption): string;
680
+ export function realpathSync(path: fs.PathLike, options?: fs.EncodingOption | fs.BufferEncodingOption): string | Buffer {
681
681
  path = normalizePath(path);
682
682
  const { base, dir } = parse(path);
683
683
  const lpath = join(dir == '/' ? '/' : realpathSync(dir), base);
@@ -691,29 +691,29 @@ export function realpathSync(path: PathLike, options?: EncodingOption | BufferEn
691
691
 
692
692
  return realpathSync(mountPoint + readlinkSync(lpath));
693
693
  } catch (e) {
694
- throw fixError(e, { [resolvedPath]: lpath });
694
+ throw fixError(<Error>e, { [resolvedPath]: lpath });
695
695
  }
696
696
  }
697
- realpathSync satisfies Omit<typeof Node.realpathSync, 'native'>;
697
+ realpathSync satisfies Omit<typeof fs.realpathSync, 'native'>;
698
698
 
699
699
  /**
700
700
  * Synchronous `access`.
701
701
  * @param path
702
702
  * @param mode
703
703
  */
704
- export function accessSync(path: PathLike, mode: number = 0o600): void {
704
+ export function accessSync(path: fs.PathLike, mode: number = 0o600): void {
705
705
  const stats = statSync(path);
706
706
  if (!stats.hasAccess(mode, cred)) {
707
707
  throw new ApiError(ErrorCode.EACCES);
708
708
  }
709
709
  }
710
- accessSync satisfies typeof Node.accessSync;
710
+ accessSync satisfies typeof fs.accessSync;
711
711
 
712
712
  /**
713
713
  * Synchronous `rm`. Removes files or directories (recursively).
714
714
  * @param path The path to the file or directory to remove.
715
715
  */
716
- export function rmSync(path: PathLike, options?: Node.RmOptions): void {
716
+ export function rmSync(path: fs.PathLike, options?: fs.RmOptions): void {
717
717
  path = normalizePath(path);
718
718
 
719
719
  const stats = statSync(path);
@@ -740,7 +740,7 @@ export function rmSync(path: PathLike, options?: Node.RmOptions): void {
740
740
  throw new ApiError(ErrorCode.EPERM, 'File type not supported', path, 'rm');
741
741
  }
742
742
  }
743
- rmSync satisfies typeof Node.rmSync;
743
+ rmSync satisfies typeof fs.rmSync;
744
744
 
745
745
  /**
746
746
  * Synchronous `mkdtemp`. Creates a unique temporary directory.
@@ -748,10 +748,10 @@ rmSync satisfies typeof Node.rmSync;
748
748
  * @param options The encoding (or an object including `encoding`).
749
749
  * @returns The path to the created temporary directory, encoded as a string or buffer.
750
750
  */
751
- export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
752
- export function mkdtempSync(prefix: string, options?: EncodingOption): string;
753
- export function mkdtempSync(prefix: string, options?: EncodingOption | BufferEncodingOption): string | Buffer {
754
- const encoding = typeof options === 'object' ? options.encoding : options || 'utf8';
751
+ export function mkdtempSync(prefix: string, options: fs.BufferEncodingOption): Buffer;
752
+ export function mkdtempSync(prefix: string, options?: fs.EncodingOption): string;
753
+ export function mkdtempSync(prefix: string, options?: fs.EncodingOption | fs.BufferEncodingOption): string | Buffer {
754
+ const encoding = typeof options === 'object' ? options?.encoding : options || 'utf8';
755
755
  const fsName = `${prefix}${Date.now()}-${Math.random().toString(36).slice(2)}`;
756
756
  const resolvedPath = '/tmp/' + fsName;
757
757
 
@@ -759,7 +759,7 @@ export function mkdtempSync(prefix: string, options?: EncodingOption | BufferEnc
759
759
 
760
760
  return encoding == 'buffer' ? Buffer.from(resolvedPath) : resolvedPath;
761
761
  }
762
- mkdtempSync satisfies typeof Node.mkdtempSync;
762
+ mkdtempSync satisfies typeof fs.mkdtempSync;
763
763
 
764
764
  /**
765
765
  * Synchronous `copyFile`. Copies a file.
@@ -768,7 +768,7 @@ mkdtempSync satisfies typeof Node.mkdtempSync;
768
768
  * @param flags Optional flags for the copy operation. Currently supports these flags:
769
769
  * * `fs.constants.COPYFILE_EXCL`: If the destination file already exists, the operation fails.
770
770
  */
771
- export function copyFileSync(src: PathLike, dest: PathLike, flags?: number): void {
771
+ export function copyFileSync(src: fs.PathLike, dest: fs.PathLike, flags?: number): void {
772
772
  src = normalizePath(src);
773
773
  dest = normalizePath(dest);
774
774
 
@@ -778,7 +778,7 @@ export function copyFileSync(src: PathLike, dest: PathLike, flags?: number): voi
778
778
 
779
779
  writeFileSync(dest, readFileSync(src));
780
780
  }
781
- copyFileSync satisfies typeof Node.copyFileSync;
781
+ copyFileSync satisfies typeof fs.copyFileSync;
782
782
 
783
783
  /**
784
784
  * Synchronous `readv`. Reads from a file descriptor into multiple buffers.
@@ -787,17 +787,17 @@ copyFileSync satisfies typeof Node.copyFileSync;
787
787
  * @param position The position in the file where to begin reading.
788
788
  * @returns The number of bytes read.
789
789
  */
790
- export function readvSync(fd: number, buffers: readonly Uint8Array[], position?: number): number {
790
+ export function readvSync(fd: number, buffers: readonly NodeJS.ArrayBufferView[], position?: number): number {
791
791
  const file = fd2file(fd);
792
792
  let bytesRead = 0;
793
793
 
794
794
  for (const buffer of buffers) {
795
- bytesRead += file.readSync(buffer, 0, buffer.length, position + bytesRead);
795
+ bytesRead += file.readSync(buffer, 0, buffer.byteLength, position! + bytesRead);
796
796
  }
797
797
 
798
798
  return bytesRead;
799
799
  }
800
- readvSync satisfies typeof Node.readvSync;
800
+ readvSync satisfies typeof fs.readvSync;
801
801
 
802
802
  /**
803
803
  * Synchronous `writev`. Writes from multiple buffers into a file descriptor.
@@ -806,17 +806,17 @@ readvSync satisfies typeof Node.readvSync;
806
806
  * @param position The position in the file where to begin writing.
807
807
  * @returns The number of bytes written.
808
808
  */
809
- export function writevSync(fd: number, buffers: readonly Uint8Array[], position?: number): number {
809
+ export function writevSync(fd: number, buffers: readonly ArrayBufferView[], position?: number): number {
810
810
  const file = fd2file(fd);
811
811
  let bytesWritten = 0;
812
812
 
813
813
  for (const buffer of buffers) {
814
- bytesWritten += file.writeSync(buffer, 0, buffer.length, position + bytesWritten);
814
+ bytesWritten += file.writeSync(new Uint8Array(buffer.buffer), 0, buffer.byteLength, position! + bytesWritten);
815
815
  }
816
816
 
817
817
  return bytesWritten;
818
818
  }
819
- writevSync satisfies typeof Node.writevSync;
819
+ writevSync satisfies typeof fs.writevSync;
820
820
 
821
821
  /**
822
822
  * Synchronous `opendir`. Opens a directory.
@@ -824,11 +824,11 @@ writevSync satisfies typeof Node.writevSync;
824
824
  * @param options Options for opening the directory.
825
825
  * @returns A `Dir` object representing the opened directory.
826
826
  */
827
- export function opendirSync(path: PathLike, options?: Node.OpenDirOptions): Dir {
827
+ export function opendirSync(path: fs.PathLike, options?: fs.OpenDirOptions): Dir {
828
828
  path = normalizePath(path);
829
829
  return new Dir(path); // Re-use existing `Dir` class
830
830
  }
831
- opendirSync satisfies typeof Node.opendirSync;
831
+ opendirSync satisfies typeof fs.opendirSync;
832
832
 
833
833
  /**
834
834
  * Synchronous `cp`. Recursively copies a file or directory.
@@ -842,7 +842,7 @@ opendirSync satisfies typeof Node.opendirSync;
842
842
  * * `preserveTimestamps`: Preserve file timestamps.
843
843
  * * `recursive`: If `true`, copies directories recursively.
844
844
  */
845
- export function cpSync(source: PathLike, destination: PathLike, opts?: Node.CopySyncOptions): void {
845
+ export function cpSync(source: fs.PathLike, destination: fs.PathLike, opts?: fs.CopySyncOptions): void {
846
846
  source = normalizePath(source);
847
847
  destination = normalizePath(destination);
848
848
 
@@ -882,7 +882,7 @@ export function cpSync(source: PathLike, destination: PathLike, opts?: Node.Copy
882
882
  utimesSync(destination, srcStats.atime, srcStats.mtime);
883
883
  }
884
884
  }
885
- cpSync satisfies typeof Node.cpSync;
885
+ cpSync satisfies typeof fs.cpSync;
886
886
 
887
887
  /**
888
888
  * Synchronous statfs(2). Returns information about the mounted file system which contains path.
@@ -890,9 +890,9 @@ cpSync satisfies typeof Node.cpSync;
890
890
  * @param path A path to an existing file or directory on the file system to be queried.
891
891
  * @param callback
892
892
  */
893
- export function statfsSync(path: PathLike, options?: Node.StatFsOptions & { bigint?: false }): StatsFs;
894
- export function statfsSync(path: PathLike, options: Node.StatFsOptions & { bigint: true }): BigIntStatsFs;
895
- export function statfsSync(path: PathLike, options?: Node.StatFsOptions): StatsFs | BigIntStatsFs;
896
- export function statfsSync(path: PathLike, options?: Node.StatFsOptions): StatsFs | BigIntStatsFs {
897
- throw ApiError.With('ENOSYS', path, 'statfs');
893
+ export function statfsSync(path: fs.PathLike, options?: fs.StatFsOptions & { bigint?: false }): StatsFs;
894
+ export function statfsSync(path: fs.PathLike, options: fs.StatFsOptions & { bigint: true }): BigIntStatsFs;
895
+ export function statfsSync(path: fs.PathLike, options?: fs.StatFsOptions): StatsFs | BigIntStatsFs;
896
+ export function statfsSync(path: fs.PathLike, options?: fs.StatFsOptions): StatsFs | BigIntStatsFs {
897
+ throw ApiError.With('ENOSYS', path.toString(), 'statfs');
898
898
  }