@zenfs/core 0.0.12 → 0.1.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/ApiError.d.ts +1 -1
- package/dist/ApiError.js +17 -16
- package/dist/backends/AsyncMirror.js +40 -46
- package/dist/backends/AsyncStore.js +326 -383
- package/dist/backends/FolderAdapter.js +8 -19
- package/dist/backends/Locked.js +91 -137
- package/dist/backends/OverlayFS.js +234 -279
- package/dist/backends/SyncStore.js +2 -2
- package/dist/backends/backend.d.ts +6 -6
- package/dist/browser.min.js +23 -6
- package/dist/browser.min.js.map +4 -4
- package/dist/emulation/callbacks.d.ts +109 -72
- package/dist/emulation/callbacks.js +40 -47
- package/dist/emulation/dir.d.ts +55 -0
- package/dist/emulation/dir.js +104 -0
- package/dist/emulation/fs.d.ts +1 -2
- package/dist/emulation/fs.js +0 -1
- package/dist/emulation/index.d.ts +3 -0
- package/dist/emulation/index.js +3 -0
- package/dist/emulation/promises.d.ts +71 -50
- package/dist/emulation/promises.js +243 -342
- package/dist/emulation/shared.d.ts +14 -0
- package/dist/emulation/shared.js +4 -3
- package/dist/emulation/streams.d.ts +102 -0
- package/dist/emulation/streams.js +55 -0
- package/dist/emulation/sync.d.ts +81 -52
- package/dist/emulation/sync.js +98 -65
- package/dist/file.d.ts +11 -5
- package/dist/file.js +79 -76
- package/dist/filesystem.d.ts +3 -3
- package/dist/filesystem.js +181 -262
- package/dist/index.d.ts +3 -3
- package/dist/index.js +39 -53
- package/dist/stats.d.ts +80 -27
- package/dist/stats.js +142 -93
- package/dist/utils.d.ts +2 -6
- package/dist/utils.js +79 -78
- package/package.json +4 -2
- package/readme.md +2 -40
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
var _a;
|
|
11
2
|
import { BaseFileSystem } from '../filesystem.js';
|
|
12
3
|
import { relative, join } from '../emulation/path.js';
|
|
@@ -42,21 +33,19 @@ export class FolderAdapter extends BaseFileSystem {
|
|
|
42
33
|
this._ready = this._initialize();
|
|
43
34
|
}
|
|
44
35
|
get metadata() {
|
|
45
|
-
return
|
|
36
|
+
return { ...super.metadata, ...this._wrapped.metadata, supportsLinks: false };
|
|
46
37
|
}
|
|
47
38
|
/**
|
|
48
39
|
* Initialize the file system. Ensures that the wrapped file system
|
|
49
40
|
* has the given folder.
|
|
50
41
|
*/
|
|
51
|
-
_initialize() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return this;
|
|
59
|
-
});
|
|
42
|
+
async _initialize() {
|
|
43
|
+
const exists = await this._wrapped.exists(this._folder, Cred.Root);
|
|
44
|
+
if (!exists && this._wrapped.metadata.readonly) {
|
|
45
|
+
throw ApiError.ENOENT(this._folder);
|
|
46
|
+
}
|
|
47
|
+
await this._wrapped.mkdir(this._folder, 0o777, Cred.Root);
|
|
48
|
+
return this;
|
|
60
49
|
}
|
|
61
50
|
}
|
|
62
51
|
_a = FolderAdapter;
|
package/dist/backends/Locked.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import Mutex from '../mutex.js';
|
|
11
2
|
/**
|
|
12
3
|
* This class serializes access to an underlying async filesystem.
|
|
@@ -27,17 +18,18 @@ export default class LockedFS {
|
|
|
27
18
|
return this._ready;
|
|
28
19
|
}
|
|
29
20
|
get metadata() {
|
|
30
|
-
return
|
|
21
|
+
return {
|
|
22
|
+
...this._fs.metadata,
|
|
23
|
+
name: 'LockedFS<' + this._fs.metadata.name + '>',
|
|
24
|
+
};
|
|
31
25
|
}
|
|
32
26
|
get fs() {
|
|
33
27
|
return this._fs;
|
|
34
28
|
}
|
|
35
|
-
rename(oldPath, newPath, cred) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this._mu.unlock(oldPath);
|
|
40
|
-
});
|
|
29
|
+
async rename(oldPath, newPath, cred) {
|
|
30
|
+
await this._mu.lock(oldPath);
|
|
31
|
+
await this._fs.rename(oldPath, newPath, cred);
|
|
32
|
+
this._mu.unlock(oldPath);
|
|
41
33
|
}
|
|
42
34
|
renameSync(oldPath, newPath, cred) {
|
|
43
35
|
if (this._mu.isLocked(oldPath)) {
|
|
@@ -45,13 +37,11 @@ export default class LockedFS {
|
|
|
45
37
|
}
|
|
46
38
|
return this._fs.renameSync(oldPath, newPath, cred);
|
|
47
39
|
}
|
|
48
|
-
stat(p, cred) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return stats;
|
|
54
|
-
});
|
|
40
|
+
async stat(p, cred) {
|
|
41
|
+
await this._mu.lock(p);
|
|
42
|
+
const stats = await this._fs.stat(p, cred);
|
|
43
|
+
this._mu.unlock(p);
|
|
44
|
+
return stats;
|
|
55
45
|
}
|
|
56
46
|
statSync(p, cred) {
|
|
57
47
|
if (this._mu.isLocked(p)) {
|
|
@@ -59,12 +49,10 @@ export default class LockedFS {
|
|
|
59
49
|
}
|
|
60
50
|
return this._fs.statSync(p, cred);
|
|
61
51
|
}
|
|
62
|
-
access(p, mode, cred) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this._mu.unlock(p);
|
|
67
|
-
});
|
|
52
|
+
async access(p, mode, cred) {
|
|
53
|
+
await this._mu.lock(p);
|
|
54
|
+
await this._fs.access(p, mode, cred);
|
|
55
|
+
this._mu.unlock(p);
|
|
68
56
|
}
|
|
69
57
|
accessSync(p, mode, cred) {
|
|
70
58
|
if (this._mu.isLocked(p)) {
|
|
@@ -72,13 +60,11 @@ export default class LockedFS {
|
|
|
72
60
|
}
|
|
73
61
|
return this._fs.accessSync(p, mode, cred);
|
|
74
62
|
}
|
|
75
|
-
open(p, flag, mode, cred) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return fd;
|
|
81
|
-
});
|
|
63
|
+
async open(p, flag, mode, cred) {
|
|
64
|
+
await this._mu.lock(p);
|
|
65
|
+
const fd = await this._fs.open(p, flag, mode, cred);
|
|
66
|
+
this._mu.unlock(p);
|
|
67
|
+
return fd;
|
|
82
68
|
}
|
|
83
69
|
openSync(p, flag, mode, cred) {
|
|
84
70
|
if (this._mu.isLocked(p)) {
|
|
@@ -86,12 +72,10 @@ export default class LockedFS {
|
|
|
86
72
|
}
|
|
87
73
|
return this._fs.openSync(p, flag, mode, cred);
|
|
88
74
|
}
|
|
89
|
-
unlink(p, cred) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this._mu.unlock(p);
|
|
94
|
-
});
|
|
75
|
+
async unlink(p, cred) {
|
|
76
|
+
await this._mu.lock(p);
|
|
77
|
+
await this._fs.unlink(p, cred);
|
|
78
|
+
this._mu.unlock(p);
|
|
95
79
|
}
|
|
96
80
|
unlinkSync(p, cred) {
|
|
97
81
|
if (this._mu.isLocked(p)) {
|
|
@@ -99,12 +83,10 @@ export default class LockedFS {
|
|
|
99
83
|
}
|
|
100
84
|
return this._fs.unlinkSync(p, cred);
|
|
101
85
|
}
|
|
102
|
-
rmdir(p, cred) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this._mu.unlock(p);
|
|
107
|
-
});
|
|
86
|
+
async rmdir(p, cred) {
|
|
87
|
+
await this._mu.lock(p);
|
|
88
|
+
await this._fs.rmdir(p, cred);
|
|
89
|
+
this._mu.unlock(p);
|
|
108
90
|
}
|
|
109
91
|
rmdirSync(p, cred) {
|
|
110
92
|
if (this._mu.isLocked(p)) {
|
|
@@ -112,12 +94,10 @@ export default class LockedFS {
|
|
|
112
94
|
}
|
|
113
95
|
return this._fs.rmdirSync(p, cred);
|
|
114
96
|
}
|
|
115
|
-
mkdir(p, mode, cred) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this._mu.unlock(p);
|
|
120
|
-
});
|
|
97
|
+
async mkdir(p, mode, cred) {
|
|
98
|
+
await this._mu.lock(p);
|
|
99
|
+
await this._fs.mkdir(p, mode, cred);
|
|
100
|
+
this._mu.unlock(p);
|
|
121
101
|
}
|
|
122
102
|
mkdirSync(p, mode, cred) {
|
|
123
103
|
if (this._mu.isLocked(p)) {
|
|
@@ -125,13 +105,11 @@ export default class LockedFS {
|
|
|
125
105
|
}
|
|
126
106
|
return this._fs.mkdirSync(p, mode, cred);
|
|
127
107
|
}
|
|
128
|
-
readdir(p, cred) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return files;
|
|
134
|
-
});
|
|
108
|
+
async readdir(p, cred) {
|
|
109
|
+
await this._mu.lock(p);
|
|
110
|
+
const files = await this._fs.readdir(p, cred);
|
|
111
|
+
this._mu.unlock(p);
|
|
112
|
+
return files;
|
|
135
113
|
}
|
|
136
114
|
readdirSync(p, cred) {
|
|
137
115
|
if (this._mu.isLocked(p)) {
|
|
@@ -139,13 +117,11 @@ export default class LockedFS {
|
|
|
139
117
|
}
|
|
140
118
|
return this._fs.readdirSync(p, cred);
|
|
141
119
|
}
|
|
142
|
-
exists(p, cred) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return exists;
|
|
148
|
-
});
|
|
120
|
+
async exists(p, cred) {
|
|
121
|
+
await this._mu.lock(p);
|
|
122
|
+
const exists = await this._fs.exists(p, cred);
|
|
123
|
+
this._mu.unlock(p);
|
|
124
|
+
return exists;
|
|
149
125
|
}
|
|
150
126
|
existsSync(p, cred) {
|
|
151
127
|
if (this._mu.isLocked(p)) {
|
|
@@ -153,13 +129,11 @@ export default class LockedFS {
|
|
|
153
129
|
}
|
|
154
130
|
return this._fs.existsSync(p, cred);
|
|
155
131
|
}
|
|
156
|
-
realpath(p, cred) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return resolvedPath;
|
|
162
|
-
});
|
|
132
|
+
async realpath(p, cred) {
|
|
133
|
+
await this._mu.lock(p);
|
|
134
|
+
const resolvedPath = await this._fs.realpath(p, cred);
|
|
135
|
+
this._mu.unlock(p);
|
|
136
|
+
return resolvedPath;
|
|
163
137
|
}
|
|
164
138
|
realpathSync(p, cred) {
|
|
165
139
|
if (this._mu.isLocked(p)) {
|
|
@@ -167,12 +141,10 @@ export default class LockedFS {
|
|
|
167
141
|
}
|
|
168
142
|
return this._fs.realpathSync(p, cred);
|
|
169
143
|
}
|
|
170
|
-
truncate(p, len, cred) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this._mu.unlock(p);
|
|
175
|
-
});
|
|
144
|
+
async truncate(p, len, cred) {
|
|
145
|
+
await this._mu.lock(p);
|
|
146
|
+
await this._fs.truncate(p, len, cred);
|
|
147
|
+
this._mu.unlock(p);
|
|
176
148
|
}
|
|
177
149
|
truncateSync(p, len, cred) {
|
|
178
150
|
if (this._mu.isLocked(p)) {
|
|
@@ -180,13 +152,11 @@ export default class LockedFS {
|
|
|
180
152
|
}
|
|
181
153
|
return this._fs.truncateSync(p, len, cred);
|
|
182
154
|
}
|
|
183
|
-
readFile(fname, flag, cred) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return data;
|
|
189
|
-
});
|
|
155
|
+
async readFile(fname, flag, cred) {
|
|
156
|
+
await this._mu.lock(fname);
|
|
157
|
+
const data = await this._fs.readFile(fname, flag, cred);
|
|
158
|
+
this._mu.unlock(fname);
|
|
159
|
+
return data;
|
|
190
160
|
}
|
|
191
161
|
readFileSync(fname, flag, cred) {
|
|
192
162
|
if (this._mu.isLocked(fname)) {
|
|
@@ -194,12 +164,10 @@ export default class LockedFS {
|
|
|
194
164
|
}
|
|
195
165
|
return this._fs.readFileSync(fname, flag, cred);
|
|
196
166
|
}
|
|
197
|
-
writeFile(fname, data, flag, mode, cred) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this._mu.unlock(fname);
|
|
202
|
-
});
|
|
167
|
+
async writeFile(fname, data, flag, mode, cred) {
|
|
168
|
+
await this._mu.lock(fname);
|
|
169
|
+
await this._fs.writeFile(fname, data, flag, mode, cred);
|
|
170
|
+
this._mu.unlock(fname);
|
|
203
171
|
}
|
|
204
172
|
writeFileSync(fname, data, flag, mode, cred) {
|
|
205
173
|
if (this._mu.isLocked(fname)) {
|
|
@@ -207,12 +175,10 @@ export default class LockedFS {
|
|
|
207
175
|
}
|
|
208
176
|
return this._fs.writeFileSync(fname, data, flag, mode, cred);
|
|
209
177
|
}
|
|
210
|
-
appendFile(fname, data, flag, mode, cred) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
this._mu.unlock(fname);
|
|
215
|
-
});
|
|
178
|
+
async appendFile(fname, data, flag, mode, cred) {
|
|
179
|
+
await this._mu.lock(fname);
|
|
180
|
+
await this._fs.appendFile(fname, data, flag, mode, cred);
|
|
181
|
+
this._mu.unlock(fname);
|
|
216
182
|
}
|
|
217
183
|
appendFileSync(fname, data, flag, mode, cred) {
|
|
218
184
|
if (this._mu.isLocked(fname)) {
|
|
@@ -220,12 +186,10 @@ export default class LockedFS {
|
|
|
220
186
|
}
|
|
221
187
|
return this._fs.appendFileSync(fname, data, flag, mode, cred);
|
|
222
188
|
}
|
|
223
|
-
chmod(p, mode, cred) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
this._mu.unlock(p);
|
|
228
|
-
});
|
|
189
|
+
async chmod(p, mode, cred) {
|
|
190
|
+
await this._mu.lock(p);
|
|
191
|
+
await this._fs.chmod(p, mode, cred);
|
|
192
|
+
this._mu.unlock(p);
|
|
229
193
|
}
|
|
230
194
|
chmodSync(p, mode, cred) {
|
|
231
195
|
if (this._mu.isLocked(p)) {
|
|
@@ -233,12 +197,10 @@ export default class LockedFS {
|
|
|
233
197
|
}
|
|
234
198
|
return this._fs.chmodSync(p, mode, cred);
|
|
235
199
|
}
|
|
236
|
-
chown(p, new_uid, new_gid, cred) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
this._mu.unlock(p);
|
|
241
|
-
});
|
|
200
|
+
async chown(p, new_uid, new_gid, cred) {
|
|
201
|
+
await this._mu.lock(p);
|
|
202
|
+
await this._fs.chown(p, new_uid, new_gid, cred);
|
|
203
|
+
this._mu.unlock(p);
|
|
242
204
|
}
|
|
243
205
|
chownSync(p, new_uid, new_gid, cred) {
|
|
244
206
|
if (this._mu.isLocked(p)) {
|
|
@@ -246,12 +208,10 @@ export default class LockedFS {
|
|
|
246
208
|
}
|
|
247
209
|
return this._fs.chownSync(p, new_uid, new_gid, cred);
|
|
248
210
|
}
|
|
249
|
-
utimes(p, atime, mtime, cred) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
this._mu.unlock(p);
|
|
254
|
-
});
|
|
211
|
+
async utimes(p, atime, mtime, cred) {
|
|
212
|
+
await this._mu.lock(p);
|
|
213
|
+
await this._fs.utimes(p, atime, mtime, cred);
|
|
214
|
+
this._mu.unlock(p);
|
|
255
215
|
}
|
|
256
216
|
utimesSync(p, atime, mtime, cred) {
|
|
257
217
|
if (this._mu.isLocked(p)) {
|
|
@@ -259,12 +219,10 @@ export default class LockedFS {
|
|
|
259
219
|
}
|
|
260
220
|
return this._fs.utimesSync(p, atime, mtime, cred);
|
|
261
221
|
}
|
|
262
|
-
link(srcpath, dstpath, cred) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
this._mu.unlock(srcpath);
|
|
267
|
-
});
|
|
222
|
+
async link(srcpath, dstpath, cred) {
|
|
223
|
+
await this._mu.lock(srcpath);
|
|
224
|
+
await this._fs.link(srcpath, dstpath, cred);
|
|
225
|
+
this._mu.unlock(srcpath);
|
|
268
226
|
}
|
|
269
227
|
linkSync(srcpath, dstpath, cred) {
|
|
270
228
|
if (this._mu.isLocked(srcpath)) {
|
|
@@ -272,12 +230,10 @@ export default class LockedFS {
|
|
|
272
230
|
}
|
|
273
231
|
return this._fs.linkSync(srcpath, dstpath, cred);
|
|
274
232
|
}
|
|
275
|
-
symlink(srcpath, dstpath, type, cred) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
this._mu.unlock(srcpath);
|
|
280
|
-
});
|
|
233
|
+
async symlink(srcpath, dstpath, type, cred) {
|
|
234
|
+
await this._mu.lock(srcpath);
|
|
235
|
+
await this._fs.symlink(srcpath, dstpath, type, cred);
|
|
236
|
+
this._mu.unlock(srcpath);
|
|
281
237
|
}
|
|
282
238
|
symlinkSync(srcpath, dstpath, type, cred) {
|
|
283
239
|
if (this._mu.isLocked(srcpath)) {
|
|
@@ -285,13 +241,11 @@ export default class LockedFS {
|
|
|
285
241
|
}
|
|
286
242
|
return this._fs.symlinkSync(srcpath, dstpath, type, cred);
|
|
287
243
|
}
|
|
288
|
-
readlink(p, cred) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return linkString;
|
|
294
|
-
});
|
|
244
|
+
async readlink(p, cred) {
|
|
245
|
+
await this._mu.lock(p);
|
|
246
|
+
const linkString = await this._fs.readlink(p, cred);
|
|
247
|
+
this._mu.unlock(p);
|
|
248
|
+
return linkString;
|
|
295
249
|
}
|
|
296
250
|
readlinkSync(p, cred) {
|
|
297
251
|
if (this._mu.isLocked(p)) {
|