@zenfs/core 0.9.7 → 0.11.0
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/Index.d.ts +3 -3
- package/dist/backends/Index.js +23 -23
- package/dist/backends/backend.js +6 -5
- package/dist/backends/fetch.d.ts +84 -0
- package/dist/backends/fetch.js +170 -0
- package/dist/backends/{Locked.d.ts → locked.d.ts} +13 -13
- package/dist/backends/{Locked.js → locked.js} +54 -54
- package/dist/backends/{InMemory.d.ts → memory.d.ts} +7 -9
- package/dist/backends/memory.js +38 -0
- package/dist/backends/{Overlay.d.ts → overlay.d.ts} +12 -13
- package/dist/backends/{Overlay.js → overlay.js} +105 -110
- package/dist/backends/port/fs.d.ts +123 -0
- package/dist/backends/port/fs.js +239 -0
- package/dist/backends/port/rpc.d.ts +60 -0
- package/dist/backends/port/rpc.js +71 -0
- package/dist/backends/store/fs.d.ts +169 -0
- package/dist/backends/store/fs.js +743 -0
- package/dist/backends/store/simple.d.ts +64 -0
- package/dist/backends/store/simple.js +111 -0
- package/dist/backends/store/store.d.ts +111 -0
- package/dist/backends/store/store.js +62 -0
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.d.ts +8 -10
- package/dist/config.js +11 -11
- package/dist/emulation/async.js +6 -6
- package/dist/emulation/dir.js +2 -2
- package/dist/emulation/index.d.ts +1 -1
- package/dist/emulation/index.js +1 -1
- package/dist/emulation/path.d.ts +3 -2
- package/dist/emulation/path.js +19 -45
- package/dist/emulation/promises.d.ts +7 -12
- package/dist/emulation/promises.js +144 -146
- package/dist/emulation/shared.d.ts +5 -10
- package/dist/emulation/shared.js +9 -9
- package/dist/emulation/streams.js +3 -3
- package/dist/emulation/sync.js +25 -25
- package/dist/{ApiError.d.ts → error.d.ts} +13 -15
- package/dist/error.js +291 -0
- package/dist/file.d.ts +2 -0
- package/dist/file.js +11 -5
- package/dist/filesystem.d.ts +3 -3
- package/dist/filesystem.js +41 -44
- package/dist/index.d.ts +7 -6
- package/dist/index.js +7 -6
- package/dist/inode.d.ts +1 -1
- package/dist/mutex.js +2 -1
- package/dist/utils.d.ts +8 -7
- package/dist/utils.js +11 -12
- package/package.json +3 -3
- package/readme.md +17 -9
- package/src/backends/Index.ts +23 -23
- package/src/backends/backend.ts +8 -7
- package/src/backends/fetch.ts +229 -0
- package/src/backends/{Locked.ts → locked.ts} +55 -55
- package/src/backends/memory.ts +44 -0
- package/src/backends/{Overlay.ts → overlay.ts} +108 -114
- package/src/backends/port/fs.ts +306 -0
- package/src/backends/port/readme.md +59 -0
- package/src/backends/port/rpc.ts +144 -0
- package/src/backends/store/fs.ts +881 -0
- package/src/backends/store/readme.md +9 -0
- package/src/backends/store/simple.ts +144 -0
- package/src/backends/store/store.ts +164 -0
- package/src/config.ts +21 -25
- package/src/emulation/async.ts +6 -6
- package/src/emulation/dir.ts +2 -2
- package/src/emulation/index.ts +1 -1
- package/src/emulation/path.ts +25 -49
- package/src/emulation/promises.ts +150 -159
- package/src/emulation/shared.ts +13 -15
- package/src/emulation/streams.ts +3 -3
- package/src/emulation/sync.ts +28 -28
- package/src/{ApiError.ts → error.ts} +89 -90
- package/src/file.ts +13 -5
- package/src/filesystem.ts +44 -47
- package/src/index.ts +7 -6
- package/src/inode.ts +1 -1
- package/src/mutex.ts +3 -1
- package/src/utils.ts +16 -18
- package/tsconfig.json +2 -2
- package/dist/ApiError.js +0 -292
- package/dist/backends/AsyncStore.d.ts +0 -204
- package/dist/backends/AsyncStore.js +0 -509
- package/dist/backends/InMemory.js +0 -49
- package/dist/backends/SyncStore.d.ts +0 -213
- package/dist/backends/SyncStore.js +0 -445
- package/src/backends/AsyncStore.ts +0 -655
- package/src/backends/InMemory.ts +0 -56
- package/src/backends/SyncStore.ts +0 -589
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrnoError } from '../error.js';
|
|
1
2
|
import { Mutex } from '../mutex.js';
|
|
2
3
|
/**
|
|
3
4
|
* This class serializes access to an underlying async filesystem.
|
|
@@ -16,7 +17,6 @@ export class LockedFS {
|
|
|
16
17
|
}
|
|
17
18
|
async ready() {
|
|
18
19
|
await this.fs.ready();
|
|
19
|
-
return this;
|
|
20
20
|
}
|
|
21
21
|
metadata() {
|
|
22
22
|
return {
|
|
@@ -31,21 +31,21 @@ export class LockedFS {
|
|
|
31
31
|
}
|
|
32
32
|
renameSync(oldPath, newPath, cred) {
|
|
33
33
|
if (this._mu.isLocked(oldPath)) {
|
|
34
|
-
throw
|
|
34
|
+
throw ErrnoError.With('EBUSY', oldPath, 'rename');
|
|
35
35
|
}
|
|
36
36
|
return this.fs.renameSync(oldPath, newPath, cred);
|
|
37
37
|
}
|
|
38
|
-
async stat(
|
|
39
|
-
await this._mu.lock(
|
|
40
|
-
const stats = await this.fs.stat(
|
|
41
|
-
this._mu.unlock(
|
|
38
|
+
async stat(path, cred) {
|
|
39
|
+
await this._mu.lock(path);
|
|
40
|
+
const stats = await this.fs.stat(path, cred);
|
|
41
|
+
this._mu.unlock(path);
|
|
42
42
|
return stats;
|
|
43
43
|
}
|
|
44
|
-
statSync(
|
|
45
|
-
if (this._mu.isLocked(
|
|
46
|
-
throw
|
|
44
|
+
statSync(path, cred) {
|
|
45
|
+
if (this._mu.isLocked(path)) {
|
|
46
|
+
throw ErrnoError.With('EBUSY', path, 'stat');
|
|
47
47
|
}
|
|
48
|
-
return this.fs.statSync(
|
|
48
|
+
return this.fs.statSync(path, cred);
|
|
49
49
|
}
|
|
50
50
|
async openFile(path, flag, cred) {
|
|
51
51
|
await this._mu.lock(path);
|
|
@@ -55,7 +55,7 @@ export class LockedFS {
|
|
|
55
55
|
}
|
|
56
56
|
openFileSync(path, flag, cred) {
|
|
57
57
|
if (this._mu.isLocked(path)) {
|
|
58
|
-
throw
|
|
58
|
+
throw ErrnoError.With('EBUSY', path, 'openFile');
|
|
59
59
|
}
|
|
60
60
|
return this.fs.openFileSync(path, flag, cred);
|
|
61
61
|
}
|
|
@@ -67,66 +67,66 @@ export class LockedFS {
|
|
|
67
67
|
}
|
|
68
68
|
createFileSync(path, flag, mode, cred) {
|
|
69
69
|
if (this._mu.isLocked(path)) {
|
|
70
|
-
throw
|
|
70
|
+
throw ErrnoError.With('EBUSY', path, 'createFile');
|
|
71
71
|
}
|
|
72
72
|
return this.fs.createFileSync(path, flag, mode, cred);
|
|
73
73
|
}
|
|
74
|
-
async unlink(
|
|
75
|
-
await this._mu.lock(
|
|
76
|
-
await this.fs.unlink(
|
|
77
|
-
this._mu.unlock(
|
|
74
|
+
async unlink(path, cred) {
|
|
75
|
+
await this._mu.lock(path);
|
|
76
|
+
await this.fs.unlink(path, cred);
|
|
77
|
+
this._mu.unlock(path);
|
|
78
78
|
}
|
|
79
|
-
unlinkSync(
|
|
80
|
-
if (this._mu.isLocked(
|
|
81
|
-
throw
|
|
79
|
+
unlinkSync(path, cred) {
|
|
80
|
+
if (this._mu.isLocked(path)) {
|
|
81
|
+
throw ErrnoError.With('EBUSY', path, 'unlink');
|
|
82
82
|
}
|
|
83
|
-
return this.fs.unlinkSync(
|
|
83
|
+
return this.fs.unlinkSync(path, cred);
|
|
84
84
|
}
|
|
85
|
-
async rmdir(
|
|
86
|
-
await this._mu.lock(
|
|
87
|
-
await this.fs.rmdir(
|
|
88
|
-
this._mu.unlock(
|
|
85
|
+
async rmdir(path, cred) {
|
|
86
|
+
await this._mu.lock(path);
|
|
87
|
+
await this.fs.rmdir(path, cred);
|
|
88
|
+
this._mu.unlock(path);
|
|
89
89
|
}
|
|
90
|
-
rmdirSync(
|
|
91
|
-
if (this._mu.isLocked(
|
|
92
|
-
throw
|
|
90
|
+
rmdirSync(path, cred) {
|
|
91
|
+
if (this._mu.isLocked(path)) {
|
|
92
|
+
throw ErrnoError.With('EBUSY', path, 'rmdir');
|
|
93
93
|
}
|
|
94
|
-
return this.fs.rmdirSync(
|
|
94
|
+
return this.fs.rmdirSync(path, cred);
|
|
95
95
|
}
|
|
96
|
-
async mkdir(
|
|
97
|
-
await this._mu.lock(
|
|
98
|
-
await this.fs.mkdir(
|
|
99
|
-
this._mu.unlock(
|
|
96
|
+
async mkdir(path, mode, cred) {
|
|
97
|
+
await this._mu.lock(path);
|
|
98
|
+
await this.fs.mkdir(path, mode, cred);
|
|
99
|
+
this._mu.unlock(path);
|
|
100
100
|
}
|
|
101
|
-
mkdirSync(
|
|
102
|
-
if (this._mu.isLocked(
|
|
103
|
-
throw
|
|
101
|
+
mkdirSync(path, mode, cred) {
|
|
102
|
+
if (this._mu.isLocked(path)) {
|
|
103
|
+
throw ErrnoError.With('EBUSY', path, 'mkdir');
|
|
104
104
|
}
|
|
105
|
-
return this.fs.mkdirSync(
|
|
105
|
+
return this.fs.mkdirSync(path, mode, cred);
|
|
106
106
|
}
|
|
107
|
-
async readdir(
|
|
108
|
-
await this._mu.lock(
|
|
109
|
-
const files = await this.fs.readdir(
|
|
110
|
-
this._mu.unlock(
|
|
107
|
+
async readdir(path, cred) {
|
|
108
|
+
await this._mu.lock(path);
|
|
109
|
+
const files = await this.fs.readdir(path, cred);
|
|
110
|
+
this._mu.unlock(path);
|
|
111
111
|
return files;
|
|
112
112
|
}
|
|
113
|
-
readdirSync(
|
|
114
|
-
if (this._mu.isLocked(
|
|
115
|
-
throw
|
|
113
|
+
readdirSync(path, cred) {
|
|
114
|
+
if (this._mu.isLocked(path)) {
|
|
115
|
+
throw ErrnoError.With('EBUSY', path, 'readdir');
|
|
116
116
|
}
|
|
117
|
-
return this.fs.readdirSync(
|
|
117
|
+
return this.fs.readdirSync(path, cred);
|
|
118
118
|
}
|
|
119
|
-
async exists(
|
|
120
|
-
await this._mu.lock(
|
|
121
|
-
const exists = await this.fs.exists(
|
|
122
|
-
this._mu.unlock(
|
|
119
|
+
async exists(path, cred) {
|
|
120
|
+
await this._mu.lock(path);
|
|
121
|
+
const exists = await this.fs.exists(path, cred);
|
|
122
|
+
this._mu.unlock(path);
|
|
123
123
|
return exists;
|
|
124
124
|
}
|
|
125
|
-
existsSync(
|
|
126
|
-
if (this._mu.isLocked(
|
|
127
|
-
throw
|
|
125
|
+
existsSync(path, cred) {
|
|
126
|
+
if (this._mu.isLocked(path)) {
|
|
127
|
+
throw ErrnoError.With('EBUSY', path, 'exists');
|
|
128
128
|
}
|
|
129
|
-
return this.fs.existsSync(
|
|
129
|
+
return this.fs.existsSync(path, cred);
|
|
130
130
|
}
|
|
131
131
|
async link(srcpath, dstpath, cred) {
|
|
132
132
|
await this._mu.lock(srcpath);
|
|
@@ -135,7 +135,7 @@ export class LockedFS {
|
|
|
135
135
|
}
|
|
136
136
|
linkSync(srcpath, dstpath, cred) {
|
|
137
137
|
if (this._mu.isLocked(srcpath)) {
|
|
138
|
-
throw
|
|
138
|
+
throw ErrnoError.With('EBUSY', srcpath, 'link');
|
|
139
139
|
}
|
|
140
140
|
return this.fs.linkSync(srcpath, dstpath, cred);
|
|
141
141
|
}
|
|
@@ -146,7 +146,7 @@ export class LockedFS {
|
|
|
146
146
|
}
|
|
147
147
|
syncSync(path, data, stats) {
|
|
148
148
|
if (this._mu.isLocked(path)) {
|
|
149
|
-
throw
|
|
149
|
+
throw ErrnoError.With('EBUSY', path, 'sync');
|
|
150
150
|
}
|
|
151
151
|
return this.fs.syncSync(path, data, stats);
|
|
152
152
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import type { Ino } from '../inode.js';
|
|
2
|
-
import {
|
|
2
|
+
import { StoreFS } from './store/fs.js';
|
|
3
|
+
import { SimpleTransaction, type SimpleSyncStore } from './store/simple.js';
|
|
3
4
|
/**
|
|
4
5
|
* A simple in-memory store
|
|
5
6
|
*/
|
|
6
|
-
export declare class InMemoryStore
|
|
7
|
+
export declare class InMemoryStore extends Map<Ino, Uint8Array> implements SimpleSyncStore {
|
|
7
8
|
name: string;
|
|
8
|
-
private store;
|
|
9
9
|
constructor(name?: string);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
put(key: Ino, data: Uint8Array, overwrite: boolean): boolean;
|
|
14
|
-
remove(key: Ino): void;
|
|
10
|
+
sync(): Promise<void>;
|
|
11
|
+
clearSync(): void;
|
|
12
|
+
transaction(): SimpleTransaction;
|
|
15
13
|
}
|
|
16
14
|
/**
|
|
17
15
|
* A simple in-memory file system backed by an InMemoryStore.
|
|
@@ -29,5 +27,5 @@ export declare const InMemory: {
|
|
|
29
27
|
};
|
|
30
28
|
readonly create: ({ name }: {
|
|
31
29
|
name?: string;
|
|
32
|
-
}) =>
|
|
30
|
+
}) => StoreFS;
|
|
33
31
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { StoreFS } from './store/fs.js';
|
|
2
|
+
import { SimpleTransaction } from './store/simple.js';
|
|
3
|
+
/**
|
|
4
|
+
* A simple in-memory store
|
|
5
|
+
*/
|
|
6
|
+
export class InMemoryStore extends Map {
|
|
7
|
+
constructor(name = 'tmp') {
|
|
8
|
+
super();
|
|
9
|
+
this.name = name;
|
|
10
|
+
}
|
|
11
|
+
async sync() { }
|
|
12
|
+
clearSync() {
|
|
13
|
+
this.clear();
|
|
14
|
+
}
|
|
15
|
+
transaction() {
|
|
16
|
+
return new SimpleTransaction(this);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A simple in-memory file system backed by an InMemoryStore.
|
|
21
|
+
* Files are not persisted across page loads.
|
|
22
|
+
*/
|
|
23
|
+
export const InMemory = {
|
|
24
|
+
name: 'InMemory',
|
|
25
|
+
isAvailable() {
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
options: {
|
|
29
|
+
name: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
required: false,
|
|
32
|
+
description: 'The name of the store',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
create({ name }) {
|
|
36
|
+
return new StoreFS(new InMemoryStore(name));
|
|
37
|
+
},
|
|
38
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FileSystem, FileSystemMetadata } from '../filesystem.js';
|
|
2
2
|
import { File } from '../file.js';
|
|
3
3
|
import { Stats } from '../stats.js';
|
|
4
|
-
import { LockedFS } from './
|
|
4
|
+
import { LockedFS } from './locked.js';
|
|
5
5
|
import { Cred } from '../cred.js';
|
|
6
6
|
/**
|
|
7
7
|
* Configuration options for OverlayFS instances.
|
|
@@ -25,7 +25,7 @@ export interface OverlayOptions {
|
|
|
25
25
|
* @internal
|
|
26
26
|
*/
|
|
27
27
|
export declare class UnlockedOverlayFS extends FileSystem {
|
|
28
|
-
ready(): Promise<
|
|
28
|
+
ready(): Promise<void>;
|
|
29
29
|
private _writable;
|
|
30
30
|
private _readable;
|
|
31
31
|
private _isInitialized;
|
|
@@ -49,22 +49,22 @@ export declare class UnlockedOverlayFS extends FileSystem {
|
|
|
49
49
|
restoreDeletionLog(log: string, cred: Cred): void;
|
|
50
50
|
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
51
51
|
renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
52
|
-
stat(
|
|
53
|
-
statSync(
|
|
52
|
+
stat(path: string, cred: Cred): Promise<Stats>;
|
|
53
|
+
statSync(path: string, cred: Cred): Stats;
|
|
54
54
|
openFile(path: string, flag: string, cred: Cred): Promise<File>;
|
|
55
55
|
openFileSync(path: string, flag: string, cred: Cred): File;
|
|
56
56
|
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
57
57
|
createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
|
|
58
58
|
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
59
59
|
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
60
|
-
unlink(
|
|
61
|
-
unlinkSync(
|
|
62
|
-
rmdir(
|
|
63
|
-
rmdirSync(
|
|
64
|
-
mkdir(
|
|
65
|
-
mkdirSync(
|
|
66
|
-
readdir(
|
|
67
|
-
readdirSync(
|
|
60
|
+
unlink(path: string, cred: Cred): Promise<void>;
|
|
61
|
+
unlinkSync(path: string, cred: Cred): void;
|
|
62
|
+
rmdir(path: string, cred: Cred): Promise<void>;
|
|
63
|
+
rmdirSync(path: string, cred: Cred): void;
|
|
64
|
+
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
65
|
+
mkdirSync(path: string, mode: number, cred: Cred): void;
|
|
66
|
+
readdir(path: string, cred: Cred): Promise<string[]>;
|
|
67
|
+
readdirSync(path: string, cred: Cred): string[];
|
|
68
68
|
private deletePath;
|
|
69
69
|
private updateLog;
|
|
70
70
|
private _reparseDeletionLog;
|
|
@@ -97,7 +97,6 @@ export declare class UnlockedOverlayFS extends FileSystem {
|
|
|
97
97
|
* @internal
|
|
98
98
|
*/
|
|
99
99
|
export declare class OverlayFS extends LockedFS<UnlockedOverlayFS> {
|
|
100
|
-
ready(): Promise<this>;
|
|
101
100
|
/**
|
|
102
101
|
* @param options The options to initialize the OverlayFS with
|
|
103
102
|
*/
|