@zenfs/core 0.10.0 → 0.11.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/dist/backends/Index.d.ts +3 -3
- package/dist/backends/Index.js +4 -4
- package/dist/backends/backend.d.ts +1 -2
- package/dist/backends/backend.js +0 -5
- package/dist/backends/{Fetch.d.ts → fetch.d.ts} +4 -4
- package/dist/backends/{Fetch.js → fetch.js} +6 -7
- package/dist/backends/{Locked.d.ts → locked.d.ts} +2 -2
- package/dist/backends/{Locked.js → locked.js} +4 -5
- 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} +98 -103
- package/dist/backends/port/fs.d.ts +15 -16
- package/dist/backends/port/fs.js +20 -22
- 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 +1 -1
- package/dist/config.js +1 -1
- package/dist/emulation/shared.js +1 -1
- package/dist/error.d.ts +0 -1
- package/dist/error.js +0 -1
- package/dist/file.js +1 -1
- package/dist/filesystem.d.ts +3 -3
- package/dist/filesystem.js +26 -29
- package/dist/index.d.ts +7 -7
- package/dist/index.js +7 -7
- package/dist/inode.d.ts +1 -1
- package/package.json +1 -1
- package/src/backends/Index.ts +4 -4
- package/src/backends/backend.ts +3 -7
- package/src/backends/{Fetch.ts → fetch.ts} +13 -14
- package/src/backends/{Locked.ts → locked.ts} +5 -6
- package/src/backends/memory.ts +44 -0
- package/src/backends/{Overlay.ts → overlay.ts} +99 -105
- package/src/backends/port/fs.ts +24 -26
- 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 +3 -3
- package/src/emulation/shared.ts +1 -1
- package/src/error.ts +0 -1
- package/src/file.ts +1 -1
- package/src/filesystem.ts +29 -32
- package/src/index.ts +7 -7
- package/src/inode.ts +1 -1
- 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/dist/backends/port/store.d.ts +0 -30
- package/dist/backends/port/store.js +0 -142
- package/src/backends/AsyncStore.ts +0 -655
- package/src/backends/InMemory.ts +0 -56
- package/src/backends/SyncStore.ts +0 -589
- package/src/backends/port/store.ts +0 -187
|
@@ -2,7 +2,7 @@ import { FileSystem } from '../filesystem.js';
|
|
|
2
2
|
import { ErrnoError, Errno } from '../error.js';
|
|
3
3
|
import { PreloadFile, parseFlag } from '../file.js';
|
|
4
4
|
import { Stats } from '../stats.js';
|
|
5
|
-
import { LockedFS } from './
|
|
5
|
+
import { LockedFS } from './locked.js';
|
|
6
6
|
import { dirname } from '../emulation/path.js';
|
|
7
7
|
import { rootCred } from '../cred.js';
|
|
8
8
|
import { decode, encode } from '../utils.js';
|
|
@@ -23,7 +23,6 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
23
23
|
await this._readable.ready();
|
|
24
24
|
await this._writable.ready();
|
|
25
25
|
await this._ready;
|
|
26
|
-
return this;
|
|
27
26
|
}
|
|
28
27
|
constructor({ writable, readable }) {
|
|
29
28
|
super();
|
|
@@ -121,31 +120,31 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
|
-
async stat(
|
|
123
|
+
async stat(path, cred) {
|
|
125
124
|
this.checkInitialized();
|
|
126
125
|
try {
|
|
127
|
-
return this._writable.stat(
|
|
126
|
+
return this._writable.stat(path, cred);
|
|
128
127
|
}
|
|
129
128
|
catch (e) {
|
|
130
|
-
if (this._deletedFiles.has(
|
|
131
|
-
throw ErrnoError.With('ENOENT',
|
|
129
|
+
if (this._deletedFiles.has(path)) {
|
|
130
|
+
throw ErrnoError.With('ENOENT', path, 'stat');
|
|
132
131
|
}
|
|
133
|
-
const oldStat = new Stats(await this._readable.stat(
|
|
132
|
+
const oldStat = new Stats(await this._readable.stat(path, cred));
|
|
134
133
|
// Make the oldStat's mode writable. Preserve the topmost part of the mode, which specifies the type
|
|
135
134
|
oldStat.mode |= 0o222;
|
|
136
135
|
return oldStat;
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
|
-
statSync(
|
|
138
|
+
statSync(path, cred) {
|
|
140
139
|
this.checkInitialized();
|
|
141
140
|
try {
|
|
142
|
-
return this._writable.statSync(
|
|
141
|
+
return this._writable.statSync(path, cred);
|
|
143
142
|
}
|
|
144
143
|
catch (e) {
|
|
145
|
-
if (this._deletedFiles.has(
|
|
146
|
-
throw ErrnoError.With('ENOENT',
|
|
144
|
+
if (this._deletedFiles.has(path)) {
|
|
145
|
+
throw ErrnoError.With('ENOENT', path, 'stat');
|
|
147
146
|
}
|
|
148
|
-
const oldStat = new Stats(this._readable.statSync(
|
|
147
|
+
const oldStat = new Stats(this._readable.statSync(path, cred));
|
|
149
148
|
// Make the oldStat's mode writable. Preserve the topmost part of the mode, which specifies the type.
|
|
150
149
|
oldStat.mode |= 0o222;
|
|
151
150
|
return oldStat;
|
|
@@ -190,145 +189,145 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
190
189
|
this.checkInitialized();
|
|
191
190
|
this._writable.linkSync(srcpath, dstpath, cred);
|
|
192
191
|
}
|
|
193
|
-
async unlink(
|
|
192
|
+
async unlink(path, cred) {
|
|
194
193
|
this.checkInitialized();
|
|
195
|
-
this.checkPath(
|
|
196
|
-
if (!(await this.exists(
|
|
197
|
-
throw ErrnoError.With('ENOENT',
|
|
194
|
+
this.checkPath(path);
|
|
195
|
+
if (!(await this.exists(path, cred))) {
|
|
196
|
+
throw ErrnoError.With('ENOENT', path, 'unlink');
|
|
198
197
|
}
|
|
199
|
-
if (await this._writable.exists(
|
|
200
|
-
await this._writable.unlink(
|
|
198
|
+
if (await this._writable.exists(path, cred)) {
|
|
199
|
+
await this._writable.unlink(path, cred);
|
|
201
200
|
}
|
|
202
201
|
// if it still exists add to the delete log
|
|
203
|
-
if (await this.exists(
|
|
204
|
-
this.deletePath(
|
|
202
|
+
if (await this.exists(path, cred)) {
|
|
203
|
+
this.deletePath(path, cred);
|
|
205
204
|
}
|
|
206
205
|
}
|
|
207
|
-
unlinkSync(
|
|
206
|
+
unlinkSync(path, cred) {
|
|
208
207
|
this.checkInitialized();
|
|
209
|
-
this.checkPath(
|
|
210
|
-
if (!this.existsSync(
|
|
211
|
-
throw ErrnoError.With('ENOENT',
|
|
208
|
+
this.checkPath(path);
|
|
209
|
+
if (!this.existsSync(path, cred)) {
|
|
210
|
+
throw ErrnoError.With('ENOENT', path, 'unlink');
|
|
212
211
|
}
|
|
213
|
-
if (this._writable.existsSync(
|
|
214
|
-
this._writable.unlinkSync(
|
|
212
|
+
if (this._writable.existsSync(path, cred)) {
|
|
213
|
+
this._writable.unlinkSync(path, cred);
|
|
215
214
|
}
|
|
216
215
|
// if it still exists add to the delete log
|
|
217
|
-
if (this.existsSync(
|
|
218
|
-
this.deletePath(
|
|
216
|
+
if (this.existsSync(path, cred)) {
|
|
217
|
+
this.deletePath(path, cred);
|
|
219
218
|
}
|
|
220
219
|
}
|
|
221
|
-
async rmdir(
|
|
220
|
+
async rmdir(path, cred) {
|
|
222
221
|
this.checkInitialized();
|
|
223
|
-
if (!(await this.exists(
|
|
224
|
-
throw ErrnoError.With('ENOENT',
|
|
222
|
+
if (!(await this.exists(path, cred))) {
|
|
223
|
+
throw ErrnoError.With('ENOENT', path, 'rmdir');
|
|
225
224
|
}
|
|
226
|
-
if (await this._writable.exists(
|
|
227
|
-
await this._writable.rmdir(
|
|
225
|
+
if (await this._writable.exists(path, cred)) {
|
|
226
|
+
await this._writable.rmdir(path, cred);
|
|
228
227
|
}
|
|
229
|
-
if (await this.exists(
|
|
228
|
+
if (await this.exists(path, cred)) {
|
|
230
229
|
// Check if directory is empty.
|
|
231
|
-
if ((await this.readdir(
|
|
232
|
-
throw ErrnoError.With('ENOTEMPTY',
|
|
230
|
+
if ((await this.readdir(path, cred)).length > 0) {
|
|
231
|
+
throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
|
|
233
232
|
}
|
|
234
233
|
else {
|
|
235
|
-
this.deletePath(
|
|
234
|
+
this.deletePath(path, cred);
|
|
236
235
|
}
|
|
237
236
|
}
|
|
238
237
|
}
|
|
239
|
-
rmdirSync(
|
|
238
|
+
rmdirSync(path, cred) {
|
|
240
239
|
this.checkInitialized();
|
|
241
|
-
if (!this.existsSync(
|
|
242
|
-
throw ErrnoError.With('ENOENT',
|
|
240
|
+
if (!this.existsSync(path, cred)) {
|
|
241
|
+
throw ErrnoError.With('ENOENT', path, 'rmdir');
|
|
243
242
|
}
|
|
244
|
-
if (this._writable.existsSync(
|
|
245
|
-
this._writable.rmdirSync(
|
|
243
|
+
if (this._writable.existsSync(path, cred)) {
|
|
244
|
+
this._writable.rmdirSync(path, cred);
|
|
246
245
|
}
|
|
247
|
-
if (this.existsSync(
|
|
246
|
+
if (this.existsSync(path, cred)) {
|
|
248
247
|
// Check if directory is empty.
|
|
249
|
-
if (this.readdirSync(
|
|
250
|
-
throw ErrnoError.With('ENOTEMPTY',
|
|
248
|
+
if (this.readdirSync(path, cred).length > 0) {
|
|
249
|
+
throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
|
|
251
250
|
}
|
|
252
251
|
else {
|
|
253
|
-
this.deletePath(
|
|
252
|
+
this.deletePath(path, cred);
|
|
254
253
|
}
|
|
255
254
|
}
|
|
256
255
|
}
|
|
257
|
-
async mkdir(
|
|
256
|
+
async mkdir(path, mode, cred) {
|
|
258
257
|
this.checkInitialized();
|
|
259
|
-
if (await this.exists(
|
|
260
|
-
throw ErrnoError.With('EEXIST',
|
|
258
|
+
if (await this.exists(path, cred)) {
|
|
259
|
+
throw ErrnoError.With('EEXIST', path, 'mkdir');
|
|
261
260
|
}
|
|
262
261
|
// The below will throw should any of the parent directories fail to exist on _writable.
|
|
263
|
-
await this.createParentDirectories(
|
|
264
|
-
await this._writable.mkdir(
|
|
262
|
+
await this.createParentDirectories(path, cred);
|
|
263
|
+
await this._writable.mkdir(path, mode, cred);
|
|
265
264
|
}
|
|
266
|
-
mkdirSync(
|
|
265
|
+
mkdirSync(path, mode, cred) {
|
|
267
266
|
this.checkInitialized();
|
|
268
|
-
if (this.existsSync(
|
|
269
|
-
throw ErrnoError.With('EEXIST',
|
|
267
|
+
if (this.existsSync(path, cred)) {
|
|
268
|
+
throw ErrnoError.With('EEXIST', path, 'mkdir');
|
|
270
269
|
}
|
|
271
270
|
// The below will throw should any of the parent directories fail to exist on _writable.
|
|
272
|
-
this.createParentDirectoriesSync(
|
|
273
|
-
this._writable.mkdirSync(
|
|
271
|
+
this.createParentDirectoriesSync(path, cred);
|
|
272
|
+
this._writable.mkdirSync(path, mode, cred);
|
|
274
273
|
}
|
|
275
|
-
async readdir(
|
|
274
|
+
async readdir(path, cred) {
|
|
276
275
|
this.checkInitialized();
|
|
277
|
-
const dirStats = await this.stat(
|
|
276
|
+
const dirStats = await this.stat(path, cred);
|
|
278
277
|
if (!dirStats.isDirectory()) {
|
|
279
|
-
throw ErrnoError.With('ENOTDIR',
|
|
278
|
+
throw ErrnoError.With('ENOTDIR', path, 'readdir');
|
|
280
279
|
}
|
|
281
280
|
// Readdir in both, check delete log on RO file system's listing, merge, return.
|
|
282
281
|
const contents = [];
|
|
283
282
|
try {
|
|
284
|
-
contents.push(...(await this._writable.readdir(
|
|
283
|
+
contents.push(...(await this._writable.readdir(path, cred)));
|
|
285
284
|
}
|
|
286
285
|
catch (e) {
|
|
287
286
|
// NOP.
|
|
288
287
|
}
|
|
289
288
|
try {
|
|
290
|
-
contents.push(...(await this._readable.readdir(
|
|
289
|
+
contents.push(...(await this._readable.readdir(path, cred)).filter((fPath) => !this._deletedFiles.has(`${path}/${fPath}`)));
|
|
291
290
|
}
|
|
292
291
|
catch (e) {
|
|
293
292
|
// NOP.
|
|
294
293
|
}
|
|
295
294
|
const seenMap = {};
|
|
296
|
-
return contents.filter((
|
|
297
|
-
const result = !seenMap[
|
|
298
|
-
seenMap[
|
|
295
|
+
return contents.filter((path) => {
|
|
296
|
+
const result = !seenMap[path];
|
|
297
|
+
seenMap[path] = true;
|
|
299
298
|
return result;
|
|
300
299
|
});
|
|
301
300
|
}
|
|
302
|
-
readdirSync(
|
|
301
|
+
readdirSync(path, cred) {
|
|
303
302
|
this.checkInitialized();
|
|
304
|
-
const dirStats = this.statSync(
|
|
303
|
+
const dirStats = this.statSync(path, cred);
|
|
305
304
|
if (!dirStats.isDirectory()) {
|
|
306
|
-
throw ErrnoError.With('ENOTDIR',
|
|
305
|
+
throw ErrnoError.With('ENOTDIR', path, 'readdir');
|
|
307
306
|
}
|
|
308
307
|
// Readdir in both, check delete log on RO file system's listing, merge, return.
|
|
309
308
|
let contents = [];
|
|
310
309
|
try {
|
|
311
|
-
contents = contents.concat(this._writable.readdirSync(
|
|
310
|
+
contents = contents.concat(this._writable.readdirSync(path, cred));
|
|
312
311
|
}
|
|
313
312
|
catch (e) {
|
|
314
313
|
// NOP.
|
|
315
314
|
}
|
|
316
315
|
try {
|
|
317
|
-
contents = contents.concat(this._readable.readdirSync(
|
|
316
|
+
contents = contents.concat(this._readable.readdirSync(path, cred).filter((fPath) => !this._deletedFiles.has(`${path}/${fPath}`)));
|
|
318
317
|
}
|
|
319
318
|
catch (e) {
|
|
320
319
|
// NOP.
|
|
321
320
|
}
|
|
322
321
|
const seenMap = {};
|
|
323
|
-
return contents.filter((
|
|
324
|
-
const result = !seenMap[
|
|
325
|
-
seenMap[
|
|
322
|
+
return contents.filter((path) => {
|
|
323
|
+
const result = !seenMap[path];
|
|
324
|
+
seenMap[path] = true;
|
|
326
325
|
return result;
|
|
327
326
|
});
|
|
328
327
|
}
|
|
329
|
-
deletePath(
|
|
330
|
-
this._deletedFiles.add(
|
|
331
|
-
this.updateLog(`d${
|
|
328
|
+
deletePath(path, cred) {
|
|
329
|
+
this._deletedFiles.add(path);
|
|
330
|
+
this.updateLog(`d${path}\n`, cred);
|
|
332
331
|
}
|
|
333
332
|
async updateLog(addition, cred) {
|
|
334
333
|
this._deleteLog += addition;
|
|
@@ -382,8 +381,8 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
382
381
|
* With the given path, create the needed parent directories on the writable storage
|
|
383
382
|
* should they not exist. Use modes from the read-only storage.
|
|
384
383
|
*/
|
|
385
|
-
createParentDirectoriesSync(
|
|
386
|
-
let parent = dirname(
|
|
384
|
+
createParentDirectoriesSync(path, cred) {
|
|
385
|
+
let parent = dirname(path), toCreate = [];
|
|
387
386
|
while (!this._writable.existsSync(parent, cred)) {
|
|
388
387
|
toCreate.push(parent);
|
|
389
388
|
parent = dirname(parent);
|
|
@@ -393,8 +392,8 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
393
392
|
this._writable.mkdirSync(p, this.statSync(p, cred).mode, cred);
|
|
394
393
|
}
|
|
395
394
|
}
|
|
396
|
-
async createParentDirectories(
|
|
397
|
-
let parent = dirname(
|
|
395
|
+
async createParentDirectories(path, cred) {
|
|
396
|
+
let parent = dirname(path), toCreate = [];
|
|
398
397
|
while (!(await this._writable.exists(parent, cred))) {
|
|
399
398
|
toCreate.push(parent);
|
|
400
399
|
parent = dirname(parent);
|
|
@@ -410,53 +409,53 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
410
409
|
* - Ensures p is on writable before proceeding. Throws an error if it doesn't exist.
|
|
411
410
|
* - Calls f to perform operation on writable.
|
|
412
411
|
*/
|
|
413
|
-
operateOnWritable(
|
|
414
|
-
if (!this.existsSync(
|
|
415
|
-
throw ErrnoError.With('ENOENT',
|
|
412
|
+
operateOnWritable(path, cred) {
|
|
413
|
+
if (!this.existsSync(path, cred)) {
|
|
414
|
+
throw ErrnoError.With('ENOENT', path, 'operateOnWriteable');
|
|
416
415
|
}
|
|
417
|
-
if (!this._writable.existsSync(
|
|
416
|
+
if (!this._writable.existsSync(path, cred)) {
|
|
418
417
|
// File is on readable storage. Copy to writable storage before
|
|
419
418
|
// changing its mode.
|
|
420
|
-
this.copyToWritableSync(
|
|
419
|
+
this.copyToWritableSync(path, cred);
|
|
421
420
|
}
|
|
422
421
|
}
|
|
423
|
-
async operateOnWritableAsync(
|
|
424
|
-
if (!(await this.exists(
|
|
425
|
-
throw ErrnoError.With('ENOENT',
|
|
422
|
+
async operateOnWritableAsync(path, cred) {
|
|
423
|
+
if (!(await this.exists(path, cred))) {
|
|
424
|
+
throw ErrnoError.With('ENOENT', path, 'operateOnWritable');
|
|
426
425
|
}
|
|
427
|
-
if (!(await this._writable.exists(
|
|
428
|
-
return this.copyToWritable(
|
|
426
|
+
if (!(await this._writable.exists(path, cred))) {
|
|
427
|
+
return this.copyToWritable(path, cred);
|
|
429
428
|
}
|
|
430
429
|
}
|
|
431
430
|
/**
|
|
432
431
|
* Copy from readable to writable storage.
|
|
433
432
|
* PRECONDITION: File does not exist on writable storage.
|
|
434
433
|
*/
|
|
435
|
-
copyToWritableSync(
|
|
436
|
-
const stats = this.statSync(
|
|
434
|
+
copyToWritableSync(path, cred) {
|
|
435
|
+
const stats = this.statSync(path, cred);
|
|
437
436
|
if (stats.isDirectory()) {
|
|
438
|
-
this._writable.mkdirSync(
|
|
437
|
+
this._writable.mkdirSync(path, stats.mode, cred);
|
|
439
438
|
return;
|
|
440
439
|
}
|
|
441
440
|
const data = new Uint8Array(stats.size);
|
|
442
|
-
const readable = this._readable.openFileSync(
|
|
441
|
+
const readable = this._readable.openFileSync(path, parseFlag('r'), cred);
|
|
443
442
|
readable.readSync(data);
|
|
444
443
|
readable.closeSync();
|
|
445
|
-
const writable = this._writable.openFileSync(
|
|
444
|
+
const writable = this._writable.openFileSync(path, parseFlag('w'), cred);
|
|
446
445
|
writable.writeSync(data);
|
|
447
446
|
writable.closeSync();
|
|
448
447
|
}
|
|
449
|
-
async copyToWritable(
|
|
450
|
-
const stats = await this.stat(
|
|
448
|
+
async copyToWritable(path, cred) {
|
|
449
|
+
const stats = await this.stat(path, cred);
|
|
451
450
|
if (stats.isDirectory()) {
|
|
452
|
-
await this._writable.mkdir(
|
|
451
|
+
await this._writable.mkdir(path, stats.mode, cred);
|
|
453
452
|
return;
|
|
454
453
|
}
|
|
455
454
|
const data = new Uint8Array(stats.size);
|
|
456
|
-
const readable = await this._readable.openFile(
|
|
455
|
+
const readable = await this._readable.openFile(path, parseFlag('r'), cred);
|
|
457
456
|
await readable.read(data);
|
|
458
457
|
await readable.close();
|
|
459
|
-
const writable = await this._writable.openFile(
|
|
458
|
+
const writable = await this._writable.openFile(path, parseFlag('w'), cred);
|
|
460
459
|
await writable.write(data);
|
|
461
460
|
await writable.close();
|
|
462
461
|
}
|
|
@@ -468,10 +467,6 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
468
467
|
* @internal
|
|
469
468
|
*/
|
|
470
469
|
export class OverlayFS extends LockedFS {
|
|
471
|
-
async ready() {
|
|
472
|
-
await super.ready();
|
|
473
|
-
return this;
|
|
474
|
-
}
|
|
475
470
|
/**
|
|
476
471
|
* @param options The options to initialize the OverlayFS with
|
|
477
472
|
*/
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { FileReadResult } from 'node:fs/promises';
|
|
4
|
+
import type { ExtractProperties } from 'utilium';
|
|
3
5
|
import type { Cred } from '../../cred.js';
|
|
4
|
-
import { FileSystem, type FileSystemMetadata } from '../../filesystem.js';
|
|
5
6
|
import { File } from '../../file.js';
|
|
7
|
+
import { FileSystem, type FileSystemMetadata } from '../../filesystem.js';
|
|
6
8
|
import { Stats, type FileType } from '../../stats.js';
|
|
7
|
-
import type { SyncStoreFS } from '../SyncStore.js';
|
|
8
9
|
import * as RPC from './rpc.js';
|
|
9
|
-
import type { ExtractProperties } from 'utilium';
|
|
10
|
-
import type { FileReadResult } from 'node:fs/promises';
|
|
11
10
|
type FileMethods = ExtractProperties<File, (...args: any[]) => Promise<any>>;
|
|
12
11
|
type FileMethod = keyof FileMethods;
|
|
13
12
|
export declare class PortFile extends File {
|
|
@@ -44,7 +43,7 @@ declare const PortFS_base: (abstract new (...args: any[]) => {
|
|
|
44
43
|
_sync: FileSystem;
|
|
45
44
|
queueDone(): Promise<void>;
|
|
46
45
|
metadata(): FileSystemMetadata;
|
|
47
|
-
ready(): Promise<
|
|
46
|
+
ready(): Promise<void>;
|
|
48
47
|
renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
49
48
|
statSync(path: string, cred: Cred): Stats;
|
|
50
49
|
createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
|
|
@@ -80,7 +79,7 @@ export declare class PortFS extends PortFS_base {
|
|
|
80
79
|
/**
|
|
81
80
|
* @hidden
|
|
82
81
|
*/
|
|
83
|
-
_sync:
|
|
82
|
+
_sync: import("../store/fs.js").StoreFS;
|
|
84
83
|
/**
|
|
85
84
|
* Constructs a new PortFS instance that connects with ZenFS running on
|
|
86
85
|
* the specified port.
|
|
@@ -88,17 +87,17 @@ export declare class PortFS extends PortFS_base {
|
|
|
88
87
|
constructor(options: RPC.Options);
|
|
89
88
|
metadata(): FileSystemMetadata;
|
|
90
89
|
protected rpc<const T extends FSMethod>(method: T, ...args: Parameters<FSMethods[T]>): Promise<Awaited<ReturnType<FSMethods[T]>>>;
|
|
91
|
-
ready(): Promise<
|
|
90
|
+
ready(): Promise<void>;
|
|
92
91
|
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
93
|
-
stat(
|
|
92
|
+
stat(path: string, cred: Cred): Promise<Stats>;
|
|
94
93
|
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
95
|
-
openFile(
|
|
96
|
-
createFile(
|
|
97
|
-
unlink(
|
|
98
|
-
rmdir(
|
|
99
|
-
mkdir(
|
|
100
|
-
readdir(
|
|
101
|
-
exists(
|
|
94
|
+
openFile(path: string, flag: string, cred: Cred): Promise<File>;
|
|
95
|
+
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
96
|
+
unlink(path: string, cred: Cred): Promise<void>;
|
|
97
|
+
rmdir(path: string, cred: Cred): Promise<void>;
|
|
98
|
+
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
99
|
+
readdir(path: string, cred: Cred): Promise<string[]>;
|
|
100
|
+
exists(path: string, cred: Cred): Promise<boolean>;
|
|
102
101
|
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
103
102
|
}
|
|
104
103
|
export declare function attachFS(port: RPC.Port, fs: FileSystem): void;
|
|
@@ -118,7 +117,7 @@ export declare const Port: {
|
|
|
118
117
|
description: string;
|
|
119
118
|
};
|
|
120
119
|
};
|
|
121
|
-
isAvailable(
|
|
120
|
+
isAvailable(): Promise<boolean>;
|
|
122
121
|
create(options: RPC.Options): PortFS;
|
|
123
122
|
};
|
|
124
123
|
export {};
|
package/dist/backends/port/fs.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { ErrnoError, Errno } from '../../error.js';
|
|
3
|
-
import { FileSystem, Async } from '../../filesystem.js';
|
|
1
|
+
import { Errno, ErrnoError } from '../../error.js';
|
|
4
2
|
import { File } from '../../file.js';
|
|
3
|
+
import { Async, FileSystem } from '../../filesystem.js';
|
|
5
4
|
import { Stats } from '../../stats.js';
|
|
6
|
-
import { InMemory } from '../
|
|
5
|
+
import { InMemory } from '../memory.js';
|
|
7
6
|
import * as RPC from './rpc.js';
|
|
8
7
|
export class PortFile extends File {
|
|
9
8
|
constructor(fs, fd, path, position) {
|
|
@@ -119,37 +118,36 @@ export class PortFS extends Async(FileSystem) {
|
|
|
119
118
|
async ready() {
|
|
120
119
|
await this.rpc('ready');
|
|
121
120
|
await super.ready();
|
|
122
|
-
return this;
|
|
123
121
|
}
|
|
124
122
|
rename(oldPath, newPath, cred) {
|
|
125
123
|
return this.rpc('rename', oldPath, newPath, cred);
|
|
126
124
|
}
|
|
127
|
-
async stat(
|
|
128
|
-
return new Stats(await this.rpc('stat',
|
|
125
|
+
async stat(path, cred) {
|
|
126
|
+
return new Stats(await this.rpc('stat', path, cred));
|
|
129
127
|
}
|
|
130
128
|
sync(path, data, stats) {
|
|
131
129
|
return this.rpc('sync', path, data, stats);
|
|
132
130
|
}
|
|
133
|
-
openFile(
|
|
134
|
-
return this.rpc('openFile',
|
|
131
|
+
openFile(path, flag, cred) {
|
|
132
|
+
return this.rpc('openFile', path, flag, cred);
|
|
135
133
|
}
|
|
136
|
-
createFile(
|
|
137
|
-
return this.rpc('createFile',
|
|
134
|
+
createFile(path, flag, mode, cred) {
|
|
135
|
+
return this.rpc('createFile', path, flag, mode, cred);
|
|
138
136
|
}
|
|
139
|
-
unlink(
|
|
140
|
-
return this.rpc('unlink',
|
|
137
|
+
unlink(path, cred) {
|
|
138
|
+
return this.rpc('unlink', path, cred);
|
|
141
139
|
}
|
|
142
|
-
rmdir(
|
|
143
|
-
return this.rpc('rmdir',
|
|
140
|
+
rmdir(path, cred) {
|
|
141
|
+
return this.rpc('rmdir', path, cred);
|
|
144
142
|
}
|
|
145
|
-
mkdir(
|
|
146
|
-
return this.rpc('mkdir',
|
|
143
|
+
mkdir(path, mode, cred) {
|
|
144
|
+
return this.rpc('mkdir', path, mode, cred);
|
|
147
145
|
}
|
|
148
|
-
readdir(
|
|
149
|
-
return this.rpc('readdir',
|
|
146
|
+
readdir(path, cred) {
|
|
147
|
+
return this.rpc('readdir', path, cred);
|
|
150
148
|
}
|
|
151
|
-
exists(
|
|
152
|
-
return this.rpc('exists',
|
|
149
|
+
exists(path, cred) {
|
|
150
|
+
return this.rpc('exists', path, cred);
|
|
153
151
|
}
|
|
154
152
|
link(srcpath, dstpath, cred) {
|
|
155
153
|
return this.rpc('link', srcpath, dstpath, cred);
|
|
@@ -232,7 +230,7 @@ export const Port = {
|
|
|
232
230
|
description: 'How long to wait before the request times out',
|
|
233
231
|
},
|
|
234
232
|
},
|
|
235
|
-
async isAvailable(
|
|
233
|
+
async isAvailable() {
|
|
236
234
|
return true;
|
|
237
235
|
},
|
|
238
236
|
create(options) {
|