@zenfs/core 0.0.11 → 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 +43 -49
- package/dist/backends/AsyncStore.js +326 -383
- package/dist/backends/FolderAdapter.js +8 -19
- package/dist/backends/Locked.d.ts +7 -8
- package/dist/backends/Locked.js +97 -143
- package/dist/backends/OverlayFS.js +240 -284
- 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 +244 -328
- 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 +117 -69
- package/dist/file.d.ts +11 -5
- package/dist/file.js +79 -76
- package/dist/filesystem.d.ts +15 -23
- package/dist/filesystem.js +186 -273
- 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 -4
- package/dist/utils.js +80 -77
- package/package.json +4 -2
- package/readme.md +2 -40
package/dist/ApiError.d.ts
CHANGED
package/dist/ApiError.js
CHANGED
|
@@ -26,22 +26,23 @@ export var ErrorCode;
|
|
|
26
26
|
* Strings associated with each error code.
|
|
27
27
|
* @internal
|
|
28
28
|
*/
|
|
29
|
-
export const ErrorStrings = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
export const ErrorStrings = {
|
|
30
|
+
[ErrorCode.EPERM]: 'Operation not permitted.',
|
|
31
|
+
[ErrorCode.ENOENT]: 'No such file or directory.',
|
|
32
|
+
[ErrorCode.EIO]: 'Input/output error.',
|
|
33
|
+
[ErrorCode.EBADF]: 'Bad file descriptor.',
|
|
34
|
+
[ErrorCode.EACCES]: 'Permission denied.',
|
|
35
|
+
[ErrorCode.EBUSY]: 'Resource busy or locked.',
|
|
36
|
+
[ErrorCode.EEXIST]: 'File exists.',
|
|
37
|
+
[ErrorCode.ENOTDIR]: 'File is not a directory.',
|
|
38
|
+
[ErrorCode.EISDIR]: 'File is a directory.',
|
|
39
|
+
[ErrorCode.EINVAL]: 'Invalid argument.',
|
|
40
|
+
[ErrorCode.EFBIG]: 'File is too big.',
|
|
41
|
+
[ErrorCode.ENOSPC]: 'No space left on disk.',
|
|
42
|
+
[ErrorCode.EROFS]: 'Cannot modify a read-only file system.',
|
|
43
|
+
[ErrorCode.ENOTEMPTY]: 'Directory is not empty.',
|
|
44
|
+
[ErrorCode.ENOTSUP]: 'Operation is not supported.',
|
|
45
|
+
};
|
|
45
46
|
/**
|
|
46
47
|
* Represents a ZenFS error. Passed back to applications after a failed
|
|
47
48
|
* call to the ZenFS API.
|
|
@@ -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 { SynchronousFileSystem } from '../filesystem.js';
|
|
12
3
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
@@ -97,14 +88,19 @@ export class AsyncMirror extends SynchronousFileSystem {
|
|
|
97
88
|
this._ready = this._initialize();
|
|
98
89
|
}
|
|
99
90
|
get metadata() {
|
|
100
|
-
return
|
|
91
|
+
return {
|
|
92
|
+
...super.metadata,
|
|
93
|
+
name: AsyncMirror.Name,
|
|
94
|
+
synchronous: true,
|
|
95
|
+
supportsProperties: this._sync.metadata.supportsProperties && this._async.metadata.supportsProperties,
|
|
96
|
+
};
|
|
101
97
|
}
|
|
102
98
|
_syncSync(fd) {
|
|
103
99
|
const stats = fd.getStats();
|
|
104
|
-
this._sync.writeFileSync(fd.getPath(), fd.getBuffer(),
|
|
100
|
+
this._sync.writeFileSync(fd.getPath(), fd.getBuffer(), FileFlag.getFileFlag('w'), stats.mode, stats.getCred(0, 0));
|
|
105
101
|
this.enqueueOp({
|
|
106
102
|
apiMethod: 'writeFile',
|
|
107
|
-
arguments: [fd.getPath(), fd.getBuffer(),
|
|
103
|
+
arguments: [fd.getPath(), fd.getBuffer(), fd.getFlag(), stats.mode, stats.getCred(0, 0)],
|
|
108
104
|
});
|
|
109
105
|
}
|
|
110
106
|
renameSync(oldPath, newPath, cred) {
|
|
@@ -121,7 +117,7 @@ export class AsyncMirror extends SynchronousFileSystem {
|
|
|
121
117
|
// Sanity check: Is this open/close permitted?
|
|
122
118
|
const fd = this._sync.openSync(p, flag, mode, cred);
|
|
123
119
|
fd.closeSync();
|
|
124
|
-
return new MirrorFile(this, p, flag, this._sync.statSync(p, cred), this._sync.readFileSync(p,
|
|
120
|
+
return new MirrorFile(this, p, flag, this._sync.statSync(p, cred), this._sync.readFileSync(p, FileFlag.getFileFlag('r'), cred));
|
|
125
121
|
}
|
|
126
122
|
unlinkSync(p, cred) {
|
|
127
123
|
this._sync.unlinkSync(p, cred);
|
|
@@ -174,42 +170,40 @@ export class AsyncMirror extends SynchronousFileSystem {
|
|
|
174
170
|
/**
|
|
175
171
|
* Called once to load up files from async storage into sync storage.
|
|
176
172
|
*/
|
|
177
|
-
_initialize() {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
yield copyItem(join(p, file));
|
|
189
|
-
}
|
|
190
|
-
}), copyFile = (p, mode) => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
const data = yield this._async.readFile(p, null, FileFlag.getFileFlag('r'), Cred.Root);
|
|
192
|
-
this._sync.writeFileSync(p, data, null, FileFlag.getFileFlag('w'), mode, Cred.Root);
|
|
193
|
-
}), copyItem = (p) => __awaiter(this, void 0, void 0, function* () {
|
|
194
|
-
const stats = yield this._async.stat(p, Cred.Root);
|
|
195
|
-
if (stats.isDirectory()) {
|
|
196
|
-
yield copyDirectory(p, stats.mode);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
yield copyFile(p, stats.mode);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
try {
|
|
203
|
-
yield copyDirectory('/', 0);
|
|
204
|
-
this._isInitialized = true;
|
|
173
|
+
async _initialize() {
|
|
174
|
+
if (!this._isInitialized) {
|
|
175
|
+
// First call triggers initialization, the rest wait.
|
|
176
|
+
const copyDirectory = async (p, mode) => {
|
|
177
|
+
if (p !== '/') {
|
|
178
|
+
const stats = await this._async.stat(p, Cred.Root);
|
|
179
|
+
this._sync.mkdirSync(p, mode, stats.getCred());
|
|
180
|
+
}
|
|
181
|
+
const files = await this._async.readdir(p, Cred.Root);
|
|
182
|
+
for (const file of files) {
|
|
183
|
+
await copyItem(join(p, file));
|
|
205
184
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
185
|
+
}, copyFile = async (p, mode) => {
|
|
186
|
+
const data = await this._async.readFile(p, FileFlag.getFileFlag('r'), Cred.Root);
|
|
187
|
+
this._sync.writeFileSync(p, data, FileFlag.getFileFlag('w'), mode, Cred.Root);
|
|
188
|
+
}, copyItem = async (p) => {
|
|
189
|
+
const stats = await this._async.stat(p, Cred.Root);
|
|
190
|
+
if (stats.isDirectory()) {
|
|
191
|
+
await copyDirectory(p, stats.mode);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
await copyFile(p, stats.mode);
|
|
209
195
|
}
|
|
196
|
+
};
|
|
197
|
+
try {
|
|
198
|
+
await copyDirectory('/', 0);
|
|
199
|
+
this._isInitialized = true;
|
|
210
200
|
}
|
|
211
|
-
|
|
212
|
-
|
|
201
|
+
catch (e) {
|
|
202
|
+
this._isInitialized = false;
|
|
203
|
+
throw e;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return this;
|
|
213
207
|
}
|
|
214
208
|
enqueueOp(op) {
|
|
215
209
|
this._queue.push(op);
|
|
@@ -239,11 +233,11 @@ AsyncMirror.Options = {
|
|
|
239
233
|
sync: {
|
|
240
234
|
type: 'object',
|
|
241
235
|
description: 'The synchronous file system to mirror the asynchronous file system to.',
|
|
242
|
-
validator: (v) =>
|
|
243
|
-
if (!
|
|
236
|
+
validator: async (v) => {
|
|
237
|
+
if (!v?.metadata.synchronous) {
|
|
244
238
|
throw new ApiError(ErrorCode.EINVAL, `'sync' option must be a file system that supports synchronous operations`);
|
|
245
239
|
}
|
|
246
|
-
}
|
|
240
|
+
},
|
|
247
241
|
},
|
|
248
242
|
async: {
|
|
249
243
|
type: 'object',
|