@zenfs/core 1.2.1 → 1.2.2

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.
@@ -10,11 +10,23 @@ export declare function setEnabled(value: boolean): void;
10
10
  /**
11
11
  * Gets stats from the cache, if they exist and the cache is enabled.
12
12
  */
13
- export declare function getStats(path: string): Stats | undefined;
13
+ export declare function getStatsSync(path: string): Stats | undefined;
14
14
  /**
15
15
  * Adds stats if the cache is enabled
16
16
  */
17
- export declare function setStats(path: string, value: Stats): void;
17
+ export declare function setStatsSync(path: string, value: Stats): void;
18
+ /**
19
+ * Clears the cache if it is enabled
20
+ */
21
+ export declare function clearStatsSync(): void;
22
+ /**
23
+ * Gets stats from the cache, if they exist and the cache is enabled.
24
+ */
25
+ export declare function getStats(path: string): Promise<Stats | undefined> | undefined;
26
+ /**
27
+ * Adds stats if the cache is enabled
28
+ */
29
+ export declare function setStats(path: string, value: Promise<Stats | undefined>): void;
18
30
  /**
19
31
  * Clears the cache if it is enabled
20
32
  */
@@ -9,6 +9,31 @@ export let isEnabled = false;
9
9
  export function setEnabled(value) {
10
10
  isEnabled = value;
11
11
  }
12
+ const statsSync = new Map();
13
+ /**
14
+ * Gets stats from the cache, if they exist and the cache is enabled.
15
+ */
16
+ export function getStatsSync(path) {
17
+ if (!isEnabled)
18
+ return;
19
+ return statsSync.get(path);
20
+ }
21
+ /**
22
+ * Adds stats if the cache is enabled
23
+ */
24
+ export function setStatsSync(path, value) {
25
+ if (!isEnabled)
26
+ return;
27
+ statsSync.set(path, value);
28
+ }
29
+ /**
30
+ * Clears the cache if it is enabled
31
+ */
32
+ export function clearStatsSync() {
33
+ if (!isEnabled)
34
+ return;
35
+ statsSync.clear();
36
+ }
12
37
  const stats = new Map();
13
38
  /**
14
39
  * Gets stats from the cache, if they exist and the cache is enabled.
@@ -435,7 +435,7 @@ export async function unlink(path) {
435
435
  path = normalizePath(path);
436
436
  const { fs, path: resolved } = resolveMount(path);
437
437
  try {
438
- if (config.checkAccess && !(cache.getStats(path) || (await fs.stat(resolved))).hasAccess(constants.W_OK)) {
438
+ if (config.checkAccess && !(await (cache.getStats(path) || fs.stat(resolved))).hasAccess(constants.W_OK)) {
439
439
  throw ErrnoError.With('EACCES', resolved, 'unlink');
440
440
  }
441
441
  await fs.unlink(resolved);
@@ -584,7 +584,10 @@ export async function rmdir(path) {
584
584
  path = await realpath(path);
585
585
  const { fs, path: resolved } = resolveMount(path);
586
586
  try {
587
- const stats = cache.getStats(path) || (await fs.stat(resolved));
587
+ const stats = await (cache.getStats(path) || fs.stat(resolved));
588
+ if (!stats) {
589
+ throw ErrnoError.With('ENOENT', path, 'readdir');
590
+ }
588
591
  if (!stats.isDirectory()) {
589
592
  throw ErrnoError.With('ENOTDIR', resolved, 'rmdir');
590
593
  }
@@ -640,8 +643,12 @@ export async function readdir(path, options) {
640
643
  throw fixError(e, { [resolved]: path });
641
644
  };
642
645
  const { fs, path: resolved } = resolveMount(path);
643
- const stats = cache.getStats(path) || (await fs.stat(resolved).catch(handleError));
644
- cache.setStats(path, stats);
646
+ const _stats = cache.getStats(path) || fs.stat(resolved).catch(handleError);
647
+ cache.setStats(path, _stats);
648
+ const stats = await _stats;
649
+ if (!stats) {
650
+ throw ErrnoError.With('ENOENT', path, 'readdir');
651
+ }
645
652
  if (config.checkAccess && !stats.hasAccess(constants.R_OK)) {
646
653
  throw ErrnoError.With('EACCES', path, 'readdir');
647
654
  }
@@ -663,8 +670,9 @@ export async function readdir(path, options) {
663
670
  const addEntry = async (entry) => {
664
671
  let entryStats;
665
672
  if (options?.recursive || options?.withFileTypes) {
666
- entryStats = cache.getStats(join(path, entry)) || (await fs.stat(join(resolved, entry)).catch(handleError));
667
- cache.setStats(join(path, entry), entryStats);
673
+ const _entryStats = cache.getStats(join(path, entry)) || fs.stat(join(resolved, entry)).catch(handleError);
674
+ cache.setStats(join(path, entry), _entryStats);
675
+ entryStats = await _entryStats;
668
676
  }
669
677
  if (options?.withFileTypes) {
670
678
  values.push(new Dirent(entry, entryStats));
@@ -934,15 +942,17 @@ access;
934
942
  */
935
943
  export async function rm(path, options) {
936
944
  path = normalizePath(path);
937
- const stats = cache.getStats(path) ||
938
- (await stat(path).catch((error) => {
939
- if (error.code != 'ENOENT' || !options?.force)
940
- throw error;
941
- }));
945
+ const _stats = cache.getStats(path) ||
946
+ stat(path).catch((error) => {
947
+ if (error.code == 'ENOENT' && options?.force)
948
+ return undefined;
949
+ throw error;
950
+ });
951
+ cache.setStats(path, _stats);
952
+ const stats = await _stats;
942
953
  if (!stats) {
943
954
  return;
944
955
  }
945
- cache.setStats(path, stats);
946
956
  switch (stats.mode & constants.S_IFMT) {
947
957
  case constants.S_IFDIR:
948
958
  if (options?.recursive) {
@@ -147,7 +147,7 @@ export function unlinkSync(path) {
147
147
  path = normalizePath(path);
148
148
  const { fs, path: resolved } = resolveMount(path);
149
149
  try {
150
- if (config.checkAccess && !(cache.getStats(path) || fs.statSync(resolved)).hasAccess(constants.W_OK)) {
150
+ if (config.checkAccess && !(cache.getStatsSync(path) || fs.statSync(resolved)).hasAccess(constants.W_OK)) {
151
151
  throw ErrnoError.With('EACCES', resolved, 'unlink');
152
152
  }
153
153
  fs.unlinkSync(resolved);
@@ -394,7 +394,7 @@ export function rmdirSync(path) {
394
394
  path = normalizePath(path);
395
395
  const { fs, path: resolved } = resolveMount(realpathSync(path));
396
396
  try {
397
- const stats = cache.getStats(path) || fs.statSync(resolved);
397
+ const stats = cache.getStatsSync(path) || fs.statSync(resolved);
398
398
  if (!stats.isDirectory()) {
399
399
  throw ErrnoError.With('ENOTDIR', resolved, 'rmdir');
400
400
  }
@@ -447,8 +447,8 @@ export function readdirSync(path, options) {
447
447
  const { fs, path: resolved } = resolveMount(realpathSync(path));
448
448
  let entries;
449
449
  try {
450
- const stats = cache.getStats(path) || fs.statSync(resolved);
451
- cache.setStats(path, stats);
450
+ const stats = cache.getStatsSync(path) || fs.statSync(resolved);
451
+ cache.setStatsSync(path, stats);
452
452
  if (config.checkAccess && !stats.hasAccess(constants.R_OK)) {
453
453
  throw ErrnoError.With('EACCES', resolved, 'readdir');
454
454
  }
@@ -474,8 +474,8 @@ export function readdirSync(path, options) {
474
474
  // Iterate over entries and handle recursive case if needed
475
475
  const values = [];
476
476
  for (const entry of entries) {
477
- const entryStat = cache.getStats(join(path, entry)) || fs.statSync(join(resolved, entry));
478
- cache.setStats(join(path, entry), entryStat);
477
+ const entryStat = cache.getStatsSync(join(path, entry)) || fs.statSync(join(resolved, entry));
478
+ cache.setStatsSync(join(path, entry), entryStat);
479
479
  if (options?.withFileTypes) {
480
480
  values.push(new Dirent(entry, entryStat));
481
481
  }
@@ -501,7 +501,7 @@ export function readdirSync(path, options) {
501
501
  }
502
502
  }
503
503
  if (!options?._isIndirect) {
504
- cache.clearStats();
504
+ cache.clearStatsSync();
505
505
  }
506
506
  return values;
507
507
  }
@@ -638,7 +638,7 @@ export function rmSync(path, options) {
638
638
  path = normalizePath(path);
639
639
  let stats;
640
640
  try {
641
- stats = cache.getStats(path) || statSync(path);
641
+ stats = cache.getStatsSync(path) || statSync(path);
642
642
  }
643
643
  catch (error) {
644
644
  if (error.code != 'ENOENT' || !options?.force)
@@ -647,7 +647,7 @@ export function rmSync(path, options) {
647
647
  if (!stats) {
648
648
  return;
649
649
  }
650
- cache.setStats(path, stats);
650
+ cache.setStatsSync(path, stats);
651
651
  switch (stats.mode & constants.S_IFMT) {
652
652
  case constants.S_IFDIR:
653
653
  if (options?.recursive) {
@@ -666,11 +666,11 @@ export function rmSync(path, options) {
666
666
  case constants.S_IFIFO:
667
667
  case constants.S_IFSOCK:
668
668
  default:
669
- cache.clearStats();
669
+ cache.clearStatsSync();
670
670
  throw new ErrnoError(Errno.EPERM, 'File type not supported', path, 'rm');
671
671
  }
672
672
  if (!options?._isIndirect) {
673
- cache.clearStats();
673
+ cache.clearStatsSync();
674
674
  }
675
675
  }
676
676
  rmSync;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "A filesystem, anywhere",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -14,12 +14,41 @@ export function setEnabled(value: boolean): void {
14
14
  isEnabled = value;
15
15
  }
16
16
 
17
- const stats = new Map<string, Stats>();
17
+ const statsSync = new Map<string, Stats>();
18
18
 
19
19
  /**
20
20
  * Gets stats from the cache, if they exist and the cache is enabled.
21
21
  */
22
- export function getStats(path: string): Stats | undefined {
22
+ export function getStatsSync(path: string): Stats | undefined {
23
+ if (!isEnabled) return;
24
+
25
+ return statsSync.get(path);
26
+ }
27
+
28
+ /**
29
+ * Adds stats if the cache is enabled
30
+ */
31
+ export function setStatsSync(path: string, value: Stats): void {
32
+ if (!isEnabled) return;
33
+
34
+ statsSync.set(path, value);
35
+ }
36
+
37
+ /**
38
+ * Clears the cache if it is enabled
39
+ */
40
+ export function clearStatsSync(): void {
41
+ if (!isEnabled) return;
42
+
43
+ statsSync.clear();
44
+ }
45
+
46
+ const stats = new Map<string, Promise<Stats | undefined>>();
47
+
48
+ /**
49
+ * Gets stats from the cache, if they exist and the cache is enabled.
50
+ */
51
+ export function getStats(path: string): Promise<Stats | undefined> | undefined {
23
52
  if (!isEnabled) return;
24
53
 
25
54
  return stats.get(path);
@@ -28,7 +57,7 @@ export function getStats(path: string): Stats | undefined {
28
57
  /**
29
58
  * Adds stats if the cache is enabled
30
59
  */
31
- export function setStats(path: string, value: Stats): void {
60
+ export function setStats(path: string, value: Promise<Stats | undefined>): void {
32
61
  if (!isEnabled) return;
33
62
 
34
63
  stats.set(path, value);
@@ -471,7 +471,7 @@ export async function unlink(path: fs.PathLike): Promise<void> {
471
471
  path = normalizePath(path);
472
472
  const { fs, path: resolved } = resolveMount(path);
473
473
  try {
474
- if (config.checkAccess && !(cache.getStats(path) || (await fs.stat(resolved))).hasAccess(constants.W_OK)) {
474
+ if (config.checkAccess && !(await (cache.getStats(path) || fs.stat(resolved)))!.hasAccess(constants.W_OK)) {
475
475
  throw ErrnoError.With('EACCES', resolved, 'unlink');
476
476
  }
477
477
  await fs.unlink(resolved);
@@ -624,7 +624,10 @@ export async function rmdir(path: fs.PathLike): Promise<void> {
624
624
  path = await realpath(path);
625
625
  const { fs, path: resolved } = resolveMount(path);
626
626
  try {
627
- const stats = cache.getStats(path) || (await fs.stat(resolved));
627
+ const stats = await (cache.getStats(path) || fs.stat(resolved));
628
+ if (!stats) {
629
+ throw ErrnoError.With('ENOENT', path, 'readdir');
630
+ }
628
631
  if (!stats.isDirectory()) {
629
632
  throw ErrnoError.With('ENOTDIR', resolved, 'rmdir');
630
633
  }
@@ -716,8 +719,13 @@ export async function readdir(
716
719
 
717
720
  const { fs, path: resolved } = resolveMount(path);
718
721
 
719
- const stats = cache.getStats(path) || (await fs.stat(resolved).catch(handleError));
720
- cache.setStats(path, stats);
722
+ const _stats = cache.getStats(path) || fs.stat(resolved).catch(handleError);
723
+ cache.setStats(path, _stats);
724
+ const stats = await _stats;
725
+
726
+ if (!stats) {
727
+ throw ErrnoError.With('ENOENT', path, 'readdir');
728
+ }
721
729
 
722
730
  if (config.checkAccess && !stats.hasAccess(constants.R_OK)) {
723
731
  throw ErrnoError.With('EACCES', path, 'readdir');
@@ -744,8 +752,9 @@ export async function readdir(
744
752
  const addEntry = async (entry: string) => {
745
753
  let entryStats: Stats | undefined;
746
754
  if (options?.recursive || options?.withFileTypes) {
747
- entryStats = cache.getStats(join(path, entry)) || (await fs.stat(join(resolved, entry)).catch(handleError));
748
- cache.setStats(join(path, entry), entryStats);
755
+ const _entryStats = cache.getStats(join(path, entry)) || fs.stat(join(resolved, entry)).catch(handleError);
756
+ cache.setStats(join(path, entry), _entryStats);
757
+ entryStats = await _entryStats;
749
758
  }
750
759
  if (options?.withFileTypes) {
751
760
  values.push(new Dirent(entry, entryStats!));
@@ -968,18 +977,20 @@ access satisfies typeof promises.access;
968
977
  export async function rm(path: fs.PathLike, options?: fs.RmOptions & InternalOptions) {
969
978
  path = normalizePath(path);
970
979
 
971
- const stats =
980
+ const _stats =
972
981
  cache.getStats(path) ||
973
- (await stat(path).catch((error: ErrnoError) => {
974
- if (error.code != 'ENOENT' || !options?.force) throw error;
975
- }));
982
+ stat(path).catch((error: ErrnoError) => {
983
+ if (error.code == 'ENOENT' && options?.force) return undefined;
984
+ throw error;
985
+ });
986
+
987
+ cache.setStats(path, _stats);
988
+ const stats = await _stats;
976
989
 
977
990
  if (!stats) {
978
991
  return;
979
992
  }
980
993
 
981
- cache.setStats(path, stats);
982
-
983
994
  switch (stats.mode & constants.S_IFMT) {
984
995
  case constants.S_IFDIR:
985
996
  if (options?.recursive) {
@@ -106,7 +106,7 @@ export function unlinkSync(path: fs.PathLike): void {
106
106
  path = normalizePath(path);
107
107
  const { fs, path: resolved } = resolveMount(path);
108
108
  try {
109
- if (config.checkAccess && !(cache.getStats(path) || fs.statSync(resolved)).hasAccess(constants.W_OK)) {
109
+ if (config.checkAccess && !(cache.getStatsSync(path) || fs.statSync(resolved)).hasAccess(constants.W_OK)) {
110
110
  throw ErrnoError.With('EACCES', resolved, 'unlink');
111
111
  }
112
112
  fs.unlinkSync(resolved);
@@ -387,7 +387,7 @@ export function rmdirSync(path: fs.PathLike): void {
387
387
  path = normalizePath(path);
388
388
  const { fs, path: resolved } = resolveMount(realpathSync(path));
389
389
  try {
390
- const stats = cache.getStats(path) || fs.statSync(resolved);
390
+ const stats = cache.getStatsSync(path) || fs.statSync(resolved);
391
391
  if (!stats.isDirectory()) {
392
392
  throw ErrnoError.With('ENOTDIR', resolved, 'rmdir');
393
393
  }
@@ -460,8 +460,8 @@ export function readdirSync(
460
460
  const { fs, path: resolved } = resolveMount(realpathSync(path));
461
461
  let entries: string[];
462
462
  try {
463
- const stats = cache.getStats(path) || fs.statSync(resolved);
464
- cache.setStats(path, stats);
463
+ const stats = cache.getStatsSync(path) || fs.statSync(resolved);
464
+ cache.setStatsSync(path, stats);
465
465
  if (config.checkAccess && !stats.hasAccess(constants.R_OK)) {
466
466
  throw ErrnoError.With('EACCES', resolved, 'readdir');
467
467
  }
@@ -488,8 +488,8 @@ export function readdirSync(
488
488
  // Iterate over entries and handle recursive case if needed
489
489
  const values: (string | Dirent | Buffer)[] = [];
490
490
  for (const entry of entries) {
491
- const entryStat = cache.getStats(join(path, entry)) || fs.statSync(join(resolved, entry));
492
- cache.setStats(join(path, entry), entryStat);
491
+ const entryStat = cache.getStatsSync(join(path, entry)) || fs.statSync(join(resolved, entry));
492
+ cache.setStatsSync(join(path, entry), entryStat);
493
493
 
494
494
  if (options?.withFileTypes) {
495
495
  values.push(new Dirent(entry, entryStat));
@@ -513,7 +513,7 @@ export function readdirSync(
513
513
  }
514
514
 
515
515
  if (!options?._isIndirect) {
516
- cache.clearStats();
516
+ cache.clearStatsSync();
517
517
  }
518
518
  return values as string[] | Dirent[] | Buffer[];
519
519
  }
@@ -671,7 +671,7 @@ export function rmSync(path: fs.PathLike, options?: fs.RmOptions & InternalOptio
671
671
 
672
672
  let stats: Stats | undefined;
673
673
  try {
674
- stats = cache.getStats(path) || statSync(path);
674
+ stats = cache.getStatsSync(path) || statSync(path);
675
675
  } catch (error) {
676
676
  if ((error as ErrnoError).code != 'ENOENT' || !options?.force) throw error;
677
677
  }
@@ -680,7 +680,7 @@ export function rmSync(path: fs.PathLike, options?: fs.RmOptions & InternalOptio
680
680
  return;
681
681
  }
682
682
 
683
- cache.setStats(path, stats);
683
+ cache.setStatsSync(path, stats);
684
684
 
685
685
  switch (stats.mode & constants.S_IFMT) {
686
686
  case constants.S_IFDIR:
@@ -701,12 +701,12 @@ export function rmSync(path: fs.PathLike, options?: fs.RmOptions & InternalOptio
701
701
  case constants.S_IFIFO:
702
702
  case constants.S_IFSOCK:
703
703
  default:
704
- cache.clearStats();
704
+ cache.clearStatsSync();
705
705
  throw new ErrnoError(Errno.EPERM, 'File type not supported', path, 'rm');
706
706
  }
707
707
 
708
708
  if (!options?._isIndirect) {
709
- cache.clearStats();
709
+ cache.clearStatsSync();
710
710
  }
711
711
  }
712
712
  rmSync satisfies typeof fs.rmSync;
@@ -10,7 +10,7 @@ suite('appendFile', () => {
10
10
  const filename = 'append.txt';
11
11
  await fs.promises.appendFile(filename, content);
12
12
  const data = await fs.promises.readFile(filename, 'utf8');
13
- assert(data == content);
13
+ assert.equal(data, content);
14
14
  });
15
15
 
16
16
  test('append data to a non-empty file', async () => {
@@ -19,7 +19,7 @@ suite('appendFile', () => {
19
19
  await fs.promises.writeFile(filename, original);
20
20
  await fs.promises.appendFile(filename, content);
21
21
  const data = await fs.promises.readFile(filename, 'utf8');
22
- assert(data == original + content);
22
+ assert.equal(data, original + content);
23
23
  });
24
24
 
25
25
  test('append a buffer to the file', async () => {
@@ -28,6 +28,6 @@ suite('appendFile', () => {
28
28
  await fs.promises.writeFile(filename, original);
29
29
  await fs.promises.appendFile(filename, content);
30
30
  const data = await fs.promises.readFile(filename, 'utf8');
31
- assert(data == original + content);
31
+ assert.equal(data, original + content);
32
32
  });
33
33
  });
@@ -18,8 +18,8 @@ suite('Dirent', () => {
18
18
  const stats = await fs.promises.lstat(testFile);
19
19
  const dirent = new fs.Dirent(testFile, stats);
20
20
 
21
- assert(dirent.name === testFile);
22
- assert(dirent.parentPath === testFile);
21
+ assert.equal(dirent.name, testFile);
22
+ assert.equal(dirent.parentPath, testFile);
23
23
  });
24
24
 
25
25
  test('Dirent.isFile', async () => {
@@ -68,7 +68,7 @@ suite('Dir', () => {
68
68
  assert(testFiles.includes(dirent2?.name));
69
69
 
70
70
  const dirent3 = await dir.read();
71
- assert(dirent3 === null);
71
+ assert.strictEqual(dirent3, null);
72
72
 
73
73
  await dir.close();
74
74
  });
@@ -76,8 +76,8 @@ suite('Dir', () => {
76
76
  test('Dir read() method (Callback varient)', (_, done) => {
77
77
  const dir = new fs.Dir(testDirPath);
78
78
  dir.read((err, dirent) => {
79
- assert(err === undefined);
80
- assert(dirent != undefined);
79
+ assert.strictEqual(err, undefined);
80
+ assert.notEqual(dirent, undefined);
81
81
  assert(dirent instanceof fs.Dirent);
82
82
  assert(testFiles.includes(dirent?.name));
83
83
  dir.closeSync();
@@ -97,7 +97,7 @@ suite('Dir', () => {
97
97
  assert(testFiles.includes(dirent2?.name));
98
98
 
99
99
  const dirent3 = dir.readSync();
100
- assert(dirent3 === null);
100
+ assert.strictEqual(dirent3, null);
101
101
 
102
102
  dir.closeSync();
103
103
  });
@@ -122,7 +122,7 @@ suite('Dir', () => {
122
122
  dirents.push(dirent);
123
123
  }
124
124
 
125
- assert(dirents.length === 2);
125
+ assert.strictEqual(dirents.length, 2);
126
126
  assert(dirents[0] instanceof fs.Dirent);
127
127
  assert(testFiles.includes(dirents[0].name));
128
128
  assert(testFiles.includes(dirents[1].name));
@@ -17,7 +17,7 @@ suite('Directory', () => {
17
17
  await fs.promises.mkdir('/nested/dir');
18
18
  } catch (error: any) {
19
19
  assert(error instanceof ErrnoError);
20
- assert(error.code === 'ENOENT');
20
+ assert.strictEqual(error.code, 'ENOENT');
21
21
  }
22
22
  assert(!(await fs.promises.exists('/nested/dir')));
23
23
  });
@@ -51,7 +51,7 @@ suite('Directory', () => {
51
51
  fs.readdirSync('/two');
52
52
  } catch (error: any) {
53
53
  assert(error instanceof ErrnoError);
54
- assert(error.code === 'EACCES');
54
+ assert.strictEqual(error.code, 'EACCES');
55
55
  }
56
56
  });
57
57
 
@@ -63,7 +63,7 @@ suite('Directory', () => {
63
63
  await fs.promises.rmdir('/rmdirTest');
64
64
  } catch (error: any) {
65
65
  assert(error instanceof ErrnoError);
66
- assert(error.code === 'ENOTEMPTY');
66
+ assert.strictEqual(error.code, 'ENOTEMPTY');
67
67
  }
68
68
  });
69
69
 
@@ -75,7 +75,7 @@ suite('Directory', () => {
75
75
  } catch (error: any) {
76
76
  assert(error instanceof ErrnoError);
77
77
  wasThrown = true;
78
- assert(error.code === 'ENOTDIR');
78
+ assert.strictEqual(error.code, 'ENOTDIR');
79
79
  }
80
80
  assert(wasThrown);
81
81
  });
@@ -85,7 +85,7 @@ suite('Directory', () => {
85
85
  await fs.promises.readdir('a.js');
86
86
  } catch (error: any) {
87
87
  assert(error instanceof ErrnoError);
88
- assert(error.code === 'ENOTDIR');
88
+ assert.strictEqual(error.code, 'ENOTDIR');
89
89
  }
90
90
  });
91
91
 
@@ -97,7 +97,7 @@ suite('Directory', () => {
97
97
  } catch (error: any) {
98
98
  assert(error instanceof ErrnoError);
99
99
  wasThrown = true;
100
- assert(error.code === 'ENOENT');
100
+ assert.strictEqual(error.code, 'ENOENT');
101
101
  }
102
102
  assert(wasThrown);
103
103
  });
@@ -107,7 +107,7 @@ suite('Directory', () => {
107
107
  await fs.promises.readdir('/does/not/exist');
108
108
  } catch (error: any) {
109
109
  assert(error instanceof ErrnoError);
110
- assert(error.code === 'ENOENT');
110
+ assert.strictEqual(error.code, 'ENOENT');
111
111
  }
112
112
  });
113
113
 
@@ -19,7 +19,7 @@ suite('Links', () => {
19
19
 
20
20
  test('readlink', async () => {
21
21
  const destination = await fs.promises.readlink(symlink);
22
- assert(destination === target);
22
+ assert.strictEqual(destination, target);
23
23
  });
24
24
 
25
25
  test('unlink', async () => {
@@ -32,7 +32,7 @@ suite('Links', () => {
32
32
  await fs.promises.link(target, hardlink);
33
33
  const targetContent = await fs.promises.readFile(target, 'utf8');
34
34
  const linkContent = await fs.promises.readFile(hardlink, 'utf8');
35
- assert(targetContent === linkContent);
35
+ assert.strictEqual(targetContent, linkContent);
36
36
  });
37
37
 
38
38
  test('file inside symlinked directory', async () => {
@@ -41,6 +41,6 @@ suite('Links', () => {
41
41
  const link = join('link', target);
42
42
  assert((await fs.promises.realpath(link)) === target);
43
43
  const linkContent = await fs.promises.readFile(link, 'utf8');
44
- assert(targetContent === linkContent);
44
+ assert.strictEqual(targetContent, linkContent);
45
45
  });
46
46
  });
@@ -12,7 +12,7 @@ suite('fs file opening', () => {
12
12
  fs.openSync('/path/to/file/that/does/not/exist', 'r');
13
13
  } catch (error: any) {
14
14
  assert(error instanceof ErrnoError);
15
- assert(error?.code === 'ENOENT');
15
+ assert.strictEqual(error?.code, 'ENOENT');
16
16
  caughtException = true;
17
17
  }
18
18
  assert(caughtException);
@@ -23,7 +23,7 @@ suite('fs file opening', () => {
23
23
  await fs.promises.open('/path/to/file/that/does/not/exist', 'r');
24
24
  } catch (error: any) {
25
25
  assert(error instanceof ErrnoError);
26
- assert(error?.code === 'ENOENT');
26
+ assert.strictEqual(error?.code, 'ENOENT');
27
27
  }
28
28
  });
29
29
 
@@ -10,7 +10,7 @@ suite('Permissions', () => {
10
10
  async function test_item(path: string): Promise<void> {
11
11
  const stats = await fs.promises.stat(path).catch((error: ErrnoError) => {
12
12
  assert(error instanceof ErrnoError);
13
- assert(error.code === 'EACCES');
13
+ assert.strictEqual(error.code, 'EACCES');
14
14
  });
15
15
  if (!stats) {
16
16
  return;
@@ -10,7 +10,7 @@ suite('read', () => {
10
10
  const handle = await fs.promises.open(filepath, 'r');
11
11
  const { bytesRead, buffer } = await handle.read(Buffer.alloc(expected.length), 0, expected.length, 0);
12
12
 
13
- assert(bytesRead == expected.length);
13
+ assert.equal(bytesRead, expected.length);
14
14
  assert(buffer.toString() == expected);
15
15
  });
16
16
 
@@ -19,7 +19,7 @@ suite('read', () => {
19
19
  const buffer = Buffer.alloc(expected.length);
20
20
  const bytesRead = fs.readSync(fd, buffer, 0, expected.length, 0);
21
21
 
22
- assert(bytesRead == expected.length);
22
+ assert.equal(bytesRead, expected.length);
23
23
  assert(buffer.toString() == expected);
24
24
  });
25
25
  });
@@ -44,7 +44,7 @@ suite('read buffer', () => {
44
44
  const handle = await fs.promises.open(filepath, 'r');
45
45
  const { bytesRead } = await handle.read(bufferAsync, 0, expected.length, 0);
46
46
 
47
- assert(bytesRead === expected.length);
47
+ assert.strictEqual(bytesRead, expected.length);
48
48
  assert(bufferAsync.toString() === expected);
49
49
  });
50
50
 
@@ -53,7 +53,7 @@ suite('read buffer', () => {
53
53
  const bytesRead = fs.readSync(fd, bufferSync, 0, expected.length, 0);
54
54
 
55
55
  assert(bufferSync.toString() === expected);
56
- assert(bytesRead === expected.length);
56
+ assert.strictEqual(bytesRead, expected.length);
57
57
  });
58
58
 
59
59
  test('read file synchronously to non-zero offset', () => {
@@ -62,6 +62,6 @@ suite('read buffer', () => {
62
62
  const bytesRead = fs.readSync(fd, buffer, 10, expected.length, 0);
63
63
 
64
64
  assert(buffer.subarray(10, buffer.length).toString() === expected);
65
- assert(bytesRead === expected.length);
65
+ assert.strictEqual(bytesRead, expected.length);
66
66
  });
67
67
  });
@@ -65,9 +65,9 @@ suite('fs file reading', () => {
65
65
  const content = fs.readFileSync('elipses.txt', 'utf8');
66
66
 
67
67
  for (let i = 0; i < content.length; i++) {
68
- assert(content[i] === '…');
68
+ assert.strictEqual(content[i], '…');
69
69
  }
70
70
 
71
- assert(content.length === 10000);
71
+ assert.strictEqual(content.length, 10000);
72
72
  });
73
73
  });
@@ -21,10 +21,10 @@ suite('Rename', () => {
21
21
  */
22
22
  async function check_directory(dir: string) {
23
23
  const contents = await fs.promises.readdir(dir);
24
- assert(contents.length === 2);
24
+ assert.strictEqual(contents.length, 2);
25
25
 
26
26
  const subContents = await fs.promises.readdir(dir + '/_rename_me');
27
- assert(subContents.length === 1);
27
+ assert.strictEqual(subContents.length, 1);
28
28
 
29
29
  assert(await fs.promises.exists(dir + '/file.dat'));
30
30
  assert(await fs.promises.exists(dir + '/_rename_me/lol.txt'));
@@ -88,7 +88,7 @@ suite('Rename', () => {
88
88
  if (e == null) {
89
89
  throw new Error("Failed invariant: Cannot rename a directory over a file.");
90
90
  } else {
91
- assert(e.code === 'ENOTDIR');
91
+ assert.strictEqual(e.code, 'ENOTDIR');
92
92
  }
93
93
  });*/
94
94
  });
@@ -101,7 +101,7 @@ suite('Rename', () => {
101
101
 
102
102
  await fs.promises.rename(renDir1, renDir2).catch((error: ErrnoError) => {
103
103
  assert(error instanceof ErrnoError);
104
- assert(error.code === 'EBUSY');
104
+ assert.strictEqual(error.code, 'EBUSY');
105
105
  });
106
106
  });
107
107
  });
@@ -18,7 +18,7 @@ suite('ReadStream', () => {
18
18
  data += chunk;
19
19
  });
20
20
  readStream.on('end', () => {
21
- assert(data == testData);
21
+ assert.equal(data, testData);
22
22
  done();
23
23
  });
24
24
  readStream.on('error', err => {
@@ -33,7 +33,7 @@ suite('ReadStream', () => {
33
33
  closed = true;
34
34
  });
35
35
  readStream.close(err => {
36
- assert(err === undefined);
36
+ assert.strictEqual(err, undefined);
37
37
  assert(closed);
38
38
  done();
39
39
  });
@@ -41,27 +41,27 @@ suite('ReadStream', () => {
41
41
 
42
42
  test('ReadStream declared properties', () => {
43
43
  const readStream = new fs.ReadStream();
44
- assert(readStream.bytesRead === undefined);
45
- assert(readStream.path === undefined);
46
- assert(readStream.pending === undefined);
44
+ assert.strictEqual(readStream.bytesRead, undefined);
45
+ assert.strictEqual(readStream.path, undefined);
46
+ assert.strictEqual(readStream.pending, undefined);
47
47
 
48
48
  // Assign values
49
49
  readStream.bytesRead = 10;
50
50
  readStream.path = testFilePath;
51
51
  readStream.pending = false;
52
52
 
53
- assert(readStream.bytesRead === 10);
54
- assert(readStream.path === testFilePath);
53
+ assert.strictEqual(readStream.bytesRead, 10);
54
+ assert.strictEqual(readStream.path, testFilePath);
55
55
  assert(!readStream.pending);
56
56
  });
57
57
 
58
58
  test('ReadStream close method can be called multiple times', (_, done) => {
59
59
  const readStream = new fs.ReadStream();
60
60
  readStream.close(err => {
61
- assert(err === undefined);
61
+ assert.strictEqual(err, undefined);
62
62
  // Call close again
63
63
  readStream.close(err2 => {
64
- assert(err2 === undefined);
64
+ assert.strictEqual(err2, undefined);
65
65
  done();
66
66
  });
67
67
  });
@@ -94,7 +94,7 @@ suite('WriteStream', () => {
94
94
  closed = true;
95
95
  });
96
96
  writeStream.close(err => {
97
- assert(err === undefined);
97
+ assert.strictEqual(err, undefined);
98
98
  assert(closed);
99
99
  done();
100
100
  });
@@ -102,27 +102,27 @@ suite('WriteStream', () => {
102
102
 
103
103
  test('WriteStream declared properties', () => {
104
104
  const writeStream = new fs.WriteStream();
105
- assert(writeStream.bytesWritten === undefined);
106
- assert(writeStream.path === undefined);
107
- assert(writeStream.pending === undefined);
105
+ assert.strictEqual(writeStream.bytesWritten, undefined);
106
+ assert.strictEqual(writeStream.path, undefined);
107
+ assert.strictEqual(writeStream.pending, undefined);
108
108
 
109
109
  // Assign values
110
110
  writeStream.bytesWritten = 20;
111
111
  writeStream.path = testFilePathWrite;
112
112
  writeStream.pending = true;
113
113
 
114
- assert(writeStream.bytesWritten === 20);
115
- assert(writeStream.path === testFilePathWrite);
114
+ assert.strictEqual(writeStream.bytesWritten, 20);
115
+ assert.strictEqual(writeStream.path, testFilePathWrite);
116
116
  assert(writeStream.pending);
117
117
  });
118
118
 
119
119
  test('WriteStream close method can be called multiple times', (_, done) => {
120
120
  const writeStream = new fs.WriteStream();
121
121
  writeStream.close(err => {
122
- assert(err === undefined);
122
+ assert.strictEqual(err, undefined);
123
123
  // Call close again
124
124
  writeStream.close(err2 => {
125
- assert(err2 === undefined);
125
+ assert.strictEqual(err2, undefined);
126
126
  done();
127
127
  });
128
128
  });
@@ -139,7 +139,7 @@ suite('FileHandle', () => {
139
139
  data += chunk;
140
140
  });
141
141
  readStream.on('end', () => {
142
- assert(data == testData);
142
+ assert.equal(data, testData);
143
143
  resolve();
144
144
  });
145
145
  readStream.on('error', reject);
@@ -159,7 +159,7 @@ suite('FileHandle', () => {
159
159
  writeStream.on('error', reject);
160
160
  });
161
161
  const data = await fs.promises.readFile(testFilePathWrite, 'utf8');
162
- assert(data == testData);
162
+ assert.equal(data, testData);
163
163
  await fileHandle.close();
164
164
  });
165
165
 
@@ -21,7 +21,7 @@ suite('times', () => {
21
21
 
22
22
  await fs.promises.utimes('foobarbaz', atime, mtime).catch((error: ErrnoError) => {
23
23
  assert(error instanceof ErrnoError);
24
- assert(error.code === 'ENOENT');
24
+ assert.strictEqual(error.code, 'ENOENT');
25
25
  });
26
26
 
27
27
  // don't close this fd
@@ -40,21 +40,21 @@ suite('times', () => {
40
40
  expect_assert(handle.fd, atime, mtime);
41
41
  } catch (error: any) {
42
42
  assert(error instanceof ErrnoError);
43
- assert(error.code === 'ENOSYS');
43
+ assert.strictEqual(error.code, 'ENOSYS');
44
44
  }
45
45
 
46
46
  try {
47
47
  fs.utimesSync('foobarbaz', atime, mtime);
48
48
  } catch (error: any) {
49
49
  assert(error instanceof ErrnoError);
50
- assert(error.code === 'ENOENT');
50
+ assert.strictEqual(error.code, 'ENOENT');
51
51
  }
52
52
 
53
53
  try {
54
54
  fs.futimesSync(-1, atime, mtime);
55
55
  } catch (error: any) {
56
56
  assert(error instanceof ErrnoError);
57
- assert(error.code == 'EBADF');
57
+ assert.equal(error.code, 'EBADF');
58
58
  }
59
59
  }
60
60
 
@@ -14,8 +14,8 @@ await fs.promises.writeFile(testFile, 'Initial content');
14
14
  suite('Watch Features', () => {
15
15
  test('fs.watch should emit events on file change', async () => {
16
16
  using watcher = fs.watch(testFile, (eventType, filename) => {
17
- assert(eventType === 'change');
18
- assert(filename === 'test.txt');
17
+ assert.strictEqual(eventType, 'change');
18
+ assert.strictEqual(filename, 'test.txt');
19
19
  });
20
20
 
21
21
  // Modify the file to trigger the event
@@ -24,8 +24,8 @@ suite('Watch Features', () => {
24
24
 
25
25
  test('fs.watch should emit events on file rename (delete)', async () => {
26
26
  using watcher = fs.watch(testFile, (eventType, filename) => {
27
- assert(eventType === 'rename');
28
- assert(filename === 'test.txt');
27
+ assert.strictEqual(eventType, 'rename');
28
+ assert.strictEqual(filename, 'test.txt');
29
29
  });
30
30
 
31
31
  // Delete the file to trigger the event
@@ -63,8 +63,8 @@ suite('Watch Features', () => {
63
63
 
64
64
  test('fs.watch should work with directories', async () => {
65
65
  using watcher = fs.watch(testDir, (eventType, filename) => {
66
- assert(eventType === 'change');
67
- assert(filename === 'newFile.txt');
66
+ assert.strictEqual(eventType, 'change');
67
+ assert.strictEqual(filename, 'newFile.txt');
68
68
  });
69
69
 
70
70
  await fs.promises.writeFile(`${testDir}/newFile.txt`, 'Content');
@@ -77,8 +77,8 @@ suite('Watch Features', () => {
77
77
  await fs.promises.writeFile(oldFile, 'Some content');
78
78
 
79
79
  using watcher = fs.watch(testDir, (eventType, filename) => {
80
- assert(eventType === 'rename');
81
- assert(filename === 'oldFile.txt');
80
+ assert.strictEqual(eventType, 'rename');
81
+ assert.strictEqual(filename, 'oldFile.txt');
82
82
  });
83
83
 
84
84
  // Rename the file to trigger the event
@@ -91,8 +91,8 @@ suite('Watch Features', () => {
91
91
  await fs.promises.writeFile(tempFile, 'Temporary content');
92
92
 
93
93
  using watcher = fs.watch(tempFile, (eventType, filename) => {
94
- assert(eventType === 'rename');
95
- assert(filename === 'tempFile.txt');
94
+ assert.strictEqual(eventType, 'rename');
95
+ assert.strictEqual(filename, 'tempFile.txt');
96
96
  });
97
97
 
98
98
  await fs.promises.unlink(tempFile);
@@ -10,11 +10,11 @@ suite('write', () => {
10
10
  const handle = await fs.promises.open(fn, 'w', 0o644);
11
11
  await handle.write('', 0, 'utf8');
12
12
  const { bytesWritten } = await handle.write(expected, 0, 'utf8');
13
- assert(bytesWritten === Buffer.from(expected).length);
13
+ assert.strictEqual(bytesWritten, Buffer.from(expected).length);
14
14
  await handle.close();
15
15
 
16
16
  const data = await fs.promises.readFile(fn, 'utf8');
17
- assert(data === expected);
17
+ assert.strictEqual(data, expected);
18
18
 
19
19
  await fs.promises.unlink(fn);
20
20
  });
@@ -27,7 +27,7 @@ suite('write', () => {
27
27
 
28
28
  const written = await handle.write(expected, 0, expected.length, null);
29
29
 
30
- assert(expected.length === written.bytesWritten);
30
+ assert.strictEqual(expected.length, written.bytesWritten);
31
31
 
32
32
  await handle.close();
33
33
 
@@ -43,13 +43,13 @@ suite('writeSync', () => {
43
43
  const fd = fs.openSync(fn, 'w');
44
44
 
45
45
  let written = fs.writeSync(fd, '');
46
- assert(written === 0);
46
+ assert.strictEqual(written, 0);
47
47
 
48
48
  fs.writeSync(fd, 'foo');
49
49
 
50
50
  const data = Buffer.from('bár');
51
51
  written = fs.writeSync(fd, data, 0, data.length);
52
- assert(written === 4);
52
+ assert.strictEqual(written, 4);
53
53
 
54
54
  fs.closeSync(fd);
55
55
 
@@ -10,7 +10,7 @@ suite('writeFile', () => {
10
10
  const filename = 'test.txt';
11
11
  await fs.promises.writeFile(filename, s);
12
12
  const data = await fs.promises.readFile(filename);
13
- assert(data.length === Buffer.from(s).length);
13
+ assert.strictEqual(data.length, Buffer.from(s).length);
14
14
  await fs.promises.unlink(filename);
15
15
  });
16
16
 
@@ -20,7 +20,7 @@ suite('writeFile', () => {
20
20
 
21
21
  await fs.promises.writeFile(filename, expected);
22
22
  const actual = await fs.promises.readFile(filename);
23
- assert(actual.length === expected.length);
23
+ assert.strictEqual(actual.length, expected.length);
24
24
 
25
25
  await fs.promises.unlink(filename);
26
26
  });
@@ -35,7 +35,7 @@ suite('writeFile', () => {
35
35
  await fs.promises.writeFile(filePath, buffer);
36
36
 
37
37
  const read = await fs.promises.readFile(filePath, 'base64');
38
- assert(read === data);
38
+ assert.strictEqual(read, data);
39
39
  });
40
40
  });
41
41
 
@@ -47,7 +47,7 @@ suite('File Writing with Custom Mode', () => {
47
47
  fs.writeFileSync(file, '123', { mode });
48
48
 
49
49
  const content = fs.readFileSync(file, 'utf8');
50
- assert(content === '123');
50
+ assert.strictEqual(content, '123');
51
51
  assert((fs.statSync(file).mode & 0o777) === mode);
52
52
 
53
53
  fs.unlinkSync(file);
@@ -60,7 +60,7 @@ suite('File Writing with Custom Mode', () => {
60
60
  fs.appendFileSync(file, 'abc', { mode });
61
61
 
62
62
  const content = fs.readFileSync(file, { encoding: 'utf8' });
63
- assert(content === 'abc');
63
+ assert.strictEqual(content, 'abc');
64
64
 
65
65
  assert((fs.statSync(file).mode & 0o777) === mode);
66
66
 
@@ -50,8 +50,8 @@ await suite('FileHandle', () => {
50
50
  test('chown', async () => {
51
51
  await handle.chown(1234, 5678);
52
52
  const stats = await handle.stat();
53
- assert(stats.uid === 1234);
54
- assert(stats.gid === 5678);
53
+ assert.equal(stats.uid, 1234);
54
+ assert.equal(stats.gid, 5678);
55
55
  });
56
56
 
57
57
  test('close', async () => {
@@ -57,6 +57,6 @@ suite('LockFS mutex', () => {
57
57
  }
58
58
 
59
59
  await Promise.all([foo(), foo(), foo()]);
60
- assert(x === 4);
60
+ assert.strictEqual(x, 4);
61
61
  });
62
62
  });
@@ -26,7 +26,7 @@ await suite('Timeout', { timeout: 1000 }, () => {
26
26
  error = e;
27
27
  }
28
28
  assert(error! instanceof ErrnoError);
29
- assert(error.code === 'EIO');
29
+ assert.strictEqual(error.code, 'EIO');
30
30
  assert(error.message.includes('RPC Failed'));
31
31
  });
32
32
 
@@ -40,7 +40,7 @@ await suite('Timeout', { timeout: 1000 }, () => {
40
40
  error = e;
41
41
  }
42
42
  assert(error! instanceof ErrnoError);
43
- assert(error.code === 'EIO');
43
+ assert.strictEqual(error.code, 'EIO');
44
44
  assert(error.message.includes('RPC Failed'));
45
45
  });
46
46
  });