@zenfs/core 0.16.1 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backends/fetch.js +5 -4
- package/dist/backends/index/fs.js +12 -5
- package/dist/backends/overlay.d.ts +1 -1
- package/dist/backends/overlay.js +9 -9
- package/dist/backends/port/rpc.js +1 -1
- package/dist/backends/store/fs.js +1 -1
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +3 -3
- package/dist/config.js +3 -5
- package/dist/emulation/async.d.ts +4 -5
- package/dist/emulation/async.js +9 -9
- package/dist/emulation/dir.js +1 -1
- package/dist/emulation/promises.js +10 -5
- package/dist/emulation/sync.d.ts +1 -0
- package/dist/emulation/sync.js +1 -1
- package/dist/file.js +6 -6
- package/dist/filesystem.js +1 -1
- package/dist/inode.d.ts +1 -1
- package/dist/inode.js +54 -37
- package/dist/polyfills.js +1 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/eslint.shared.js +53 -0
- package/package.json +10 -6
- package/scripts/build.js +1 -3
- package/src/backends/fetch.ts +6 -5
- package/src/backends/index/fs.ts +12 -5
- package/src/backends/index/index.ts +1 -1
- package/src/backends/overlay.ts +9 -9
- package/src/backends/port/rpc.ts +1 -1
- package/src/backends/store/fs.ts +2 -2
- package/src/config.ts +4 -7
- package/src/emulation/async.ts +31 -18
- package/src/emulation/dir.ts +1 -1
- package/src/emulation/promises.ts +11 -6
- package/src/emulation/sync.ts +5 -4
- package/src/file.ts +6 -6
- package/src/filesystem.ts +2 -1
- package/src/inode.ts +56 -37
- package/src/polyfills.ts +1 -0
- package/src/utils.ts +5 -2
package/dist/backends/fetch.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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>;
|
package/dist/backends/overlay.js
CHANGED
|
@@ -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) {
|