@zenfs/core 0.17.0 → 0.18.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/backends/backend.d.ts +2 -3
- package/dist/backends/fetch.js +2 -2
- package/dist/backends/file_index.d.ts +14 -15
- package/dist/backends/file_index.js +3 -9
- package/dist/backends/overlay.d.ts +21 -22
- package/dist/backends/overlay.js +111 -114
- package/dist/backends/port/fs.d.ts +21 -22
- package/dist/backends/port/fs.js +23 -23
- package/dist/backends/store/fs.d.ts +20 -21
- package/dist/backends/store/fs.js +70 -138
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.js +2 -2
- package/dist/{cred.d.ts → credentials.d.ts} +3 -2
- package/dist/credentials.js +16 -0
- package/dist/emulation/async.d.ts +20 -5
- package/dist/emulation/async.js +57 -9
- package/dist/emulation/dir.d.ts +4 -7
- package/dist/emulation/dir.js +16 -24
- package/dist/emulation/promises.d.ts +3 -3
- package/dist/emulation/promises.js +103 -46
- package/dist/emulation/shared.d.ts +0 -3
- package/dist/emulation/shared.js +0 -6
- package/dist/emulation/sync.d.ts +3 -4
- package/dist/emulation/sync.js +107 -65
- package/dist/emulation/watchers.d.ts +40 -3
- package/dist/emulation/watchers.js +115 -9
- package/dist/error.d.ts +1 -1
- package/dist/error.js +1 -1
- package/dist/filesystem.d.ts +23 -24
- package/dist/filesystem.js +6 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/mixins/async.d.ts +13 -14
- package/dist/mixins/async.js +45 -47
- package/dist/mixins/index.d.ts +4 -0
- package/dist/mixins/index.js +4 -0
- package/dist/mixins/mutexed.d.ts +1 -1
- package/dist/mixins/mutexed.js +61 -53
- package/dist/mixins/readonly.d.ts +14 -15
- package/dist/mixins/readonly.js +12 -12
- package/dist/mixins/sync.js +20 -20
- package/dist/stats.d.ts +12 -5
- package/dist/stats.js +11 -2
- package/dist/utils.d.ts +3 -9
- package/dist/utils.js +7 -24
- package/package.json +4 -3
- package/src/backends/backend.ts +2 -3
- package/src/backends/fetch.ts +2 -2
- package/src/backends/file_index.ts +3 -12
- package/src/backends/overlay.ts +112 -116
- package/src/backends/port/fs.ts +25 -26
- package/src/backends/store/fs.ts +72 -151
- package/src/config.ts +3 -2
- package/src/{cred.ts → credentials.ts} +11 -2
- package/src/emulation/async.ts +76 -18
- package/src/emulation/dir.ts +21 -29
- package/src/emulation/promises.ts +107 -46
- package/src/emulation/shared.ts +0 -8
- package/src/emulation/sync.ts +109 -66
- package/src/emulation/watchers.ts +140 -10
- package/src/error.ts +1 -1
- package/src/filesystem.ts +25 -26
- package/src/index.ts +2 -1
- package/src/mixins/async.ts +54 -55
- package/src/mixins/index.ts +4 -0
- package/src/mixins/mutexed.ts +62 -55
- package/src/mixins/readonly.ts +26 -27
- package/src/mixins/sync.ts +22 -23
- package/src/stats.ts +15 -5
- package/src/utils.ts +9 -34
- package/dist/cred.js +0 -8
package/dist/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { checkOptions, isBackend, isBackendConfig } from './backends/backend.js';
|
|
2
|
+
import { credentials } from './credentials.js';
|
|
2
3
|
import * as fs from './emulation/index.js';
|
|
3
|
-
import { setCred } from './emulation/shared.js';
|
|
4
4
|
import { Errno, ErrnoError } from './error.js';
|
|
5
5
|
import { FileSystem } from './filesystem.js';
|
|
6
6
|
function isMountConfig(arg) {
|
|
@@ -63,7 +63,7 @@ export async function configureSingle(config) {
|
|
|
63
63
|
export async function configure(config) {
|
|
64
64
|
const uid = 'uid' in config ? config.uid || 0 : 0;
|
|
65
65
|
const gid = 'gid' in config ? config.gid || 0 : 0;
|
|
66
|
-
|
|
66
|
+
Object.assign(credentials, { uid, gid, suid: uid, sgid: gid, euid: uid, egid: gid });
|
|
67
67
|
if (!config.mounts) {
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Similar to Linux's cred struct.
|
|
4
4
|
* @see https://github.com/torvalds/linux/blob/master/include/linux/cred.h
|
|
5
5
|
*/
|
|
6
|
-
export interface
|
|
6
|
+
export interface Credentials {
|
|
7
7
|
uid: number;
|
|
8
8
|
gid: number;
|
|
9
9
|
suid: number;
|
|
@@ -11,4 +11,5 @@ export interface Cred {
|
|
|
11
11
|
euid: number;
|
|
12
12
|
egid: number;
|
|
13
13
|
}
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const credentials: Credentials;
|
|
15
|
+
export declare const rootCredentials: Credentials;
|
|
@@ -7,9 +7,10 @@ import type { FileContents } from '../filesystem.js';
|
|
|
7
7
|
import { BigIntStats, type Stats } from '../stats.js';
|
|
8
8
|
import { type Callback } from '../utils.js';
|
|
9
9
|
import type { Dirent } from './dir.js';
|
|
10
|
-
import {
|
|
10
|
+
import type { Dir } from './dir.js';
|
|
11
11
|
import * as promises from './promises.js';
|
|
12
12
|
import { ReadStream, WriteStream } from './streams.js';
|
|
13
|
+
import { FSWatcher } from './watchers.js';
|
|
13
14
|
/**
|
|
14
15
|
* Asynchronous rename. No arguments other than a possible exception are given
|
|
15
16
|
* to the completion callback.
|
|
@@ -358,7 +359,15 @@ export declare function realpath(path: fs.PathLike, options: fs.EncodingOption,
|
|
|
358
359
|
export declare function access(path: fs.PathLike, cb: Callback): void;
|
|
359
360
|
export declare function access(path: fs.PathLike, mode: number, cb: Callback): void;
|
|
360
361
|
/**
|
|
361
|
-
*
|
|
362
|
+
* Watch for changes on a file. The callback listener will be called each time the file is accessed.
|
|
363
|
+
*
|
|
364
|
+
* The `options` argument may be omitted. If provided, it should be an object with a `persistent` boolean and an `interval` number specifying the polling interval in milliseconds.
|
|
365
|
+
*
|
|
366
|
+
* When a change is detected, the `listener` callback is called with the current and previous `Stats` objects.
|
|
367
|
+
*
|
|
368
|
+
* @param path The path to the file to watch.
|
|
369
|
+
* @param options Optional options object specifying `persistent` and `interval`.
|
|
370
|
+
* @param listener The callback listener to be called when the file changes.
|
|
362
371
|
*/
|
|
363
372
|
export declare function watchFile(path: fs.PathLike, listener: (curr: Stats, prev: Stats) => void): void;
|
|
364
373
|
export declare function watchFile(path: fs.PathLike, options: {
|
|
@@ -366,13 +375,19 @@ export declare function watchFile(path: fs.PathLike, options: {
|
|
|
366
375
|
interval?: number;
|
|
367
376
|
}, listener: (curr: Stats, prev: Stats) => void): void;
|
|
368
377
|
/**
|
|
369
|
-
*
|
|
378
|
+
* Stop watching for changes on a file.
|
|
379
|
+
*
|
|
380
|
+
* If the `listener` is specified, only that particular listener is removed.
|
|
381
|
+
* If no `listener` is specified, all listeners are removed, and the file is no longer watched.
|
|
382
|
+
*
|
|
383
|
+
* @param path The path to the file to stop watching.
|
|
384
|
+
* @param listener Optional listener to remove.
|
|
370
385
|
*/
|
|
371
386
|
export declare function unwatchFile(path: fs.PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
|
|
372
|
-
export declare function watch(path: fs.PathLike, listener?: (event: string, filename: string) => any):
|
|
387
|
+
export declare function watch(path: fs.PathLike, listener?: (event: string, filename: string) => any): FSWatcher;
|
|
373
388
|
export declare function watch(path: fs.PathLike, options: {
|
|
374
389
|
persistent?: boolean;
|
|
375
|
-
}, listener?: (event: string, filename: string) => any):
|
|
390
|
+
}, listener?: (event: string, filename: string) => any): FSWatcher;
|
|
376
391
|
interface StreamOptions {
|
|
377
392
|
flags?: string;
|
|
378
393
|
encoding?: BufferEncoding;
|
package/dist/emulation/async.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import {
|
|
2
|
+
import { Errno, ErrnoError } from '../error.js';
|
|
3
3
|
import { BigIntStats } from '../stats.js';
|
|
4
|
-
import {
|
|
4
|
+
import { normalizeMode, normalizePath } from '../utils.js';
|
|
5
5
|
import { R_OK } from './constants.js';
|
|
6
6
|
import * as promises from './promises.js';
|
|
7
7
|
import { fd2file } from './shared.js';
|
|
8
8
|
import { ReadStream, WriteStream } from './streams.js';
|
|
9
|
-
import { FSWatcher } from './watchers.js';
|
|
9
|
+
import { FSWatcher, StatWatcher } from './watchers.js';
|
|
10
|
+
const nop = () => { };
|
|
10
11
|
/**
|
|
11
12
|
* Asynchronous rename. No arguments other than a possible exception are given
|
|
12
13
|
* to the completion callback.
|
|
@@ -432,19 +433,66 @@ export function access(path, cbMode, cb = nop) {
|
|
|
432
433
|
.catch(cb);
|
|
433
434
|
}
|
|
434
435
|
access;
|
|
435
|
-
|
|
436
|
-
|
|
436
|
+
const statWatchers = new Map();
|
|
437
|
+
export function watchFile(path, optsListener, listener) {
|
|
438
|
+
const normalizedPath = normalizePath(path.toString());
|
|
439
|
+
const options = typeof optsListener != 'function' ? optsListener : {};
|
|
440
|
+
if (typeof optsListener === 'function') {
|
|
441
|
+
listener = optsListener;
|
|
442
|
+
}
|
|
443
|
+
if (!listener) {
|
|
444
|
+
throw new ErrnoError(Errno.EINVAL, 'No listener specified', path.toString(), 'watchFile');
|
|
445
|
+
}
|
|
446
|
+
if (statWatchers.has(normalizedPath)) {
|
|
447
|
+
const entry = statWatchers.get(normalizedPath);
|
|
448
|
+
if (entry) {
|
|
449
|
+
entry.listeners.add(listener);
|
|
450
|
+
}
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const watcher = new StatWatcher(normalizedPath, options);
|
|
454
|
+
watcher.on('change', (curr, prev) => {
|
|
455
|
+
const entry = statWatchers.get(normalizedPath);
|
|
456
|
+
if (!entry) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
for (const listener of entry.listeners) {
|
|
460
|
+
listener(curr, prev);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
statWatchers.set(normalizedPath, { watcher, listeners: new Set() });
|
|
437
464
|
}
|
|
438
465
|
watchFile;
|
|
439
466
|
/**
|
|
440
|
-
*
|
|
467
|
+
* Stop watching for changes on a file.
|
|
468
|
+
*
|
|
469
|
+
* If the `listener` is specified, only that particular listener is removed.
|
|
470
|
+
* If no `listener` is specified, all listeners are removed, and the file is no longer watched.
|
|
471
|
+
*
|
|
472
|
+
* @param path The path to the file to stop watching.
|
|
473
|
+
* @param listener Optional listener to remove.
|
|
441
474
|
*/
|
|
442
475
|
export function unwatchFile(path, listener = nop) {
|
|
443
|
-
|
|
476
|
+
const normalizedPath = normalizePath(path.toString());
|
|
477
|
+
const entry = statWatchers.get(normalizedPath);
|
|
478
|
+
if (entry) {
|
|
479
|
+
if (listener && listener !== nop) {
|
|
480
|
+
entry.listeners.delete(listener);
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
// If no listener is specified, remove all listeners
|
|
484
|
+
entry.listeners.clear();
|
|
485
|
+
}
|
|
486
|
+
if (entry.listeners.size === 0) {
|
|
487
|
+
// No more listeners, stop the watcher
|
|
488
|
+
entry.watcher.stop();
|
|
489
|
+
statWatchers.delete(normalizedPath);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
444
492
|
}
|
|
445
493
|
unwatchFile;
|
|
446
494
|
export function watch(path, options, listener) {
|
|
447
|
-
const watcher = new FSWatcher(typeof options == 'object' ? options : {});
|
|
495
|
+
const watcher = new FSWatcher(normalizePath(path), typeof options == 'object' ? options : {});
|
|
448
496
|
listener = typeof options == 'function' ? options : listener;
|
|
449
497
|
watcher.on('change', listener || nop);
|
|
450
498
|
return watcher;
|
|
@@ -482,7 +530,7 @@ export function createReadStream(path, _options) {
|
|
|
482
530
|
handle
|
|
483
531
|
?.close()
|
|
484
532
|
.then(() => callback(error))
|
|
485
|
-
.catch(
|
|
533
|
+
.catch(nop);
|
|
486
534
|
},
|
|
487
535
|
});
|
|
488
536
|
stream.path = path.toString();
|
package/dist/emulation/dir.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type {
|
|
3
|
-
import type { Callback } from '../utils.js';
|
|
2
|
+
import type { Dir as _Dir, Dirent as _Dirent } from 'fs';
|
|
4
3
|
import type { Stats } from '../stats.js';
|
|
4
|
+
import type { Callback } from '../utils.js';
|
|
5
5
|
export declare class Dirent implements _Dirent {
|
|
6
6
|
path: string;
|
|
7
7
|
protected stats: Stats;
|
|
@@ -23,11 +23,7 @@ export declare class Dir implements _Dir {
|
|
|
23
23
|
readonly path: string;
|
|
24
24
|
protected closed: boolean;
|
|
25
25
|
protected checkClosed(): void;
|
|
26
|
-
protected _entries
|
|
27
|
-
/**
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
_loadEntries(): Promise<void>;
|
|
26
|
+
protected _entries?: Dirent[];
|
|
31
27
|
constructor(path: string);
|
|
32
28
|
/**
|
|
33
29
|
* Asynchronously close the directory's underlying resource handle.
|
|
@@ -54,6 +50,7 @@ export declare class Dir implements _Dir {
|
|
|
54
50
|
* Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
|
|
55
51
|
*/
|
|
56
52
|
readSync(): Dirent | null;
|
|
53
|
+
next(): Promise<IteratorResult<Dirent>>;
|
|
57
54
|
/**
|
|
58
55
|
* Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
|
|
59
56
|
*/
|
package/dist/emulation/dir.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Errno, ErrnoError } from '../error.js';
|
|
2
|
+
import { basename } from './path.js';
|
|
1
3
|
import { readdir } from './promises.js';
|
|
2
|
-
import { ErrnoError, Errno } from '../error.js';
|
|
3
4
|
import { readdirSync } from './sync.js';
|
|
4
|
-
import { basename } from './path.js';
|
|
5
5
|
export class Dirent {
|
|
6
6
|
get name() {
|
|
7
7
|
return basename(this.path);
|
|
@@ -44,16 +44,9 @@ export class Dir {
|
|
|
44
44
|
throw new ErrnoError(Errno.EBADF, 'Can not use closed Dir');
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
async _loadEntries() {
|
|
51
|
-
this._entries ?? (this._entries = await readdir(this.path, { withFileTypes: true }));
|
|
52
|
-
}
|
|
53
47
|
constructor(path) {
|
|
54
48
|
this.path = path;
|
|
55
49
|
this.closed = false;
|
|
56
|
-
this._entries = [];
|
|
57
50
|
}
|
|
58
51
|
close(cb) {
|
|
59
52
|
this.closed = true;
|
|
@@ -70,11 +63,12 @@ export class Dir {
|
|
|
70
63
|
this.closed = true;
|
|
71
64
|
}
|
|
72
65
|
async _read() {
|
|
73
|
-
|
|
66
|
+
this.checkClosed();
|
|
67
|
+
this._entries ?? (this._entries = await readdir(this.path, { withFileTypes: true }));
|
|
74
68
|
if (!this._entries.length) {
|
|
75
69
|
return null;
|
|
76
70
|
}
|
|
77
|
-
return this._entries.shift()
|
|
71
|
+
return this._entries.shift() ?? null;
|
|
78
72
|
}
|
|
79
73
|
read(cb) {
|
|
80
74
|
if (!cb) {
|
|
@@ -88,27 +82,25 @@ export class Dir {
|
|
|
88
82
|
* Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
|
|
89
83
|
*/
|
|
90
84
|
readSync() {
|
|
85
|
+
this.checkClosed();
|
|
91
86
|
this._entries ?? (this._entries = readdirSync(this.path, { withFileTypes: true }));
|
|
92
87
|
if (!this._entries.length) {
|
|
93
88
|
return null;
|
|
94
89
|
}
|
|
95
|
-
return this._entries.shift()
|
|
90
|
+
return this._entries.shift() ?? null;
|
|
91
|
+
}
|
|
92
|
+
async next() {
|
|
93
|
+
const value = await this._read();
|
|
94
|
+
if (value) {
|
|
95
|
+
return { done: false, value };
|
|
96
|
+
}
|
|
97
|
+
await this.close();
|
|
98
|
+
return { done: true, value: undefined };
|
|
96
99
|
}
|
|
97
100
|
/**
|
|
98
101
|
* Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
|
|
99
102
|
*/
|
|
100
103
|
[Symbol.asyncIterator]() {
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
[Symbol.asyncIterator]: this[Symbol.asyncIterator],
|
|
104
|
-
async next() {
|
|
105
|
-
const value = await _this._read();
|
|
106
|
-
if (value != null) {
|
|
107
|
-
return { done: false, value };
|
|
108
|
-
}
|
|
109
|
-
await _this.close();
|
|
110
|
-
return { done: true, value: undefined };
|
|
111
|
-
},
|
|
112
|
-
};
|
|
104
|
+
return this;
|
|
113
105
|
}
|
|
114
106
|
}
|
|
@@ -314,10 +314,10 @@ export declare function readdir(path: fs.PathLike, options: fs.ObjectEncodingOpt
|
|
|
314
314
|
}): Promise<Dirent[]>;
|
|
315
315
|
/**
|
|
316
316
|
* `link`.
|
|
317
|
-
* @param
|
|
318
|
-
* @param
|
|
317
|
+
* @param targetPath
|
|
318
|
+
* @param linkPath
|
|
319
319
|
*/
|
|
320
|
-
export declare function link(
|
|
320
|
+
export declare function link(targetPath: fs.PathLike, linkPath: fs.PathLike): Promise<void>;
|
|
321
321
|
/**
|
|
322
322
|
* `symlink`.
|
|
323
323
|
* @param target target path
|