@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
package/dist/emulation/sync.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
2
2
|
import { FileFlag } from '../file.js';
|
|
3
|
-
import {
|
|
3
|
+
import { BigIntStats } from '../stats.js';
|
|
4
|
+
import { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts, } from './shared.js';
|
|
4
5
|
import { decode, encode } from '../utils.js';
|
|
6
|
+
import { Dirent } from './dir.js';
|
|
7
|
+
import { join } from './path.js';
|
|
5
8
|
function doOp(...[name, resolveSymlinks, path, ...args]) {
|
|
6
9
|
path = normalizePath(path);
|
|
7
10
|
const { fs, path: resolvedPath } = resolveFS(resolveSymlinks && existsSync(path) ? realpathSync(path) : path);
|
|
@@ -36,6 +39,7 @@ export function renameSync(oldPath, newPath) {
|
|
|
36
39
|
throw fixError(e, paths);
|
|
37
40
|
}
|
|
38
41
|
}
|
|
42
|
+
renameSync;
|
|
39
43
|
/**
|
|
40
44
|
* Test whether or not the given path exists by checking with the file system.
|
|
41
45
|
* @param path
|
|
@@ -53,24 +57,17 @@ export function existsSync(path) {
|
|
|
53
57
|
throw e;
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
export function statSync(path) {
|
|
62
|
-
return doOp('statSync', true, path, cred);
|
|
60
|
+
existsSync;
|
|
61
|
+
export function statSync(path, options) {
|
|
62
|
+
const stats = doOp('statSync', true, path, cred);
|
|
63
|
+
return options?.bigint ? BigIntStats.clone(stats) : stats;
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* @param path
|
|
69
|
-
* @return [ZenFS.node.fs.Stats]
|
|
70
|
-
*/
|
|
71
|
-
export function lstatSync(path) {
|
|
72
|
-
return doOp('statSync', false, path, cred);
|
|
65
|
+
statSync;
|
|
66
|
+
export function lstatSync(path, options) {
|
|
67
|
+
const stats = doOp('statSync', false, path, cred);
|
|
68
|
+
return options?.bigint ? BigIntStats.clone(stats) : stats;
|
|
73
69
|
}
|
|
70
|
+
lstatSync;
|
|
74
71
|
/**
|
|
75
72
|
* Synchronous `truncate`.
|
|
76
73
|
* @param path
|
|
@@ -82,6 +79,7 @@ export function truncateSync(path, len = 0) {
|
|
|
82
79
|
}
|
|
83
80
|
return doOp('truncateSync', true, path, len, cred);
|
|
84
81
|
}
|
|
82
|
+
truncateSync;
|
|
85
83
|
/**
|
|
86
84
|
* Synchronous `unlink`.
|
|
87
85
|
* @param path
|
|
@@ -89,18 +87,20 @@ export function truncateSync(path, len = 0) {
|
|
|
89
87
|
export function unlinkSync(path) {
|
|
90
88
|
return doOp('unlinkSync', false, path, cred);
|
|
91
89
|
}
|
|
90
|
+
unlinkSync;
|
|
92
91
|
/**
|
|
93
92
|
* Synchronous file open.
|
|
94
93
|
* @see http://www.manpagez.com/man/2/open/
|
|
95
94
|
* @param path
|
|
96
95
|
* @param flags
|
|
97
96
|
* @param mode defaults to `0644`
|
|
98
|
-
* @
|
|
97
|
+
* @returns file descriptor
|
|
99
98
|
*/
|
|
100
99
|
export function openSync(path, flag, mode = 0o644) {
|
|
101
100
|
const file = doOp('openSync', true, path, FileFlag.getFileFlag(flag), normalizeMode(mode, 0o644), cred);
|
|
102
101
|
return getFdForFile(file);
|
|
103
102
|
}
|
|
103
|
+
openSync;
|
|
104
104
|
export function readFileSync(filename, arg2 = {}) {
|
|
105
105
|
const options = normalizeOptions(arg2, null, 'r', null);
|
|
106
106
|
const flag = FileFlag.getFileFlag(options.flag);
|
|
@@ -116,6 +116,7 @@ export function readFileSync(filename, arg2 = {}) {
|
|
|
116
116
|
return data;
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
+
readFileSync;
|
|
119
120
|
export function writeFileSync(filename, data, arg3) {
|
|
120
121
|
const options = normalizeOptions(arg3, 'utf8', 'w', 0o644);
|
|
121
122
|
const flag = FileFlag.getFileFlag(options.flag);
|
|
@@ -128,6 +129,7 @@ export function writeFileSync(filename, data, arg3) {
|
|
|
128
129
|
const encodedData = typeof data == 'string' ? encode(data) : data;
|
|
129
130
|
return doOp('writeFileSync', true, filename, encodedData, flag, options.mode, cred);
|
|
130
131
|
}
|
|
132
|
+
writeFileSync;
|
|
131
133
|
export function appendFileSync(filename, data, arg3) {
|
|
132
134
|
const options = normalizeOptions(arg3, 'utf8', 'a', 0o644);
|
|
133
135
|
const flag = FileFlag.getFileFlag(options.flag);
|
|
@@ -140,16 +142,12 @@ export function appendFileSync(filename, data, arg3) {
|
|
|
140
142
|
const encodedData = typeof data == 'string' ? encode(data) : data;
|
|
141
143
|
return doOp('appendFileSync', true, filename, encodedData, flag, options.mode, cred);
|
|
142
144
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
* @param fd
|
|
148
|
-
* @return [ZenFS.node.fs.Stats]
|
|
149
|
-
*/
|
|
150
|
-
export function fstatSync(fd) {
|
|
151
|
-
return fd2file(fd).statSync();
|
|
145
|
+
appendFileSync;
|
|
146
|
+
export function fstatSync(fd, options) {
|
|
147
|
+
const stats = fd2file(fd).statSync();
|
|
148
|
+
return options?.bigint ? BigIntStats.clone(stats) : stats;
|
|
152
149
|
}
|
|
150
|
+
fstatSync;
|
|
153
151
|
/**
|
|
154
152
|
* Synchronous close.
|
|
155
153
|
* @param fd
|
|
@@ -158,6 +156,7 @@ export function closeSync(fd) {
|
|
|
158
156
|
fd2file(fd).closeSync();
|
|
159
157
|
fdMap.delete(fd);
|
|
160
158
|
}
|
|
159
|
+
closeSync;
|
|
161
160
|
/**
|
|
162
161
|
* Synchronous ftruncate.
|
|
163
162
|
* @param fd
|
|
@@ -170,6 +169,7 @@ export function ftruncateSync(fd, len = 0) {
|
|
|
170
169
|
}
|
|
171
170
|
file.truncateSync(len);
|
|
172
171
|
}
|
|
172
|
+
ftruncateSync;
|
|
173
173
|
/**
|
|
174
174
|
* Synchronous fsync.
|
|
175
175
|
* @param fd
|
|
@@ -177,6 +177,7 @@ export function ftruncateSync(fd, len = 0) {
|
|
|
177
177
|
export function fsyncSync(fd) {
|
|
178
178
|
fd2file(fd).syncSync();
|
|
179
179
|
}
|
|
180
|
+
fsyncSync;
|
|
180
181
|
/**
|
|
181
182
|
* Synchronous fdatasync.
|
|
182
183
|
* @param fd
|
|
@@ -184,6 +185,7 @@ export function fsyncSync(fd) {
|
|
|
184
185
|
export function fdatasyncSync(fd) {
|
|
185
186
|
fd2file(fd).datasyncSync();
|
|
186
187
|
}
|
|
188
|
+
fdatasyncSync;
|
|
187
189
|
export function writeSync(fd, arg2, arg3, arg4, arg5) {
|
|
188
190
|
let buffer, offset = 0, length, position;
|
|
189
191
|
if (typeof arg2 === 'string') {
|
|
@@ -207,6 +209,7 @@ export function writeSync(fd, arg2, arg3, arg4, arg5) {
|
|
|
207
209
|
}
|
|
208
210
|
return file.writeSync(buffer, offset, length, position);
|
|
209
211
|
}
|
|
212
|
+
writeSync;
|
|
210
213
|
export function readSync(fd, buffer, opts, length, position) {
|
|
211
214
|
const file = fd2file(fd);
|
|
212
215
|
let offset = opts;
|
|
@@ -218,6 +221,7 @@ export function readSync(fd, buffer, opts, length, position) {
|
|
|
218
221
|
}
|
|
219
222
|
return file.readSync(buffer, offset, length, position);
|
|
220
223
|
}
|
|
224
|
+
readSync;
|
|
221
225
|
/**
|
|
222
226
|
* Synchronous `fchown`.
|
|
223
227
|
* @param fd
|
|
@@ -227,6 +231,7 @@ export function readSync(fd, buffer, opts, length, position) {
|
|
|
227
231
|
export function fchownSync(fd, uid, gid) {
|
|
228
232
|
fd2file(fd).chownSync(uid, gid);
|
|
229
233
|
}
|
|
234
|
+
fchownSync;
|
|
230
235
|
/**
|
|
231
236
|
* Synchronous `fchmod`.
|
|
232
237
|
* @param fd
|
|
@@ -236,6 +241,7 @@ export function fchmodSync(fd, mode) {
|
|
|
236
241
|
const numMode = typeof mode === 'string' ? parseInt(mode, 8) : mode;
|
|
237
242
|
fd2file(fd).chmodSync(numMode);
|
|
238
243
|
}
|
|
244
|
+
fchmodSync;
|
|
239
245
|
/**
|
|
240
246
|
* Change the file timestamps of a file referenced by the supplied file
|
|
241
247
|
* descriptor.
|
|
@@ -246,6 +252,7 @@ export function fchmodSync(fd, mode) {
|
|
|
246
252
|
export function futimesSync(fd, atime, mtime) {
|
|
247
253
|
fd2file(fd).utimesSync(normalizeTime(atime), normalizeTime(mtime));
|
|
248
254
|
}
|
|
255
|
+
futimesSync;
|
|
249
256
|
// DIRECTORY-ONLY METHODS
|
|
250
257
|
/**
|
|
251
258
|
* Synchronous `rmdir`.
|
|
@@ -254,35 +261,38 @@ export function futimesSync(fd, atime, mtime) {
|
|
|
254
261
|
export function rmdirSync(path) {
|
|
255
262
|
return doOp('rmdirSync', true, path, cred);
|
|
256
263
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
*/
|
|
262
|
-
export function mkdirSync(path, mode) {
|
|
264
|
+
rmdirSync;
|
|
265
|
+
export function mkdirSync(path, options) {
|
|
266
|
+
const mode = typeof options == 'number' || typeof options == 'string' ? options : options?.mode;
|
|
267
|
+
const recursive = typeof options == 'object' && options?.recursive;
|
|
263
268
|
doOp('mkdirSync', true, path, normalizeMode(mode, 0o777), cred);
|
|
264
269
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
* @param path
|
|
268
|
-
* @return [String[]]
|
|
269
|
-
*/
|
|
270
|
-
export function readdirSync(path) {
|
|
270
|
+
mkdirSync;
|
|
271
|
+
export function readdirSync(path, options) {
|
|
271
272
|
path = normalizePath(path);
|
|
272
273
|
const entries = doOp('readdirSync', true, path, cred);
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const entry = point.slice(path.length);
|
|
277
|
-
if (entry.includes('/') || entry.length == 0) {
|
|
278
|
-
// ignore FSs mounted in subdirectories and any FS mounted to `path`.
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
entries.push(entry);
|
|
274
|
+
for (const mount of mounts.keys()) {
|
|
275
|
+
if (!mount.startsWith(path)) {
|
|
276
|
+
continue;
|
|
282
277
|
}
|
|
278
|
+
const entry = mount.slice(path.length);
|
|
279
|
+
if (entry.includes('/') || entry.length == 0) {
|
|
280
|
+
// ignore FSs mounted in subdirectories and any FS mounted to `path`.
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
entries.push(entry);
|
|
283
284
|
}
|
|
284
|
-
return entries
|
|
285
|
+
return entries.map((entry) => {
|
|
286
|
+
if (typeof options == 'object' && options?.withFileTypes) {
|
|
287
|
+
return new Dirent(entry, statSync(join(path, entry)));
|
|
288
|
+
}
|
|
289
|
+
if (options == 'buffer' || (typeof options == 'object' && options.encoding == 'buffer')) {
|
|
290
|
+
return encode(entry);
|
|
291
|
+
}
|
|
292
|
+
return entry;
|
|
293
|
+
});
|
|
285
294
|
}
|
|
295
|
+
readdirSync;
|
|
286
296
|
// SYMLINK METHODS
|
|
287
297
|
/**
|
|
288
298
|
* Synchronous `link`.
|
|
@@ -293,6 +303,7 @@ export function linkSync(srcpath, dstpath) {
|
|
|
293
303
|
dstpath = normalizePath(dstpath);
|
|
294
304
|
return doOp('linkSync', false, srcpath, dstpath, cred);
|
|
295
305
|
}
|
|
306
|
+
linkSync;
|
|
296
307
|
/**
|
|
297
308
|
* Synchronous `symlink`.
|
|
298
309
|
* @param srcpath
|
|
@@ -306,14 +317,12 @@ export function symlinkSync(srcpath, dstpath, type) {
|
|
|
306
317
|
dstpath = normalizePath(dstpath);
|
|
307
318
|
return doOp('symlinkSync', false, srcpath, dstpath, type, cred);
|
|
308
319
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
*/
|
|
314
|
-
export function readlinkSync(path) {
|
|
315
|
-
return doOp('readlinkSync', false, path, cred);
|
|
320
|
+
symlinkSync;
|
|
321
|
+
export function readlinkSync(path, options) {
|
|
322
|
+
const value = doOp('readlinkSync', false, path, cred);
|
|
323
|
+
return encode(value, typeof options == 'object' ? options.encoding : options);
|
|
316
324
|
}
|
|
325
|
+
readlinkSync;
|
|
317
326
|
// PROPERTY OPERATIONS
|
|
318
327
|
/**
|
|
319
328
|
* Synchronous `chown`.
|
|
@@ -324,6 +333,7 @@ export function readlinkSync(path) {
|
|
|
324
333
|
export function chownSync(path, uid, gid) {
|
|
325
334
|
doOp('chownSync', true, path, uid, gid, cred);
|
|
326
335
|
}
|
|
336
|
+
chownSync;
|
|
327
337
|
/**
|
|
328
338
|
* Synchronous `lchown`.
|
|
329
339
|
* @param path
|
|
@@ -333,6 +343,7 @@ export function chownSync(path, uid, gid) {
|
|
|
333
343
|
export function lchownSync(path, uid, gid) {
|
|
334
344
|
doOp('chownSync', false, path, uid, gid, cred);
|
|
335
345
|
}
|
|
346
|
+
lchownSync;
|
|
336
347
|
/**
|
|
337
348
|
* Synchronous `chmod`.
|
|
338
349
|
* @param path
|
|
@@ -345,6 +356,7 @@ export function chmodSync(path, mode) {
|
|
|
345
356
|
}
|
|
346
357
|
doOp('chmodSync', true, path, numMode, cred);
|
|
347
358
|
}
|
|
359
|
+
chmodSync;
|
|
348
360
|
/**
|
|
349
361
|
* Synchronous `lchmod`.
|
|
350
362
|
* @param path
|
|
@@ -357,6 +369,7 @@ export function lchmodSync(path, mode) {
|
|
|
357
369
|
}
|
|
358
370
|
doOp('chmodSync', false, path, numMode, cred);
|
|
359
371
|
}
|
|
372
|
+
lchmodSync;
|
|
360
373
|
/**
|
|
361
374
|
* Change file timestamps of the file referenced by the supplied path.
|
|
362
375
|
* @param path
|
|
@@ -366,6 +379,7 @@ export function lchmodSync(path, mode) {
|
|
|
366
379
|
export function utimesSync(path, atime, mtime) {
|
|
367
380
|
doOp('utimesSync', true, path, normalizeTime(atime), normalizeTime(mtime), cred);
|
|
368
381
|
}
|
|
382
|
+
utimesSync;
|
|
369
383
|
/**
|
|
370
384
|
* Change file timestamps of the file referenced by the supplied path.
|
|
371
385
|
* @param path
|
|
@@ -375,15 +389,8 @@ export function utimesSync(path, atime, mtime) {
|
|
|
375
389
|
export function lutimesSync(path, atime, mtime) {
|
|
376
390
|
doOp('utimesSync', false, path, normalizeTime(atime), normalizeTime(mtime), cred);
|
|
377
391
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
* @param path
|
|
381
|
-
* @param cache An object literal of mapped paths that can be used to
|
|
382
|
-
* force a specific path resolution or avoid additional `fs.stat` calls for
|
|
383
|
-
* known real paths.
|
|
384
|
-
* @return [String]
|
|
385
|
-
*/
|
|
386
|
-
export function realpathSync(path, cache = {}) {
|
|
392
|
+
lutimesSync;
|
|
393
|
+
export function realpathSync(path, options) {
|
|
387
394
|
path = normalizePath(path);
|
|
388
395
|
const { fs, path: resolvedPath, mountPoint } = resolveFS(path);
|
|
389
396
|
try {
|
|
@@ -398,6 +405,7 @@ export function realpathSync(path, cache = {}) {
|
|
|
398
405
|
throw fixError(e, { [resolvedPath]: path });
|
|
399
406
|
}
|
|
400
407
|
}
|
|
408
|
+
realpathSync;
|
|
401
409
|
/**
|
|
402
410
|
* Synchronous `access`.
|
|
403
411
|
* @param path
|
|
@@ -406,3 +414,28 @@ export function realpathSync(path, cache = {}) {
|
|
|
406
414
|
export function accessSync(path, mode = 0o600) {
|
|
407
415
|
return doOp('accessSync', true, path, mode, cred);
|
|
408
416
|
}
|
|
417
|
+
accessSync;
|
|
418
|
+
export function rmSync(path) {
|
|
419
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
420
|
+
}
|
|
421
|
+
rmSync;
|
|
422
|
+
export function mkdtempSync(prefix, options) {
|
|
423
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
424
|
+
}
|
|
425
|
+
mkdtempSync;
|
|
426
|
+
export function copyFileSync(src, dest, flags) {
|
|
427
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
428
|
+
}
|
|
429
|
+
copyFileSync;
|
|
430
|
+
export function readvSync(fd, buffers, position) {
|
|
431
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
432
|
+
}
|
|
433
|
+
readvSync;
|
|
434
|
+
export function writevSync(fd, buffers, position) {
|
|
435
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
436
|
+
}
|
|
437
|
+
writevSync;
|
|
438
|
+
export function opendirSync(path, options) {
|
|
439
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
440
|
+
}
|
|
441
|
+
opendirSync;
|
package/dist/file.d.ts
CHANGED
|
@@ -29,18 +29,24 @@ export declare class FileFlag {
|
|
|
29
29
|
private static validFlagStrs;
|
|
30
30
|
/**
|
|
31
31
|
* Get an object representing the given file flag.
|
|
32
|
-
* @param
|
|
32
|
+
* @param flag The string or number representing the flag
|
|
33
33
|
* @return The FileFlag object representing the flag
|
|
34
34
|
* @throw when the flag string is invalid
|
|
35
35
|
*/
|
|
36
|
-
static getFileFlag(
|
|
36
|
+
static getFileFlag(flag: string | number): FileFlag;
|
|
37
37
|
private flagStr;
|
|
38
38
|
/**
|
|
39
39
|
* This should never be called directly.
|
|
40
|
-
* @param
|
|
41
|
-
* @throw when the
|
|
40
|
+
* @param flag The string or number representing the flag
|
|
41
|
+
* @throw when the flag is invalid
|
|
42
42
|
*/
|
|
43
|
-
constructor(
|
|
43
|
+
constructor(flag: string | number);
|
|
44
|
+
/**
|
|
45
|
+
* @param flag The number representing the flag
|
|
46
|
+
* @return The string representing the flag
|
|
47
|
+
* @throw when the flag number is invalid
|
|
48
|
+
*/
|
|
49
|
+
static StringFromNumber(flag: number): string;
|
|
44
50
|
/**
|
|
45
51
|
* Get the underlying flag string for this flag.
|
|
46
52
|
*/
|
package/dist/file.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
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 { ApiError, ErrorCode } from './ApiError.js';
|
|
11
2
|
import { Stats } from './stats.js';
|
|
12
3
|
import { getMount } from './emulation/shared.js';
|
|
4
|
+
import { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_SYNC } from './emulation/constants.js';
|
|
13
5
|
export var ActionType;
|
|
14
6
|
(function (ActionType) {
|
|
15
7
|
// Indicates that the code should not do anything.
|
|
@@ -42,26 +34,65 @@ export var ActionType;
|
|
|
42
34
|
export class FileFlag {
|
|
43
35
|
/**
|
|
44
36
|
* Get an object representing the given file flag.
|
|
45
|
-
* @param
|
|
37
|
+
* @param flag The string or number representing the flag
|
|
46
38
|
* @return The FileFlag object representing the flag
|
|
47
39
|
* @throw when the flag string is invalid
|
|
48
40
|
*/
|
|
49
|
-
static getFileFlag(
|
|
41
|
+
static getFileFlag(flag) {
|
|
50
42
|
// Check cache first.
|
|
51
|
-
if (!FileFlag.flagCache.has(
|
|
52
|
-
FileFlag.flagCache.set(
|
|
43
|
+
if (!FileFlag.flagCache.has(flag)) {
|
|
44
|
+
FileFlag.flagCache.set(flag, new FileFlag(flag));
|
|
53
45
|
}
|
|
54
|
-
return FileFlag.flagCache.get(
|
|
46
|
+
return FileFlag.flagCache.get(flag);
|
|
55
47
|
}
|
|
56
48
|
/**
|
|
57
49
|
* This should never be called directly.
|
|
58
|
-
* @param
|
|
59
|
-
* @throw when the
|
|
50
|
+
* @param flag The string or number representing the flag
|
|
51
|
+
* @throw when the flag is invalid
|
|
60
52
|
*/
|
|
61
|
-
constructor(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
constructor(flag) {
|
|
54
|
+
if (typeof flag === 'number') {
|
|
55
|
+
flag = FileFlag.StringFromNumber(flag);
|
|
56
|
+
}
|
|
57
|
+
if (FileFlag.validFlagStrs.indexOf(flag) < 0) {
|
|
58
|
+
throw new ApiError(ErrorCode.EINVAL, 'Invalid flag string: ' + flag);
|
|
59
|
+
}
|
|
60
|
+
this.flagStr = flag;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @param flag The number representing the flag
|
|
64
|
+
* @return The string representing the flag
|
|
65
|
+
* @throw when the flag number is invalid
|
|
66
|
+
*/
|
|
67
|
+
static StringFromNumber(flag) {
|
|
68
|
+
// based on https://github.com/nodejs/node/blob/abbdc3efaa455e6c907ebef5409ac8b0f222f969/lib/internal/fs/utils.js#L619
|
|
69
|
+
switch (flag) {
|
|
70
|
+
case O_RDONLY:
|
|
71
|
+
return 'r';
|
|
72
|
+
case O_RDONLY | O_SYNC:
|
|
73
|
+
return 'rs';
|
|
74
|
+
case O_RDWR:
|
|
75
|
+
return 'r+';
|
|
76
|
+
case O_RDWR | O_SYNC:
|
|
77
|
+
return 'rs+';
|
|
78
|
+
case O_TRUNC | O_CREAT | O_WRONLY:
|
|
79
|
+
return 'w';
|
|
80
|
+
case O_TRUNC | O_CREAT | O_WRONLY | O_EXCL:
|
|
81
|
+
return 'wx';
|
|
82
|
+
case O_TRUNC | O_CREAT | O_RDWR:
|
|
83
|
+
return 'w+';
|
|
84
|
+
case O_TRUNC | O_CREAT | O_RDWR | O_EXCL:
|
|
85
|
+
return 'wx+';
|
|
86
|
+
case O_APPEND | O_CREAT | O_WRONLY:
|
|
87
|
+
return 'a';
|
|
88
|
+
case O_APPEND | O_CREAT | O_WRONLY | O_EXCL:
|
|
89
|
+
return 'ax';
|
|
90
|
+
case O_APPEND | O_CREAT | O_RDWR:
|
|
91
|
+
return 'a+';
|
|
92
|
+
case O_APPEND | O_CREAT | O_RDWR | O_EXCL:
|
|
93
|
+
return 'ax+';
|
|
94
|
+
default:
|
|
95
|
+
throw new ApiError(ErrorCode.EINVAL, 'Invalid flag number: ' + flag);
|
|
65
96
|
}
|
|
66
97
|
}
|
|
67
98
|
/**
|
|
@@ -156,42 +187,32 @@ FileFlag.validFlagStrs = ['r', 'r+', 'rs', 'rs+', 'w', 'wx', 'w+', 'wx+', 'a', '
|
|
|
156
187
|
* object.
|
|
157
188
|
*/
|
|
158
189
|
export class BaseFile {
|
|
159
|
-
sync() {
|
|
160
|
-
|
|
161
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
162
|
-
});
|
|
190
|
+
async sync() {
|
|
191
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
163
192
|
}
|
|
164
193
|
syncSync() {
|
|
165
194
|
throw new ApiError(ErrorCode.ENOTSUP);
|
|
166
195
|
}
|
|
167
|
-
datasync() {
|
|
168
|
-
return
|
|
169
|
-
return this.sync();
|
|
170
|
-
});
|
|
196
|
+
async datasync() {
|
|
197
|
+
return this.sync();
|
|
171
198
|
}
|
|
172
199
|
datasyncSync() {
|
|
173
200
|
return this.syncSync();
|
|
174
201
|
}
|
|
175
|
-
chown(uid, gid) {
|
|
176
|
-
|
|
177
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
178
|
-
});
|
|
202
|
+
async chown(uid, gid) {
|
|
203
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
179
204
|
}
|
|
180
205
|
chownSync(uid, gid) {
|
|
181
206
|
throw new ApiError(ErrorCode.ENOTSUP);
|
|
182
207
|
}
|
|
183
|
-
chmod(mode) {
|
|
184
|
-
|
|
185
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
186
|
-
});
|
|
208
|
+
async chmod(mode) {
|
|
209
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
187
210
|
}
|
|
188
211
|
chmodSync(mode) {
|
|
189
212
|
throw new ApiError(ErrorCode.ENOTSUP);
|
|
190
213
|
}
|
|
191
|
-
utimes(atime, mtime) {
|
|
192
|
-
|
|
193
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
194
|
-
});
|
|
214
|
+
async utimes(atime, mtime) {
|
|
215
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
195
216
|
}
|
|
196
217
|
utimesSync(atime, mtime) {
|
|
197
218
|
throw new ApiError(ErrorCode.ENOTSUP);
|
|
@@ -294,10 +315,8 @@ export class PreloadFile extends BaseFile {
|
|
|
294
315
|
* class.
|
|
295
316
|
* @param [Function(ZenFS.ApiError)] cb
|
|
296
317
|
*/
|
|
297
|
-
sync() {
|
|
298
|
-
|
|
299
|
-
this.syncSync();
|
|
300
|
-
});
|
|
318
|
+
async sync() {
|
|
319
|
+
this.syncSync();
|
|
301
320
|
}
|
|
302
321
|
/**
|
|
303
322
|
* **Core**: Synchronous sync.
|
|
@@ -310,10 +329,8 @@ export class PreloadFile extends BaseFile {
|
|
|
310
329
|
* class.
|
|
311
330
|
* @param [Function(ZenFS.ApiError)] cb
|
|
312
331
|
*/
|
|
313
|
-
close() {
|
|
314
|
-
|
|
315
|
-
this.closeSync();
|
|
316
|
-
});
|
|
332
|
+
async close() {
|
|
333
|
+
this.closeSync();
|
|
317
334
|
}
|
|
318
335
|
/**
|
|
319
336
|
* **Core**: Synchronous close.
|
|
@@ -325,10 +342,8 @@ export class PreloadFile extends BaseFile {
|
|
|
325
342
|
* Asynchronous `stat`.
|
|
326
343
|
* @param [Function(ZenFS.ApiError, ZenFS.node.fs.Stats)] cb
|
|
327
344
|
*/
|
|
328
|
-
stat() {
|
|
329
|
-
return
|
|
330
|
-
return Stats.clone(this._stat);
|
|
331
|
-
});
|
|
345
|
+
async stat() {
|
|
346
|
+
return Stats.clone(this._stat);
|
|
332
347
|
}
|
|
333
348
|
/**
|
|
334
349
|
* Synchronous `stat`.
|
|
@@ -387,10 +402,8 @@ export class PreloadFile extends BaseFile {
|
|
|
387
402
|
* @param [Function(ZenFS.ApiError, Number, ZenFS.node.Uint8Array)]
|
|
388
403
|
* cb The number specifies the number of bytes written into the file.
|
|
389
404
|
*/
|
|
390
|
-
write(buffer, offset, length, position) {
|
|
391
|
-
return
|
|
392
|
-
return this.writeSync(buffer, offset, length, position);
|
|
393
|
-
});
|
|
405
|
+
async write(buffer, offset, length, position) {
|
|
406
|
+
return this.writeSync(buffer, offset, length, position);
|
|
394
407
|
}
|
|
395
408
|
/**
|
|
396
409
|
* Write buffer to the file.
|
|
@@ -446,10 +459,8 @@ export class PreloadFile extends BaseFile {
|
|
|
446
459
|
* @param [Function(ZenFS.ApiError, Number, ZenFS.node.Uint8Array)] cb The
|
|
447
460
|
* number is the number of bytes read
|
|
448
461
|
*/
|
|
449
|
-
read(buffer, offset, length, position) {
|
|
450
|
-
return
|
|
451
|
-
return { bytesRead: this.readSync(buffer, offset, length, position), buffer };
|
|
452
|
-
});
|
|
462
|
+
async read(buffer, offset, length, position) {
|
|
463
|
+
return { bytesRead: this.readSync(buffer, offset, length, position), buffer };
|
|
453
464
|
}
|
|
454
465
|
/**
|
|
455
466
|
* Read data from the file.
|
|
@@ -483,10 +494,8 @@ export class PreloadFile extends BaseFile {
|
|
|
483
494
|
* Asynchronous `fchmod`.
|
|
484
495
|
* @param [Number|String] mode
|
|
485
496
|
*/
|
|
486
|
-
chmod(mode) {
|
|
487
|
-
|
|
488
|
-
this.chmodSync(mode);
|
|
489
|
-
});
|
|
497
|
+
async chmod(mode) {
|
|
498
|
+
this.chmodSync(mode);
|
|
490
499
|
}
|
|
491
500
|
/**
|
|
492
501
|
* Synchronous `fchmod`.
|
|
@@ -505,10 +514,8 @@ export class PreloadFile extends BaseFile {
|
|
|
505
514
|
* @param [Number] uid
|
|
506
515
|
* @param [Number] gid
|
|
507
516
|
*/
|
|
508
|
-
chown(uid, gid) {
|
|
509
|
-
|
|
510
|
-
this.chownSync(uid, gid);
|
|
511
|
-
});
|
|
517
|
+
async chown(uid, gid) {
|
|
518
|
+
this.chownSync(uid, gid);
|
|
512
519
|
}
|
|
513
520
|
/**
|
|
514
521
|
* Synchronous `fchown`.
|
|
@@ -545,10 +552,8 @@ export class NoSyncFile extends PreloadFile {
|
|
|
545
552
|
* Asynchronous sync. Doesn't do anything, simply calls the cb.
|
|
546
553
|
* @param [Function(ZenFS.ApiError)] cb
|
|
547
554
|
*/
|
|
548
|
-
sync() {
|
|
549
|
-
return
|
|
550
|
-
return;
|
|
551
|
-
});
|
|
555
|
+
async sync() {
|
|
556
|
+
return;
|
|
552
557
|
}
|
|
553
558
|
/**
|
|
554
559
|
* Synchronous sync. Doesn't do anything.
|
|
@@ -560,10 +565,8 @@ export class NoSyncFile extends PreloadFile {
|
|
|
560
565
|
* Asynchronous close. Doesn't do anything, simply calls the cb.
|
|
561
566
|
* @param [Function(ZenFS.ApiError)] cb
|
|
562
567
|
*/
|
|
563
|
-
close() {
|
|
564
|
-
return
|
|
565
|
-
return;
|
|
566
|
-
});
|
|
568
|
+
async close() {
|
|
569
|
+
return;
|
|
567
570
|
}
|
|
568
571
|
/**
|
|
569
572
|
* Synchronous close. Doesn't do anything.
|
package/dist/filesystem.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { ApiError } from './ApiError.js';
|
|
|
2
2
|
import { Stats } from './stats.js';
|
|
3
3
|
import { File, FileFlag } from './file.js';
|
|
4
4
|
import { Cred } from './cred.js';
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
export type
|
|
5
|
+
export type NoArgCallback = (e?: ApiError) => unknown;
|
|
6
|
+
export type TwoArgCallback<T> = (e?: ApiError, rv?: T) => unknown;
|
|
7
|
+
export type ThreeArgCallback<T, U> = (e?: ApiError, arg1?: T, arg2?: U) => unknown;
|
|
8
8
|
export type FileContents = Uint8Array | string;
|
|
9
9
|
/**
|
|
10
10
|
* Metadata about a FileSystem
|