@zenfs/core 0.0.1
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/README.md +293 -0
- package/dist/ApiError.d.ts +86 -0
- package/dist/ApiError.js +135 -0
- package/dist/backends/AsyncMirror.d.ts +102 -0
- package/dist/backends/AsyncMirror.js +252 -0
- package/dist/backends/AsyncStore.d.ts +166 -0
- package/dist/backends/AsyncStore.js +620 -0
- package/dist/backends/FolderAdapter.d.ts +52 -0
- package/dist/backends/FolderAdapter.js +184 -0
- package/dist/backends/InMemory.d.ts +25 -0
- package/dist/backends/InMemory.js +46 -0
- package/dist/backends/Locked.d.ts +64 -0
- package/dist/backends/Locked.js +302 -0
- package/dist/backends/OverlayFS.d.ts +120 -0
- package/dist/backends/OverlayFS.js +749 -0
- package/dist/backends/SyncStore.d.ts +223 -0
- package/dist/backends/SyncStore.js +479 -0
- package/dist/backends/backend.d.ts +73 -0
- package/dist/backends/backend.js +14 -0
- package/dist/backends/index.d.ts +11 -0
- package/dist/backends/index.js +15 -0
- package/dist/browser.min.js +12 -0
- package/dist/browser.min.js.map +7 -0
- package/dist/cred.d.ts +14 -0
- package/dist/cred.js +15 -0
- package/dist/emulation/callbacks.d.ts +382 -0
- package/dist/emulation/callbacks.js +422 -0
- package/dist/emulation/constants.d.ts +101 -0
- package/dist/emulation/constants.js +110 -0
- package/dist/emulation/fs.d.ts +7 -0
- package/dist/emulation/fs.js +5 -0
- package/dist/emulation/index.d.ts +5 -0
- package/dist/emulation/index.js +7 -0
- package/dist/emulation/promises.d.ts +309 -0
- package/dist/emulation/promises.js +521 -0
- package/dist/emulation/shared.d.ts +62 -0
- package/dist/emulation/shared.js +192 -0
- package/dist/emulation/sync.d.ts +278 -0
- package/dist/emulation/sync.js +392 -0
- package/dist/file.d.ts +449 -0
- package/dist/file.js +576 -0
- package/dist/filesystem.d.ts +367 -0
- package/dist/filesystem.js +542 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +113 -0
- package/dist/inode.d.ts +51 -0
- package/dist/inode.js +112 -0
- package/dist/mutex.d.ts +12 -0
- package/dist/mutex.js +48 -0
- package/dist/stats.d.ts +98 -0
- package/dist/stats.js +226 -0
- package/dist/utils.d.ts +52 -0
- package/dist/utils.js +261 -0
- package/license.md +122 -0
- package/package.json +61 -0
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
// disable no-unused-vars since BaseFileSystem uses them a lot
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var _a;
|
|
13
|
+
import { ApiError, ErrorCode } from './ApiError';
|
|
14
|
+
import { FileFlag, ActionType } from './file';
|
|
15
|
+
import * as path from 'path';
|
|
16
|
+
import { Buffer } from 'buffer';
|
|
17
|
+
/**
|
|
18
|
+
* Structure for a filesystem. **All** ZenFS FileSystems must implement
|
|
19
|
+
* this.
|
|
20
|
+
*
|
|
21
|
+
* ### Argument Assumptions
|
|
22
|
+
*
|
|
23
|
+
* You can assume the following about arguments passed to each API method:
|
|
24
|
+
*
|
|
25
|
+
* - Every path is an absolute path. `.`, `..`, and other items
|
|
26
|
+
* are resolved into an absolute form.
|
|
27
|
+
* - All arguments are present. Any optional arguments at the Node API level
|
|
28
|
+
* have been passed in with their default values.
|
|
29
|
+
*/
|
|
30
|
+
export class FileSystem {
|
|
31
|
+
constructor(options) {
|
|
32
|
+
// unused
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Basic filesystem class. Most filesystems should extend this class, as it
|
|
37
|
+
* provides default implementations for a handful of methods.
|
|
38
|
+
*/
|
|
39
|
+
export class BaseFileSystem extends FileSystem {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
super();
|
|
42
|
+
this._ready = Promise.resolve(this);
|
|
43
|
+
}
|
|
44
|
+
get metadata() {
|
|
45
|
+
return {
|
|
46
|
+
name: this.constructor.name,
|
|
47
|
+
readonly: false,
|
|
48
|
+
synchronous: false,
|
|
49
|
+
supportsProperties: false,
|
|
50
|
+
supportsLinks: false,
|
|
51
|
+
totalSpace: 0,
|
|
52
|
+
freeSpace: 0,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
whenReady() {
|
|
56
|
+
return this._ready;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Opens the file at path p with the given flag. The file must exist.
|
|
60
|
+
* @param p The path to open.
|
|
61
|
+
* @param flag The flag to use when opening the file.
|
|
62
|
+
*/
|
|
63
|
+
openFile(p, flag, cred) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create the file at path p with the given mode. Then, open it with the given
|
|
70
|
+
* flag.
|
|
71
|
+
*/
|
|
72
|
+
createFile(p, flag, mode, cred) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
open(p, flag, mode, cred) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
try {
|
|
80
|
+
const stats = yield this.stat(p, cred);
|
|
81
|
+
switch (flag.pathExistsAction()) {
|
|
82
|
+
case ActionType.THROW_EXCEPTION:
|
|
83
|
+
throw ApiError.EEXIST(p);
|
|
84
|
+
case ActionType.TRUNCATE_FILE:
|
|
85
|
+
// NOTE: In a previous implementation, we deleted the file and
|
|
86
|
+
// re-created it. However, this created a race condition if another
|
|
87
|
+
// asynchronous request was trying to read the file, as the file
|
|
88
|
+
// would not exist for a small period of time.
|
|
89
|
+
const fd = yield this.openFile(p, flag, cred);
|
|
90
|
+
if (!fd)
|
|
91
|
+
throw new Error('BFS has reached an impossible code path; please file a bug.');
|
|
92
|
+
yield fd.truncate(0);
|
|
93
|
+
yield fd.sync();
|
|
94
|
+
return fd;
|
|
95
|
+
case ActionType.NOP:
|
|
96
|
+
return this.openFile(p, flag, cred);
|
|
97
|
+
default:
|
|
98
|
+
throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
|
|
99
|
+
}
|
|
100
|
+
// File exists.
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
// File does not exist.
|
|
104
|
+
switch (flag.pathNotExistsAction()) {
|
|
105
|
+
case ActionType.CREATE_FILE:
|
|
106
|
+
// Ensure parent exists.
|
|
107
|
+
const parentStats = yield this.stat(path.dirname(p), cred);
|
|
108
|
+
if (parentStats && !parentStats.isDirectory()) {
|
|
109
|
+
throw ApiError.ENOTDIR(path.dirname(p));
|
|
110
|
+
}
|
|
111
|
+
return this.createFile(p, flag, mode, cred);
|
|
112
|
+
case ActionType.THROW_EXCEPTION:
|
|
113
|
+
throw ApiError.ENOENT(p);
|
|
114
|
+
default:
|
|
115
|
+
throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
access(p, mode, cred) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
accessSync(p, mode, cred) {
|
|
126
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
127
|
+
}
|
|
128
|
+
rename(oldPath, newPath, cred) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
renameSync(oldPath, newPath, cred) {
|
|
134
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
135
|
+
}
|
|
136
|
+
stat(p, cred) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
statSync(p, cred) {
|
|
142
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Opens the file at path p with the given flag. The file must exist.
|
|
146
|
+
* @param p The path to open.
|
|
147
|
+
* @param flag The flag to use when opening the file.
|
|
148
|
+
* @return A File object corresponding to the opened file.
|
|
149
|
+
*/
|
|
150
|
+
openFileSync(p, flag, cred) {
|
|
151
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create the file at path p with the given mode. Then, open it with the given
|
|
155
|
+
* flag.
|
|
156
|
+
*/
|
|
157
|
+
createFileSync(p, flag, mode, cred) {
|
|
158
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
159
|
+
}
|
|
160
|
+
openSync(p, flag, mode, cred) {
|
|
161
|
+
// Check if the path exists, and is a file.
|
|
162
|
+
let stats;
|
|
163
|
+
try {
|
|
164
|
+
stats = this.statSync(p, cred);
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
// File does not exist.
|
|
168
|
+
switch (flag.pathNotExistsAction()) {
|
|
169
|
+
case ActionType.CREATE_FILE:
|
|
170
|
+
// Ensure parent exists.
|
|
171
|
+
const parentStats = this.statSync(path.dirname(p), cred);
|
|
172
|
+
if (!parentStats.isDirectory()) {
|
|
173
|
+
throw ApiError.ENOTDIR(path.dirname(p));
|
|
174
|
+
}
|
|
175
|
+
return this.createFileSync(p, flag, mode, cred);
|
|
176
|
+
case ActionType.THROW_EXCEPTION:
|
|
177
|
+
throw ApiError.ENOENT(p);
|
|
178
|
+
default:
|
|
179
|
+
throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!stats.hasAccess(mode, cred)) {
|
|
183
|
+
throw ApiError.EACCES(p);
|
|
184
|
+
}
|
|
185
|
+
// File exists.
|
|
186
|
+
switch (flag.pathExistsAction()) {
|
|
187
|
+
case ActionType.THROW_EXCEPTION:
|
|
188
|
+
throw ApiError.EEXIST(p);
|
|
189
|
+
case ActionType.TRUNCATE_FILE:
|
|
190
|
+
// Delete file.
|
|
191
|
+
this.unlinkSync(p, cred);
|
|
192
|
+
// Create file. Use the same mode as the old file.
|
|
193
|
+
// Node itself modifies the ctime when this occurs, so this action
|
|
194
|
+
// will preserve that behavior if the underlying file system
|
|
195
|
+
// supports those properties.
|
|
196
|
+
return this.createFileSync(p, flag, stats.mode, cred);
|
|
197
|
+
case ActionType.NOP:
|
|
198
|
+
return this.openFileSync(p, flag, cred);
|
|
199
|
+
default:
|
|
200
|
+
throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
unlink(p, cred) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
unlinkSync(p, cred) {
|
|
209
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
210
|
+
}
|
|
211
|
+
rmdir(p, cred) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
rmdirSync(p, cred) {
|
|
217
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
218
|
+
}
|
|
219
|
+
mkdir(p, mode, cred) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
mkdirSync(p, mode, cred) {
|
|
225
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
226
|
+
}
|
|
227
|
+
readdir(p, cred) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
readdirSync(p, cred) {
|
|
233
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
234
|
+
}
|
|
235
|
+
exists(p, cred) {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
try {
|
|
238
|
+
yield this.stat(p, cred);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
existsSync(p, cred) {
|
|
247
|
+
try {
|
|
248
|
+
this.statSync(p, cred);
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
catch (e) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
realpath(p, cred) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
if (this.metadata.supportsLinks) {
|
|
258
|
+
// The path could contain symlinks. Split up the path,
|
|
259
|
+
// resolve any symlinks, return the resolved string.
|
|
260
|
+
const splitPath = p.split(path.sep);
|
|
261
|
+
// TODO: Simpler to just pass through file, find sep and such.
|
|
262
|
+
for (let i = 0; i < splitPath.length; i++) {
|
|
263
|
+
const addPaths = splitPath.slice(0, i + 1);
|
|
264
|
+
splitPath[i] = path.join(...addPaths);
|
|
265
|
+
}
|
|
266
|
+
return splitPath.join(path.sep);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// No symlinks. We just need to verify that it exists.
|
|
270
|
+
if (!(yield this.exists(p, cred))) {
|
|
271
|
+
throw ApiError.ENOENT(p);
|
|
272
|
+
}
|
|
273
|
+
return p;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
realpathSync(p, cred) {
|
|
278
|
+
if (this.metadata.supportsLinks) {
|
|
279
|
+
// The path could contain symlinks. Split up the path,
|
|
280
|
+
// resolve any symlinks, return the resolved string.
|
|
281
|
+
const splitPath = p.split(path.sep);
|
|
282
|
+
// TODO: Simpler to just pass through file, find sep and such.
|
|
283
|
+
for (let i = 0; i < splitPath.length; i++) {
|
|
284
|
+
const addPaths = splitPath.slice(0, i + 1);
|
|
285
|
+
splitPath[i] = path.join(...addPaths);
|
|
286
|
+
}
|
|
287
|
+
return splitPath.join(path.sep);
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
// No symlinks. We just need to verify that it exists.
|
|
291
|
+
if (this.existsSync(p, cred)) {
|
|
292
|
+
return p;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
throw ApiError.ENOENT(p);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
truncate(p, len, cred) {
|
|
300
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
301
|
+
const fd = yield this.open(p, FileFlag.getFileFlag('r+'), 0o644, cred);
|
|
302
|
+
try {
|
|
303
|
+
yield fd.truncate(len);
|
|
304
|
+
}
|
|
305
|
+
finally {
|
|
306
|
+
yield fd.close();
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
truncateSync(p, len, cred) {
|
|
311
|
+
const fd = this.openSync(p, FileFlag.getFileFlag('r+'), 0o644, cred);
|
|
312
|
+
// Need to safely close FD, regardless of whether or not truncate succeeds.
|
|
313
|
+
try {
|
|
314
|
+
fd.truncateSync(len);
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
fd.closeSync();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
readFile(fname, encoding, flag, cred) {
|
|
321
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
+
// Get file.
|
|
323
|
+
const fd = yield this.open(fname, flag, 0o644, cred);
|
|
324
|
+
try {
|
|
325
|
+
const stat = yield fd.stat();
|
|
326
|
+
// Allocate buffer.
|
|
327
|
+
const buf = Buffer.alloc(stat.size);
|
|
328
|
+
yield fd.read(buf, 0, stat.size, 0);
|
|
329
|
+
yield fd.close();
|
|
330
|
+
if (encoding === null) {
|
|
331
|
+
return buf;
|
|
332
|
+
}
|
|
333
|
+
return buf.toString(encoding);
|
|
334
|
+
}
|
|
335
|
+
finally {
|
|
336
|
+
yield fd.close();
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
readFileSync(fname, encoding, flag, cred) {
|
|
341
|
+
// Get file.
|
|
342
|
+
const fd = this.openSync(fname, flag, 0o644, cred);
|
|
343
|
+
try {
|
|
344
|
+
const stat = fd.statSync();
|
|
345
|
+
// Allocate buffer.
|
|
346
|
+
const buf = Buffer.alloc(stat.size);
|
|
347
|
+
fd.readSync(buf, 0, stat.size, 0);
|
|
348
|
+
fd.closeSync();
|
|
349
|
+
if (encoding === null) {
|
|
350
|
+
return buf;
|
|
351
|
+
}
|
|
352
|
+
return buf.toString(encoding);
|
|
353
|
+
}
|
|
354
|
+
finally {
|
|
355
|
+
fd.closeSync();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
writeFile(fname, data, encoding, flag, mode, cred) {
|
|
359
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
// Get file.
|
|
361
|
+
const fd = yield this.open(fname, flag, mode, cred);
|
|
362
|
+
try {
|
|
363
|
+
if (typeof data === 'string') {
|
|
364
|
+
data = Buffer.from(data, encoding);
|
|
365
|
+
}
|
|
366
|
+
// Write into file.
|
|
367
|
+
yield fd.write(data, 0, data.length, 0);
|
|
368
|
+
}
|
|
369
|
+
finally {
|
|
370
|
+
yield fd.close();
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
writeFileSync(fname, data, encoding, flag, mode, cred) {
|
|
375
|
+
// Get file.
|
|
376
|
+
const fd = this.openSync(fname, flag, mode, cred);
|
|
377
|
+
try {
|
|
378
|
+
if (typeof data === 'string') {
|
|
379
|
+
data = Buffer.from(data, encoding);
|
|
380
|
+
}
|
|
381
|
+
// Write into file.
|
|
382
|
+
fd.writeSync(data, 0, data.length, 0);
|
|
383
|
+
}
|
|
384
|
+
finally {
|
|
385
|
+
fd.closeSync();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
appendFile(fname, data, encoding, flag, mode, cred) {
|
|
389
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
390
|
+
const fd = yield this.open(fname, flag, mode, cred);
|
|
391
|
+
try {
|
|
392
|
+
if (typeof data === 'string') {
|
|
393
|
+
data = Buffer.from(data, encoding);
|
|
394
|
+
}
|
|
395
|
+
yield fd.write(data, 0, data.length, null);
|
|
396
|
+
}
|
|
397
|
+
finally {
|
|
398
|
+
yield fd.close();
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
appendFileSync(fname, data, encoding, flag, mode, cred) {
|
|
403
|
+
const fd = this.openSync(fname, flag, mode, cred);
|
|
404
|
+
try {
|
|
405
|
+
if (typeof data === 'string') {
|
|
406
|
+
data = Buffer.from(data, encoding);
|
|
407
|
+
}
|
|
408
|
+
fd.writeSync(data, 0, data.length, null);
|
|
409
|
+
}
|
|
410
|
+
finally {
|
|
411
|
+
fd.closeSync();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
chmod(p, mode, cred) {
|
|
415
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
416
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
chmodSync(p, mode, cred) {
|
|
420
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
421
|
+
}
|
|
422
|
+
chown(p, new_uid, new_gid, cred) {
|
|
423
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
chownSync(p, new_uid, new_gid, cred) {
|
|
428
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
429
|
+
}
|
|
430
|
+
utimes(p, atime, mtime, cred) {
|
|
431
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
432
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
utimesSync(p, atime, mtime, cred) {
|
|
436
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
437
|
+
}
|
|
438
|
+
link(srcpath, dstpath, cred) {
|
|
439
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
440
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
linkSync(srcpath, dstpath, cred) {
|
|
444
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
445
|
+
}
|
|
446
|
+
symlink(srcpath, dstpath, type, cred) {
|
|
447
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
448
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
symlinkSync(srcpath, dstpath, type, cred) {
|
|
452
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
453
|
+
}
|
|
454
|
+
readlink(p, cred) {
|
|
455
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
456
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
readlinkSync(p, cred) {
|
|
460
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
_a = BaseFileSystem;
|
|
464
|
+
BaseFileSystem.Name = _a.name;
|
|
465
|
+
/**
|
|
466
|
+
* Implements the asynchronous API in terms of the synchronous API.
|
|
467
|
+
*/
|
|
468
|
+
export class SynchronousFileSystem extends BaseFileSystem {
|
|
469
|
+
get metadata() {
|
|
470
|
+
return Object.assign(Object.assign({}, super.metadata), { synchronous: true });
|
|
471
|
+
}
|
|
472
|
+
access(p, mode, cred) {
|
|
473
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
474
|
+
return this.accessSync(p, mode, cred);
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
rename(oldPath, newPath, cred) {
|
|
478
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
479
|
+
return this.renameSync(oldPath, newPath, cred);
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
stat(p, cred) {
|
|
483
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
return this.statSync(p, cred);
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
open(p, flags, mode, cred) {
|
|
488
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
489
|
+
return this.openSync(p, flags, mode, cred);
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
unlink(p, cred) {
|
|
493
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
494
|
+
return this.unlinkSync(p, cred);
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
rmdir(p, cred) {
|
|
498
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
499
|
+
return this.rmdirSync(p, cred);
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
mkdir(p, mode, cred) {
|
|
503
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
504
|
+
return this.mkdirSync(p, mode, cred);
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
readdir(p, cred) {
|
|
508
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
509
|
+
return this.readdirSync(p, cred);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
chmod(p, mode, cred) {
|
|
513
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
514
|
+
return this.chmodSync(p, mode, cred);
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
chown(p, new_uid, new_gid, cred) {
|
|
518
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
519
|
+
return this.chownSync(p, new_uid, new_gid, cred);
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
utimes(p, atime, mtime, cred) {
|
|
523
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
524
|
+
return this.utimesSync(p, atime, mtime, cred);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
link(srcpath, dstpath, cred) {
|
|
528
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
529
|
+
return this.linkSync(srcpath, dstpath, cred);
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
symlink(srcpath, dstpath, type, cred) {
|
|
533
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
534
|
+
return this.symlinkSync(srcpath, dstpath, type, cred);
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
readlink(p, cred) {
|
|
538
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
539
|
+
return this.readlinkSync(p, cred);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZenFS's main module. This is exposed in the browser via the ZenFS global.
|
|
3
|
+
*/
|
|
4
|
+
import fs from './emulation/fs';
|
|
5
|
+
import { FileSystem, type BFSOneArgCallback, type BFSCallback } from './filesystem';
|
|
6
|
+
import { backends } from './backends';
|
|
7
|
+
/**
|
|
8
|
+
* Initializes ZenFS with the given file systems.
|
|
9
|
+
*/
|
|
10
|
+
export declare function initialize(mounts: {
|
|
11
|
+
[point: string]: FileSystem;
|
|
12
|
+
}, uid?: number, gid?: number): void;
|
|
13
|
+
/**
|
|
14
|
+
* Defines a mapping of mount points to their configurations
|
|
15
|
+
*/
|
|
16
|
+
export interface ConfigMapping {
|
|
17
|
+
[mountPoint: string]: FileSystem | FileSystemConfiguration | keyof typeof backends;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A configuration for ZenFS
|
|
21
|
+
*/
|
|
22
|
+
export type Configuration = FileSystem | FileSystemConfiguration | ConfigMapping;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a file system with the given configuration, and initializes ZenFS with it.
|
|
25
|
+
* See the FileSystemConfiguration type for more info on the configuration object.
|
|
26
|
+
*/
|
|
27
|
+
export declare function configure(config: Configuration): Promise<void>;
|
|
28
|
+
export declare function configure(config: Configuration, cb: BFSOneArgCallback): void;
|
|
29
|
+
/**
|
|
30
|
+
* Asynchronously creates a file system with the given configuration, and initializes ZenFS with it.
|
|
31
|
+
* See the FileSystemConfiguration type for more info on the configuration object.
|
|
32
|
+
* Note: unlike configure, the .then is provided with the file system
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Specifies a file system backend type and its options.
|
|
36
|
+
*
|
|
37
|
+
* Individual options can recursively contain FileSystemConfiguration objects for
|
|
38
|
+
* option values that require file systems.
|
|
39
|
+
*
|
|
40
|
+
* For example, to mirror Dropbox to Storage with AsyncMirror, use the following
|
|
41
|
+
* object:
|
|
42
|
+
*
|
|
43
|
+
* ```javascript
|
|
44
|
+
* var config = {
|
|
45
|
+
* fs: "AsyncMirror",
|
|
46
|
+
* options: {
|
|
47
|
+
* sync: {fs: "Storage"},
|
|
48
|
+
* async: {fs: "Dropbox", options: {client: anAuthenticatedDropboxSDKClient }}
|
|
49
|
+
* }
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* The option object for each file system corresponds to that file system's option object passed to its `Create()` method.
|
|
54
|
+
*/
|
|
55
|
+
export interface FileSystemConfiguration {
|
|
56
|
+
fs: string;
|
|
57
|
+
options?: object;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Retrieve a file system with the given configuration. Will return a promise if invoked without a callback
|
|
61
|
+
* @param config A FileSystemConfiguration object. See FileSystemConfiguration for details.
|
|
62
|
+
* @param cb Called when the file system is constructed, or when an error occurs.
|
|
63
|
+
*/
|
|
64
|
+
export declare function getFileSystem(config: FileSystemConfiguration): Promise<FileSystem>;
|
|
65
|
+
export declare function getFileSystem(config: FileSystemConfiguration, cb: BFSCallback<FileSystem>): void;
|
|
66
|
+
export * from './backends';
|
|
67
|
+
export * from './backends/AsyncStore';
|
|
68
|
+
export * from './backends/SyncStore';
|
|
69
|
+
export * from './ApiError';
|
|
70
|
+
export * from './cred';
|
|
71
|
+
export * from './file';
|
|
72
|
+
export * from './filesystem';
|
|
73
|
+
export * from './inode';
|
|
74
|
+
export * from './mutex';
|
|
75
|
+
export * from './stats';
|
|
76
|
+
export * from './utils';
|
|
77
|
+
export { fs };
|
|
78
|
+
export default fs;
|