@zenfs/core 0.16.1 → 0.16.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.
@@ -1,20 +1,21 @@
1
1
  import { Errno, ErrnoError } from '../error.js';
2
2
  import { IndexFS } from './index/fs.js';
3
3
  async function fetchFile(path, type) {
4
- const response = await fetch(path).catch(e => {
4
+ const response = await fetch(path).catch((e) => {
5
5
  throw new ErrnoError(Errno.EIO, e.message);
6
6
  });
7
7
  if (!response.ok) {
8
8
  throw new ErrnoError(Errno.EIO, 'fetch failed: response returned code ' + response.status);
9
9
  }
10
10
  switch (type) {
11
- case 'buffer':
12
- const arrayBuffer = await response.arrayBuffer().catch(e => {
11
+ case 'buffer': {
12
+ const arrayBuffer = await response.arrayBuffer().catch((e) => {
13
13
  throw new ErrnoError(Errno.EIO, e.message);
14
14
  });
15
15
  return new Uint8Array(arrayBuffer);
16
+ }
16
17
  case 'json':
17
- return response.json().catch(e => {
18
+ return response.json().catch((e) => {
18
19
  throw new ErrnoError(Errno.EIO, e.message);
19
20
  });
20
21
  default:
@@ -30,8 +30,8 @@ export class IndexFS extends Readonly(FileSystem) {
30
30
  stats.fileData = this.getDataSync(path, stats);
31
31
  }
32
32
  }
33
- async stat(path) {
34
- return this.statSync(path);
33
+ stat(path) {
34
+ return Promise.resolve(this.statSync(path));
35
35
  }
36
36
  statSync(path) {
37
37
  if (!this.index.has(path)) {
@@ -69,8 +69,8 @@ export class IndexFS extends Readonly(FileSystem) {
69
69
  }
70
70
  return new NoSyncFile(this, path, flag, stats, stats.isDirectory() ? stats.fileData : this.getDataSync(path, stats));
71
71
  }
72
- async readdir(path) {
73
- return this.readdirSync(path);
72
+ readdir(path) {
73
+ return Promise.resolve(this.readdirSync(path));
74
74
  }
75
75
  readdirSync(path) {
76
76
  // Check if it exists.
@@ -81,6 +81,13 @@ export class IndexFS extends Readonly(FileSystem) {
81
81
  if (!stats.isDirectory()) {
82
82
  throw ErrnoError.With('ENOTDIR', path, 'readdir');
83
83
  }
84
- return JSON.parse(decode(stats.fileData));
84
+ const content = JSON.parse(decode(stats.fileData));
85
+ if (!Array.isArray(content)) {
86
+ throw ErrnoError.With('ENODATA', path, 'readdir');
87
+ }
88
+ if (!content.every(item => typeof item == 'string')) {
89
+ throw ErrnoError.With('ENODATA', path, 'readdir');
90
+ }
91
+ return content;
85
92
  }
86
93
  }
@@ -47,7 +47,7 @@ export declare class UnlockedOverlayFS extends FileSystem {
47
47
  */
48
48
  _initialize(): Promise<void>;
49
49
  getDeletionLog(): string;
50
- restoreDeletionLog(log: string, cred: Cred): void;
50
+ restoreDeletionLog(log: string, cred: Cred): Promise<void>;
51
51
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
52
52
  renameSync(oldPath: string, newPath: string, cred: Cred): void;
53
53
  stat(path: string, cred: Cred): Promise<Stats>;
@@ -92,10 +92,10 @@ export class UnlockedOverlayFS extends FileSystem {
92
92
  getDeletionLog() {
93
93
  return this._deleteLog;
94
94
  }
95
- restoreDeletionLog(log, cred) {
95
+ async restoreDeletionLog(log, cred) {
96
96
  this._deleteLog = log;
97
97
  this._reparseDeletionLog();
98
- this.updateLog('', cred);
98
+ await this.updateLog('', cred);
99
99
  }
100
100
  async rename(oldPath, newPath, cred) {
101
101
  this.checkInitialized();
@@ -203,7 +203,7 @@ export class UnlockedOverlayFS extends FileSystem {
203
203
  }
204
204
  // if it still exists add to the delete log
205
205
  if (await this.exists(path, cred)) {
206
- this.deletePath(path, cred);
206
+ await this.deletePath(path, cred);
207
207
  }
208
208
  }
209
209
  unlinkSync(path, cred) {
@@ -217,7 +217,7 @@ export class UnlockedOverlayFS extends FileSystem {
217
217
  }
218
218
  // if it still exists add to the delete log
219
219
  if (this.existsSync(path, cred)) {
220
- this.deletePath(path, cred);
220
+ void this.deletePath(path, cred);
221
221
  }
222
222
  }
223
223
  async rmdir(path, cred) {
@@ -234,7 +234,7 @@ export class UnlockedOverlayFS extends FileSystem {
234
234
  throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
235
235
  }
236
236
  else {
237
- this.deletePath(path, cred);
237
+ await this.deletePath(path, cred);
238
238
  }
239
239
  }
240
240
  }
@@ -252,7 +252,7 @@ export class UnlockedOverlayFS extends FileSystem {
252
252
  throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
253
253
  }
254
254
  else {
255
- this.deletePath(path, cred);
255
+ void this.deletePath(path, cred);
256
256
  }
257
257
  }
258
258
  }
@@ -328,9 +328,9 @@ export class UnlockedOverlayFS extends FileSystem {
328
328
  return result;
329
329
  });
330
330
  }
331
- deletePath(path, cred) {
331
+ async deletePath(path, cred) {
332
332
  this._deletedFiles.add(path);
333
- this.updateLog(`d${path}\n`, cred);
333
+ await this.updateLog(`d${path}\n`, cred);
334
334
  }
335
335
  async updateLog(addition, cred) {
336
336
  this._deleteLog += addition;
@@ -344,7 +344,7 @@ export class UnlockedOverlayFS extends FileSystem {
344
344
  await log.write(encode(this._deleteLog));
345
345
  if (this._deleteLogUpdateNeeded) {
346
346
  this._deleteLogUpdateNeeded = false;
347
- this.updateLog('', cred);
347
+ await this.updateLog('', cred);
348
348
  }
349
349
  }
350
350
  catch (e) {
@@ -80,7 +80,7 @@ export function catchMessages(port) {
80
80
  detach(port, handler);
81
81
  for (const event of events) {
82
82
  const request = 'data' in event ? event.data : event;
83
- handleRequest(port, fs, request);
83
+ void handleRequest(port, fs, request);
84
84
  }
85
85
  };
86
86
  }
@@ -598,7 +598,7 @@ export class StoreFS extends FileSystem {
598
598
  return inode;
599
599
  }
600
600
  catch (e) {
601
- tx.abort();
601
+ await tx.abort();
602
602
  throw e;
603
603
  }
604
604
  }