@zenfs/core 1.0.10 → 1.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/backends/backend.d.ts +4 -8
- package/dist/backends/backend.js +7 -11
- package/dist/backends/fetch.d.ts +2 -4
- package/dist/backends/fetch.js +1 -3
- package/dist/backends/file_index.js +3 -3
- package/dist/backends/memory.d.ts +1 -1
- package/dist/backends/overlay.d.ts +7 -3
- package/dist/backends/overlay.js +13 -9
- package/dist/backends/port/fs.d.ts +12 -17
- package/dist/backends/port/fs.js +5 -8
- package/dist/backends/port/rpc.d.ts +1 -1
- package/dist/backends/store/fs.d.ts +13 -15
- package/dist/backends/store/fs.js +35 -54
- package/dist/backends/store/simple.d.ts +1 -1
- package/dist/backends/store/simple.js +1 -1
- package/dist/backends/store/store.d.ts +7 -13
- package/dist/config.d.ts +13 -5
- package/dist/config.js +36 -26
- package/dist/devices.d.ts +158 -0
- package/dist/devices.js +423 -0
- package/dist/emulation/async.d.ts +21 -176
- package/dist/emulation/async.js +17 -111
- package/dist/emulation/constants.d.ts +5 -0
- package/dist/emulation/constants.js +5 -0
- package/dist/emulation/dir.d.ts +0 -1
- package/dist/emulation/path.d.ts +0 -4
- package/dist/emulation/path.js +4 -8
- package/dist/emulation/promises.d.ts +31 -121
- package/dist/emulation/promises.js +30 -97
- package/dist/emulation/shared.d.ts +7 -3
- package/dist/emulation/shared.js +11 -7
- package/dist/emulation/streams.d.ts +0 -3
- package/dist/emulation/sync.d.ts +25 -178
- package/dist/emulation/sync.js +36 -129
- package/dist/emulation/watchers.d.ts +0 -4
- package/dist/error.d.ts +11 -11
- package/dist/error.js +8 -10
- package/dist/file.d.ts +50 -171
- package/dist/file.js +34 -117
- package/dist/filesystem.d.ts +10 -62
- package/dist/filesystem.js +5 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/inode.d.ts +0 -5
- package/dist/inode.js +0 -5
- package/dist/mixins/async.d.ts +4 -6
- package/dist/mixins/async.js +3 -1
- package/dist/mixins/mutexed.d.ts +4 -4
- package/dist/mixins/mutexed.js +7 -5
- package/dist/mixins/readonly.js +14 -15
- package/dist/mixins/shared.d.ts +5 -5
- package/dist/mixins/sync.d.ts +2 -2
- package/dist/stats.d.ts +21 -37
- package/dist/stats.js +10 -23
- package/dist/utils.d.ts +15 -7
- package/dist/utils.js +28 -6
- package/package.json +4 -4
- package/readme.md +58 -2
- package/src/backends/backend.ts +7 -11
- package/src/backends/fetch.ts +2 -4
- package/src/backends/file_index.ts +3 -3
- package/src/backends/memory.ts +1 -1
- package/src/backends/overlay.ts +11 -9
- package/src/backends/port/fs.ts +11 -14
- package/src/backends/port/rpc.ts +1 -0
- package/src/backends/store/fs.ts +40 -55
- package/src/backends/store/simple.ts +1 -1
- package/src/backends/store/store.ts +7 -13
- package/src/config.ts +48 -26
- package/src/devices.ts +469 -0
- package/src/emulation/async.ts +28 -178
- package/src/emulation/constants.ts +6 -0
- package/src/emulation/path.ts +4 -11
- package/src/emulation/promises.ts +34 -116
- package/src/emulation/shared.ts +11 -8
- package/src/emulation/sync.ts +41 -185
- package/src/error.ts +7 -11
- package/src/file.ts +48 -182
- package/src/filesystem.ts +14 -65
- package/src/index.ts +2 -0
- package/src/inode.ts +0 -6
- package/src/mixins/async.ts +4 -6
- package/src/mixins/mutexed.ts +4 -4
- package/src/mixins/readonly.ts +15 -15
- package/src/mixins/shared.ts +5 -5
- package/src/mixins/sync.ts +3 -3
- package/src/stats.ts +22 -40
- package/src/utils.ts +33 -6
package/dist/filesystem.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface FileSystemMetadata {
|
|
|
10
10
|
*/
|
|
11
11
|
name: string;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Whether the FS is readonly or not
|
|
14
14
|
*/
|
|
15
15
|
readonly: boolean;
|
|
16
16
|
/**
|
|
@@ -52,11 +52,10 @@ export interface FileSystemMetadata {
|
|
|
52
52
|
type: number;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* This class includes default implementations for `exists` and `existsSync`
|
|
58
|
-
*
|
|
55
|
+
* Provides a consistent and easy to use internal API.
|
|
56
|
+
* Default implementations for `exists` and `existsSync` are included.
|
|
59
57
|
* If you are extending this class, note that every path is an absolute path and all arguments are present.
|
|
58
|
+
* @internal
|
|
60
59
|
*/
|
|
61
60
|
export declare abstract class FileSystem {
|
|
62
61
|
/**
|
|
@@ -71,99 +70,48 @@ export declare abstract class FileSystem {
|
|
|
71
70
|
_disableSync?: boolean;
|
|
72
71
|
constructor(...args: any[]);
|
|
73
72
|
ready(): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Asynchronous rename.
|
|
76
|
-
*/
|
|
77
73
|
abstract rename(oldPath: string, newPath: string): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* Synchronous rename.
|
|
80
|
-
*/
|
|
81
74
|
abstract renameSync(oldPath: string, newPath: string): void;
|
|
82
|
-
/**
|
|
83
|
-
* Asynchronous `stat`.
|
|
84
|
-
*/
|
|
85
75
|
abstract stat(path: string): Promise<Stats>;
|
|
86
|
-
/**
|
|
87
|
-
* Synchronous `stat`.
|
|
88
|
-
*/
|
|
89
76
|
abstract statSync(path: string): Stats;
|
|
90
77
|
/**
|
|
91
|
-
* Opens the file at `path` with
|
|
78
|
+
* Opens the file at `path` with `flag`. The file must exist.
|
|
92
79
|
* @param path The path to open.
|
|
93
80
|
* @param flag The flag to use when opening the file.
|
|
94
81
|
*/
|
|
95
82
|
abstract openFile(path: string, flag: string): Promise<File>;
|
|
96
83
|
/**
|
|
97
|
-
* Opens the file at `path` with
|
|
84
|
+
* Opens the file at `path` with `flag`. The file must exist.
|
|
98
85
|
* @param path The path to open.
|
|
99
86
|
* @param flag The flag to use when opening the file.
|
|
100
|
-
* @return A File object corresponding to the opened file.
|
|
101
87
|
*/
|
|
102
88
|
abstract openFileSync(path: string, flag: string): File;
|
|
103
89
|
/**
|
|
104
|
-
* Create the file at `path` with
|
|
90
|
+
* Create the file at `path` with `mode`. Then, open it with `flag`.
|
|
105
91
|
*/
|
|
106
92
|
abstract createFile(path: string, flag: string, mode: number): Promise<File>;
|
|
107
93
|
/**
|
|
108
|
-
* Create the file at `path` with
|
|
94
|
+
* Create the file at `path` with `mode`. Then, open it with `flag`.
|
|
109
95
|
*/
|
|
110
96
|
abstract createFileSync(path: string, flag: string, mode: number): File;
|
|
111
|
-
/**
|
|
112
|
-
* Asynchronous `unlink`.
|
|
113
|
-
*/
|
|
114
97
|
abstract unlink(path: string): Promise<void>;
|
|
115
|
-
/**
|
|
116
|
-
* Synchronous `unlink`.
|
|
117
|
-
*/
|
|
118
98
|
abstract unlinkSync(path: string): void;
|
|
119
|
-
/**
|
|
120
|
-
* Asynchronous `rmdir`.
|
|
121
|
-
*/
|
|
122
99
|
abstract rmdir(path: string): Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* Synchronous `rmdir`.
|
|
125
|
-
*/
|
|
126
100
|
abstract rmdirSync(path: string): void;
|
|
127
|
-
/**
|
|
128
|
-
* Asynchronous `mkdir`.
|
|
129
|
-
* @param mode Mode to make the directory using.
|
|
130
|
-
*/
|
|
131
101
|
abstract mkdir(path: string, mode: number): Promise<void>;
|
|
132
|
-
/**
|
|
133
|
-
* Synchronous `mkdir`.
|
|
134
|
-
* @param mode Mode to make the directory using.
|
|
135
|
-
*/
|
|
136
102
|
abstract mkdirSync(path: string, mode: number): void;
|
|
137
|
-
/**
|
|
138
|
-
* Asynchronous `readdir`. Reads the contents of a directory.
|
|
139
|
-
*/
|
|
140
103
|
abstract readdir(path: string): Promise<string[]>;
|
|
141
|
-
/**
|
|
142
|
-
* Synchronous `readdir`. Reads the contents of a directory.
|
|
143
|
-
*/
|
|
144
104
|
abstract readdirSync(path: string): string[];
|
|
145
105
|
/**
|
|
146
|
-
* Test whether or not
|
|
106
|
+
* Test whether or not `path` exists.
|
|
147
107
|
*/
|
|
148
108
|
exists(path: string): Promise<boolean>;
|
|
149
109
|
/**
|
|
150
|
-
* Test whether or not
|
|
110
|
+
* Test whether or not `path` exists.
|
|
151
111
|
*/
|
|
152
112
|
existsSync(path: string): boolean;
|
|
153
|
-
/**
|
|
154
|
-
* Asynchronous `link`.
|
|
155
|
-
*/
|
|
156
113
|
abstract link(target: string, link: string): Promise<void>;
|
|
157
|
-
/**
|
|
158
|
-
* Synchronous `link`.
|
|
159
|
-
*/
|
|
160
114
|
abstract linkSync(target: string, link: string): void;
|
|
161
|
-
/**
|
|
162
|
-
* Synchronize the data and stats for path asynchronously
|
|
163
|
-
*/
|
|
164
115
|
abstract sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
165
|
-
/**
|
|
166
|
-
* Synchronize the data and stats for path synchronously
|
|
167
|
-
*/
|
|
168
116
|
abstract syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
169
117
|
}
|
package/dist/filesystem.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ZenFsType } from './stats.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* This class includes default implementations for `exists` and `existsSync`
|
|
6
|
-
*
|
|
3
|
+
* Provides a consistent and easy to use internal API.
|
|
4
|
+
* Default implementations for `exists` and `existsSync` are included.
|
|
7
5
|
* If you are extending this class, note that every path is an absolute path and all arguments are present.
|
|
6
|
+
* @internal
|
|
8
7
|
*/
|
|
9
8
|
export class FileSystem {
|
|
10
9
|
/**
|
|
@@ -25,7 +24,7 @@ export class FileSystem {
|
|
|
25
24
|
constructor(...args) { }
|
|
26
25
|
async ready() { }
|
|
27
26
|
/**
|
|
28
|
-
* Test whether or not
|
|
27
|
+
* Test whether or not `path` exists.
|
|
29
28
|
*/
|
|
30
29
|
async exists(path) {
|
|
31
30
|
try {
|
|
@@ -37,7 +36,7 @@ export class FileSystem {
|
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
/**
|
|
40
|
-
* Test whether or not
|
|
39
|
+
* Test whether or not `path` exists.
|
|
41
40
|
*/
|
|
42
41
|
existsSync(path) {
|
|
43
42
|
try {
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export * from './backends/store/store.js';
|
|
|
10
10
|
export * from './backends/backend.js';
|
|
11
11
|
export * from './config.js';
|
|
12
12
|
export * from './credentials.js';
|
|
13
|
+
export * from './devices.js';
|
|
14
|
+
export { default as devices } from './devices.js';
|
|
13
15
|
export * from './file.js';
|
|
14
16
|
export * from './filesystem.js';
|
|
15
17
|
export * from './inode.js';
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,8 @@ export * from './backends/store/store.js';
|
|
|
10
10
|
export * from './backends/backend.js';
|
|
11
11
|
export * from './config.js';
|
|
12
12
|
export * from './credentials.js';
|
|
13
|
+
export * from './devices.js';
|
|
14
|
+
export { default as devices } from './devices.js';
|
|
13
15
|
export * from './file.js';
|
|
14
16
|
export * from './filesystem.js';
|
|
15
17
|
export * from './inode.js';
|
package/dist/inode.d.ts
CHANGED
|
@@ -4,11 +4,6 @@ import { Stats, type StatsLike } from './stats.js';
|
|
|
4
4
|
* This will be helpful if in the future inode numbers/IDs are changed to strings or numbers.
|
|
5
5
|
*/
|
|
6
6
|
export type Ino = bigint;
|
|
7
|
-
/**
|
|
8
|
-
* Max 32-bit integer
|
|
9
|
-
* @hidden
|
|
10
|
-
*/
|
|
11
|
-
export declare const size_max: number;
|
|
12
7
|
/**
|
|
13
8
|
* Room inode
|
|
14
9
|
* @hidden
|
package/dist/inode.js
CHANGED
|
@@ -38,11 +38,6 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
|
|
|
38
38
|
};
|
|
39
39
|
import { Stats } from './stats.js';
|
|
40
40
|
import { types as t, struct, sizeof, serialize, deserialize } from 'utilium';
|
|
41
|
-
/**
|
|
42
|
-
* Max 32-bit integer
|
|
43
|
-
* @hidden
|
|
44
|
-
*/
|
|
45
|
-
export const size_max = 2 ** 32 - 1;
|
|
46
41
|
/**
|
|
47
42
|
* Room inode
|
|
48
43
|
* @hidden
|
package/dist/mixins/async.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { type File } from '../file.js';
|
|
2
2
|
import type { FileSystem } from '../filesystem.js';
|
|
3
3
|
import type { Stats } from '../stats.js';
|
|
4
|
-
import type {
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
4
|
+
import type { AsyncFSMethods, Mixin } from './shared.js';
|
|
5
|
+
/** @internal */
|
|
8
6
|
export type AsyncOperation = {
|
|
9
|
-
[K in keyof
|
|
10
|
-
}[keyof
|
|
7
|
+
[K in keyof AsyncFSMethods]: [K, ...Parameters<FileSystem[K]>];
|
|
8
|
+
}[keyof AsyncFSMethods];
|
|
11
9
|
/**
|
|
12
10
|
* Async() implements synchronous methods on an asynchronous file system
|
|
13
11
|
*
|
package/dist/mixins/async.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
2
|
if (value !== null && value !== void 0) {
|
|
3
3
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose;
|
|
4
|
+
var dispose, inner;
|
|
5
5
|
if (async) {
|
|
6
6
|
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
7
|
dispose = value[Symbol.asyncDispose];
|
|
@@ -9,8 +9,10 @@ var __addDisposableResource = (this && this.__addDisposableResource) || function
|
|
|
9
9
|
if (dispose === void 0) {
|
|
10
10
|
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
11
|
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
12
13
|
}
|
|
13
14
|
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
14
16
|
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
15
17
|
}
|
|
16
18
|
else if (async) {
|
package/dist/mixins/mutexed.d.ts
CHANGED
|
@@ -75,15 +75,15 @@ export declare class _MutexedFS<T extends FileSystem> implements FileSystem {
|
|
|
75
75
|
* This serializes access to an underlying async filesystem.
|
|
76
76
|
* For example, on an OverlayFS instance with an async lower
|
|
77
77
|
* directory operations like rename and rmdir may involve multiple
|
|
78
|
-
* requests involving both the upper and lower
|
|
78
|
+
* requests involving both the upper and lower file systems -- they
|
|
79
79
|
* are not executed in a single atomic step. OverlayFS uses this
|
|
80
80
|
* to avoid having to reason about the correctness of
|
|
81
81
|
* multiple requests interleaving.
|
|
82
82
|
*
|
|
83
|
-
*
|
|
83
|
+
* @privateRemarks
|
|
84
84
|
* Instead of extending the passed class, `MutexedFS` stores it internally.
|
|
85
|
-
* This is to avoid a deadlock caused when a
|
|
86
|
-
* The problem is discussed
|
|
85
|
+
* This is to avoid a deadlock caused when a method calls another one
|
|
86
|
+
* The problem is discussed extensively in [#78](https://github.com/zen-fs/core/issues/78)
|
|
87
87
|
* Instead of extending `FileSystem`,
|
|
88
88
|
* `MutexedFS` implements it in order to make sure all of the methods are passed through
|
|
89
89
|
*
|
package/dist/mixins/mutexed.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
2
|
if (value !== null && value !== void 0) {
|
|
3
3
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose;
|
|
4
|
+
var dispose, inner;
|
|
5
5
|
if (async) {
|
|
6
6
|
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
7
|
dispose = value[Symbol.asyncDispose];
|
|
@@ -9,8 +9,10 @@ var __addDisposableResource = (this && this.__addDisposableResource) || function
|
|
|
9
9
|
if (dispose === void 0) {
|
|
10
10
|
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
11
|
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
12
13
|
}
|
|
13
14
|
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
14
16
|
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
15
17
|
}
|
|
16
18
|
else if (async) {
|
|
@@ -443,15 +445,15 @@ export class _MutexedFS {
|
|
|
443
445
|
* This serializes access to an underlying async filesystem.
|
|
444
446
|
* For example, on an OverlayFS instance with an async lower
|
|
445
447
|
* directory operations like rename and rmdir may involve multiple
|
|
446
|
-
* requests involving both the upper and lower
|
|
448
|
+
* requests involving both the upper and lower file systems -- they
|
|
447
449
|
* are not executed in a single atomic step. OverlayFS uses this
|
|
448
450
|
* to avoid having to reason about the correctness of
|
|
449
451
|
* multiple requests interleaving.
|
|
450
452
|
*
|
|
451
|
-
*
|
|
453
|
+
* @privateRemarks
|
|
452
454
|
* Instead of extending the passed class, `MutexedFS` stores it internally.
|
|
453
|
-
* This is to avoid a deadlock caused when a
|
|
454
|
-
* The problem is discussed
|
|
455
|
+
* This is to avoid a deadlock caused when a method calls another one
|
|
456
|
+
* The problem is discussed extensively in [#78](https://github.com/zen-fs/core/issues/78)
|
|
455
457
|
* Instead of extending `FileSystem`,
|
|
456
458
|
* `MutexedFS` implements it in order to make sure all of the methods are passed through
|
|
457
459
|
*
|
package/dist/mixins/readonly.js
CHANGED
|
@@ -8,47 +8,46 @@ export function Readonly(FS) {
|
|
|
8
8
|
metadata() {
|
|
9
9
|
return { ...super.metadata(), readonly: true };
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
async rename(oldPath, newPath) {
|
|
11
|
+
async rename() {
|
|
13
12
|
throw new ErrnoError(Errno.EROFS);
|
|
14
13
|
}
|
|
15
|
-
renameSync(
|
|
14
|
+
renameSync() {
|
|
16
15
|
throw new ErrnoError(Errno.EROFS);
|
|
17
16
|
}
|
|
18
|
-
async createFile(
|
|
17
|
+
async createFile() {
|
|
19
18
|
throw new ErrnoError(Errno.EROFS);
|
|
20
19
|
}
|
|
21
|
-
createFileSync(
|
|
20
|
+
createFileSync() {
|
|
22
21
|
throw new ErrnoError(Errno.EROFS);
|
|
23
22
|
}
|
|
24
|
-
async unlink(
|
|
23
|
+
async unlink() {
|
|
25
24
|
throw new ErrnoError(Errno.EROFS);
|
|
26
25
|
}
|
|
27
|
-
unlinkSync(
|
|
26
|
+
unlinkSync() {
|
|
28
27
|
throw new ErrnoError(Errno.EROFS);
|
|
29
28
|
}
|
|
30
|
-
async rmdir(
|
|
29
|
+
async rmdir() {
|
|
31
30
|
throw new ErrnoError(Errno.EROFS);
|
|
32
31
|
}
|
|
33
|
-
rmdirSync(
|
|
32
|
+
rmdirSync() {
|
|
34
33
|
throw new ErrnoError(Errno.EROFS);
|
|
35
34
|
}
|
|
36
|
-
async mkdir(
|
|
35
|
+
async mkdir() {
|
|
37
36
|
throw new ErrnoError(Errno.EROFS);
|
|
38
37
|
}
|
|
39
|
-
mkdirSync(
|
|
38
|
+
mkdirSync() {
|
|
40
39
|
throw new ErrnoError(Errno.EROFS);
|
|
41
40
|
}
|
|
42
|
-
async link(
|
|
41
|
+
async link() {
|
|
43
42
|
throw new ErrnoError(Errno.EROFS);
|
|
44
43
|
}
|
|
45
|
-
linkSync(
|
|
44
|
+
linkSync() {
|
|
46
45
|
throw new ErrnoError(Errno.EROFS);
|
|
47
46
|
}
|
|
48
|
-
async sync(
|
|
47
|
+
async sync() {
|
|
49
48
|
throw new ErrnoError(Errno.EROFS);
|
|
50
49
|
}
|
|
51
|
-
syncSync(
|
|
50
|
+
syncSync() {
|
|
52
51
|
throw new ErrnoError(Errno.EROFS);
|
|
53
52
|
}
|
|
54
53
|
}
|
package/dist/mixins/shared.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import type { ExtractProperties } from 'utilium';
|
|
|
2
2
|
import type { FileSystem } from '../filesystem.js';
|
|
3
3
|
/**
|
|
4
4
|
* `TBase` with `TMixin` mixed-in.
|
|
5
|
-
* @internal
|
|
5
|
+
* @internal
|
|
6
6
|
*/
|
|
7
7
|
export type Mixin<TBase extends typeof FileSystem, TMixin> = (abstract new (...args: any[]) => TMixin) & TBase;
|
|
8
8
|
/**
|
|
9
|
-
* Asynchronous `FileSystem` methods. This is a
|
|
10
|
-
* @
|
|
9
|
+
* Asynchronous `FileSystem` methods. This is a convenience type.
|
|
10
|
+
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export type
|
|
12
|
+
export type AsyncFSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<unknown>>;
|
|
13
13
|
/**
|
|
14
|
-
* Concrete `FileSystem`. This is a
|
|
14
|
+
* Concrete `FileSystem`. This is a convenience type.
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
17
|
export type ConcreteFS = ExtractProperties<FileSystem, any>;
|
package/dist/mixins/sync.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FileSystem } from '../filesystem.js';
|
|
2
|
-
import type { Mixin,
|
|
2
|
+
import type { Mixin, AsyncFSMethods } from './shared.js';
|
|
3
3
|
/**
|
|
4
4
|
* Implements the asynchronous API in terms of the synchronous API.
|
|
5
5
|
*/
|
|
6
|
-
export declare function Sync<T extends typeof FileSystem>(FS: T): Mixin<T,
|
|
6
|
+
export declare function Sync<T extends typeof FileSystem>(FS: T): Mixin<T, AsyncFSMethods>;
|
package/dist/stats.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import type * as Node from 'fs';
|
|
3
2
|
import { type Credentials } from './credentials.js';
|
|
4
3
|
import { S_IFDIR, S_IFLNK, S_IFREG } from './emulation/constants.js';
|
|
5
4
|
/**
|
|
6
|
-
* Indicates the type of
|
|
5
|
+
* Indicates the type of a file. Applied to 'mode'.
|
|
7
6
|
*/
|
|
8
7
|
export type FileType = typeof S_IFREG | typeof S_IFDIR | typeof S_IFLNK;
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
8
|
export interface StatsLike<T extends number | bigint = number | bigint> {
|
|
13
9
|
/**
|
|
14
10
|
* Size of the item in bytes.
|
|
@@ -17,35 +13,34 @@ export interface StatsLike<T extends number | bigint = number | bigint> {
|
|
|
17
13
|
size: T;
|
|
18
14
|
/**
|
|
19
15
|
* Unix-style file mode (e.g. 0o644) that includes the item type
|
|
20
|
-
* Type of the item can be FILE, DIRECTORY, SYMLINK, or SOCKET
|
|
21
16
|
*/
|
|
22
17
|
mode: T;
|
|
23
18
|
/**
|
|
24
|
-
*
|
|
19
|
+
* Time of last access, since epoch
|
|
25
20
|
*/
|
|
26
21
|
atimeMs: T;
|
|
27
22
|
/**
|
|
28
|
-
*
|
|
23
|
+
* Time of last modification, since epoch
|
|
29
24
|
*/
|
|
30
25
|
mtimeMs: T;
|
|
31
26
|
/**
|
|
32
|
-
*
|
|
27
|
+
* Time of last time file status was changed, since epoch
|
|
33
28
|
*/
|
|
34
29
|
ctimeMs: T;
|
|
35
30
|
/**
|
|
36
|
-
*
|
|
31
|
+
* Time of file creation, since epoch
|
|
37
32
|
*/
|
|
38
33
|
birthtimeMs: T;
|
|
39
34
|
/**
|
|
40
|
-
*
|
|
35
|
+
* The id of the user that owns the file
|
|
41
36
|
*/
|
|
42
37
|
uid: T;
|
|
43
38
|
/**
|
|
44
|
-
*
|
|
39
|
+
* The id of the group that owns the file
|
|
45
40
|
*/
|
|
46
41
|
gid: T;
|
|
47
42
|
/**
|
|
48
|
-
*
|
|
43
|
+
* Inode number
|
|
49
44
|
*/
|
|
50
45
|
ino: T;
|
|
51
46
|
}
|
|
@@ -67,27 +62,27 @@ export declare abstract class StatsCommon<T extends number | bigint> implements
|
|
|
67
62
|
*/
|
|
68
63
|
dev: T;
|
|
69
64
|
/**
|
|
70
|
-
*
|
|
65
|
+
* Inode number
|
|
71
66
|
*/
|
|
72
67
|
ino: T;
|
|
73
68
|
/**
|
|
74
|
-
*
|
|
69
|
+
* Device ID (if special file)
|
|
75
70
|
*/
|
|
76
71
|
rdev: T;
|
|
77
72
|
/**
|
|
78
|
-
*
|
|
73
|
+
* Number of hard links
|
|
79
74
|
*/
|
|
80
75
|
nlink: T;
|
|
81
76
|
/**
|
|
82
|
-
*
|
|
77
|
+
* Block size for file system I/O
|
|
83
78
|
*/
|
|
84
79
|
blksize: T;
|
|
85
80
|
/**
|
|
86
|
-
*
|
|
81
|
+
* User ID of owner
|
|
87
82
|
*/
|
|
88
83
|
uid: T;
|
|
89
84
|
/**
|
|
90
|
-
*
|
|
85
|
+
* Group ID of owner
|
|
91
86
|
*/
|
|
92
87
|
gid: T;
|
|
93
88
|
/**
|
|
@@ -95,25 +90,25 @@ export declare abstract class StatsCommon<T extends number | bigint> implements
|
|
|
95
90
|
*/
|
|
96
91
|
fileData?: Uint8Array;
|
|
97
92
|
/**
|
|
98
|
-
*
|
|
93
|
+
* Time of last access, since epoch
|
|
99
94
|
*/
|
|
100
95
|
atimeMs: T;
|
|
101
96
|
get atime(): Date;
|
|
102
97
|
set atime(value: Date);
|
|
103
98
|
/**
|
|
104
|
-
*
|
|
99
|
+
* Time of last modification, since epoch
|
|
105
100
|
*/
|
|
106
101
|
mtimeMs: T;
|
|
107
102
|
get mtime(): Date;
|
|
108
103
|
set mtime(value: Date);
|
|
109
104
|
/**
|
|
110
|
-
*
|
|
105
|
+
* Time of last time file status was changed, since epoch
|
|
111
106
|
*/
|
|
112
107
|
ctimeMs: T;
|
|
113
108
|
get ctime(): Date;
|
|
114
109
|
set ctime(value: Date);
|
|
115
110
|
/**
|
|
116
|
-
*
|
|
111
|
+
* Time of file creation, since epoch
|
|
117
112
|
*/
|
|
118
113
|
birthtimeMs: T;
|
|
119
114
|
get birthtime(): Date;
|
|
@@ -127,17 +122,8 @@ export declare abstract class StatsCommon<T extends number | bigint> implements
|
|
|
127
122
|
* Creates a new stats instance from a stats-like object. Can be used to copy stats (note)
|
|
128
123
|
*/
|
|
129
124
|
constructor({ atimeMs, mtimeMs, ctimeMs, birthtimeMs, uid, gid, size, mode, ino }?: Partial<StatsLike>);
|
|
130
|
-
/**
|
|
131
|
-
* @returns true if this item is a file.
|
|
132
|
-
*/
|
|
133
125
|
isFile(): boolean;
|
|
134
|
-
/**
|
|
135
|
-
* @returns True if this item is a directory.
|
|
136
|
-
*/
|
|
137
126
|
isDirectory(): boolean;
|
|
138
|
-
/**
|
|
139
|
-
* @returns true if this item is a symbolic link
|
|
140
|
-
*/
|
|
141
127
|
isSymbolicLink(): boolean;
|
|
142
128
|
isSocket(): boolean;
|
|
143
129
|
isBlockDevice(): boolean;
|
|
@@ -156,8 +142,8 @@ export declare abstract class StatsCommon<T extends number | bigint> implements
|
|
|
156
142
|
*/
|
|
157
143
|
cred(uid?: number, gid?: number): Credentials;
|
|
158
144
|
/**
|
|
159
|
-
* Change the mode of the file.
|
|
160
|
-
* up the type of the file
|
|
145
|
+
* Change the mode of the file.
|
|
146
|
+
* We use this helper function to prevent messing up the type of the file.
|
|
161
147
|
* @internal
|
|
162
148
|
*/
|
|
163
149
|
chmod(mode: number): void;
|
|
@@ -197,9 +183,7 @@ export declare class BigIntStats extends StatsCommon<bigint> implements Node.Big
|
|
|
197
183
|
* @internal
|
|
198
184
|
*/
|
|
199
185
|
export declare function isStatsEqual<T extends number | bigint>(left: StatsCommon<T>, right: StatsCommon<T>): boolean;
|
|
200
|
-
/**
|
|
201
|
-
* @internal
|
|
202
|
-
*/
|
|
186
|
+
/** @internal */
|
|
203
187
|
export declare const ZenFsType = 525687744115;
|
|
204
188
|
/**
|
|
205
189
|
* @hidden
|
package/dist/stats.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { credentials } from './credentials.js';
|
|
2
|
-
import { S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, S_IRWXG, S_IRWXO, S_IRWXU } from './emulation/constants.js';
|
|
3
|
-
import { size_max } from './inode.js';
|
|
2
|
+
import { S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, S_IRWXG, S_IRWXO, S_IRWXU, size_max } from './emulation/constants.js';
|
|
4
3
|
/**
|
|
5
4
|
* Provides information about a particular entry in the file system.
|
|
6
5
|
* Common code used by both Stats and BigIntStats.
|
|
@@ -45,27 +44,27 @@ export class StatsCommon {
|
|
|
45
44
|
*/
|
|
46
45
|
this.dev = this._convert(0);
|
|
47
46
|
/**
|
|
48
|
-
*
|
|
47
|
+
* Inode number
|
|
49
48
|
*/
|
|
50
49
|
this.ino = this._convert(0);
|
|
51
50
|
/**
|
|
52
|
-
*
|
|
51
|
+
* Device ID (if special file)
|
|
53
52
|
*/
|
|
54
53
|
this.rdev = this._convert(0);
|
|
55
54
|
/**
|
|
56
|
-
*
|
|
55
|
+
* Number of hard links
|
|
57
56
|
*/
|
|
58
57
|
this.nlink = this._convert(1);
|
|
59
58
|
/**
|
|
60
|
-
*
|
|
59
|
+
* Block size for file system I/O
|
|
61
60
|
*/
|
|
62
61
|
this.blksize = this._convert(4096);
|
|
63
62
|
/**
|
|
64
|
-
*
|
|
63
|
+
* User ID of owner
|
|
65
64
|
*/
|
|
66
65
|
this.uid = this._convert(0);
|
|
67
66
|
/**
|
|
68
|
-
*
|
|
67
|
+
* Group ID of owner
|
|
69
68
|
*/
|
|
70
69
|
this.gid = this._convert(0);
|
|
71
70
|
const now = Date.now();
|
|
@@ -82,25 +81,15 @@ export class StatsCommon {
|
|
|
82
81
|
this.mode = (this.mode | this._convert(S_IFREG));
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
|
-
/**
|
|
86
|
-
* @returns true if this item is a file.
|
|
87
|
-
*/
|
|
88
84
|
isFile() {
|
|
89
85
|
return (this.mode & S_IFMT) === S_IFREG;
|
|
90
86
|
}
|
|
91
|
-
/**
|
|
92
|
-
* @returns True if this item is a directory.
|
|
93
|
-
*/
|
|
94
87
|
isDirectory() {
|
|
95
88
|
return (this.mode & S_IFMT) === S_IFDIR;
|
|
96
89
|
}
|
|
97
|
-
/**
|
|
98
|
-
* @returns true if this item is a symbolic link
|
|
99
|
-
*/
|
|
100
90
|
isSymbolicLink() {
|
|
101
91
|
return (this.mode & S_IFMT) === S_IFLNK;
|
|
102
92
|
}
|
|
103
|
-
// Currently unsupported
|
|
104
93
|
isSocket() {
|
|
105
94
|
return (this.mode & S_IFMT) === S_IFSOCK;
|
|
106
95
|
}
|
|
@@ -143,8 +132,8 @@ export class StatsCommon {
|
|
|
143
132
|
};
|
|
144
133
|
}
|
|
145
134
|
/**
|
|
146
|
-
* Change the mode of the file.
|
|
147
|
-
* up the type of the file
|
|
135
|
+
* Change the mode of the file.
|
|
136
|
+
* We use this helper function to prevent messing up the type of the file.
|
|
148
137
|
* @internal
|
|
149
138
|
*/
|
|
150
139
|
chmod(mode) {
|
|
@@ -212,9 +201,7 @@ export class BigIntStats extends StatsCommon {
|
|
|
212
201
|
export function isStatsEqual(left, right) {
|
|
213
202
|
return left.size == right.size && +left.atime == +right.atime && +left.mtime == +right.mtime && +left.ctime == +right.ctime && left.mode == right.mode;
|
|
214
203
|
}
|
|
215
|
-
/**
|
|
216
|
-
* @internal
|
|
217
|
-
*/
|
|
204
|
+
/** @internal */
|
|
218
205
|
export const ZenFsType = 0x7a656e6673; // 'z' 'e' 'n' 'f' 's'
|
|
219
206
|
/**
|
|
220
207
|
* @hidden
|