@zenfs/core 1.7.2 → 1.8.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.js +3 -4
- package/dist/backends/fetch.d.ts +17 -18
- package/dist/backends/fetch.js +95 -58
- package/dist/backends/index.d.ts +2 -1
- package/dist/backends/index.js +2 -1
- package/dist/backends/memory.d.ts +1 -1
- package/dist/backends/overlay.d.ts +7 -2
- package/dist/backends/overlay.js +32 -9
- package/dist/backends/passthrough.d.ts +4 -0
- package/dist/backends/passthrough.js +128 -0
- package/dist/backends/port/fs.d.ts +9 -44
- package/dist/backends/port/fs.js +93 -116
- package/dist/backends/port/rpc.d.ts +8 -5
- package/dist/backends/port/rpc.js +9 -7
- package/dist/backends/store/file_index.d.ts +38 -0
- package/dist/backends/store/file_index.js +76 -0
- package/dist/backends/store/fs.d.ts +55 -34
- package/dist/backends/store/fs.js +417 -233
- package/dist/backends/store/index_fs.d.ts +34 -0
- package/dist/backends/store/index_fs.js +67 -0
- package/dist/backends/store/inode.d.ts +26 -8
- package/dist/backends/store/inode.js +92 -91
- package/dist/backends/store/simple.d.ts +20 -20
- package/dist/backends/store/simple.js +3 -4
- package/dist/backends/store/store.d.ts +12 -12
- package/dist/backends/store/store.js +4 -6
- package/dist/devices.d.ts +11 -10
- package/dist/devices.js +15 -11
- package/dist/file.d.ts +111 -7
- package/dist/file.js +319 -71
- package/dist/filesystem.d.ts +22 -4
- package/dist/mixins/mutexed.d.ts +7 -2
- package/dist/mixins/mutexed.js +56 -0
- package/dist/mixins/sync.d.ts +1 -1
- package/dist/stats.d.ts +12 -6
- package/dist/stats.js +14 -6
- package/dist/utils.d.ts +17 -3
- package/dist/utils.js +32 -10
- package/dist/vfs/constants.d.ts +2 -2
- package/dist/vfs/constants.js +2 -2
- package/dist/vfs/dir.js +3 -1
- package/dist/vfs/index.js +4 -1
- package/dist/vfs/promises.js +31 -11
- package/dist/vfs/shared.js +2 -0
- package/dist/vfs/sync.js +25 -13
- package/dist/vfs/types.d.ts +15 -0
- package/package.json +2 -3
- package/readme.md +2 -2
- package/scripts/test.js +73 -11
- package/tests/common/mutex.test.ts +1 -1
- package/tests/fetch/run.sh +16 -0
- package/tests/fetch/server.ts +49 -0
- package/tests/fetch/setup.ts +13 -0
- package/tests/fs/read.test.ts +10 -10
- package/tests/fs/times.test.ts +2 -2
- package/tests/setup/index.ts +38 -0
- package/tests/setup/port.ts +15 -0
- package/dist/backends/file_index.d.ts +0 -63
- package/dist/backends/file_index.js +0 -163
- package/tests/common/async.test.ts +0 -31
- package/tests/setup/cow+fetch.ts +0 -45
- /package/tests/fs/{appendFile.test.ts → append.test.ts} +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { File } from '../../file.js';
|
|
2
|
+
import type { CreationOptions } from '../../filesystem.js';
|
|
3
|
+
import { Stats } from '../../stats.js';
|
|
4
|
+
import type { IndexData } from './file_index.js';
|
|
5
|
+
import { Index } from './file_index.js';
|
|
6
|
+
import { StoreFS } from './fs.js';
|
|
7
|
+
import type { Store } from './store.js';
|
|
8
|
+
/**
|
|
9
|
+
* Uses an `Index` for metadata.
|
|
10
|
+
*
|
|
11
|
+
* Implementors: You *must* populate the underlying store for read operations to work!
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class IndexFS<T extends Store> extends StoreFS<T> {
|
|
15
|
+
private indexData;
|
|
16
|
+
protected readonly index: Index;
|
|
17
|
+
protected _isInitialized: boolean;
|
|
18
|
+
ready(): Promise<void>;
|
|
19
|
+
constructor(store: T, indexData: IndexData | Promise<IndexData>);
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated
|
|
22
|
+
*/
|
|
23
|
+
reloadFiles(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated
|
|
26
|
+
*/
|
|
27
|
+
reloadFilesSync(): void;
|
|
28
|
+
stat(path: string): Promise<Stats>;
|
|
29
|
+
statSync(path: string): Stats;
|
|
30
|
+
createFile(path: string, flag: string, mode: number, options: CreationOptions): Promise<File>;
|
|
31
|
+
createFileSync(path: string, flag: string, mode: number, options: CreationOptions): File;
|
|
32
|
+
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
33
|
+
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ErrnoError } from '../../error.js';
|
|
2
|
+
import { PreloadFile } from '../../file.js';
|
|
3
|
+
import { Stats } from '../../stats.js';
|
|
4
|
+
import { S_IFREG } from '../../vfs/constants.js';
|
|
5
|
+
import { Index } from './file_index.js';
|
|
6
|
+
import { StoreFS } from './fs.js';
|
|
7
|
+
/**
|
|
8
|
+
* Uses an `Index` for metadata.
|
|
9
|
+
*
|
|
10
|
+
* Implementors: You *must* populate the underlying store for read operations to work!
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
/* node:coverage disable */
|
|
14
|
+
export class IndexFS extends StoreFS {
|
|
15
|
+
async ready() {
|
|
16
|
+
await super.ready();
|
|
17
|
+
if (this._isInitialized)
|
|
18
|
+
return;
|
|
19
|
+
this.index.fromJSON(await this.indexData);
|
|
20
|
+
this._isInitialized = true;
|
|
21
|
+
}
|
|
22
|
+
constructor(store, indexData) {
|
|
23
|
+
super(store);
|
|
24
|
+
this.indexData = indexData;
|
|
25
|
+
this.index = new Index();
|
|
26
|
+
this._isInitialized = false;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated
|
|
30
|
+
*/
|
|
31
|
+
async reloadFiles() { }
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated
|
|
34
|
+
*/
|
|
35
|
+
reloadFilesSync() { }
|
|
36
|
+
stat(path) {
|
|
37
|
+
return Promise.resolve(this.statSync(path));
|
|
38
|
+
}
|
|
39
|
+
statSync(path) {
|
|
40
|
+
if (!this.index.has(path))
|
|
41
|
+
throw ErrnoError.With('ENOENT', path, 'stat');
|
|
42
|
+
return new Stats(this.index.get(path));
|
|
43
|
+
}
|
|
44
|
+
async createFile(path, flag, mode, options) {
|
|
45
|
+
const node = await this.commitNew(path, S_IFREG, { mode, ...options }, new Uint8Array(), 'createFile');
|
|
46
|
+
const file = new PreloadFile(this, path, flag, node.toStats(), new Uint8Array());
|
|
47
|
+
this.index.set(path, node);
|
|
48
|
+
return file;
|
|
49
|
+
}
|
|
50
|
+
createFileSync(path, flag, mode, options) {
|
|
51
|
+
const node = this.commitNewSync(path, S_IFREG, { mode, ...options }, new Uint8Array(), 'createFile');
|
|
52
|
+
const file = new PreloadFile(this, path, flag, node.toStats(), new Uint8Array());
|
|
53
|
+
this.index.set(path, node);
|
|
54
|
+
return file;
|
|
55
|
+
}
|
|
56
|
+
async sync(path, data, stats) {
|
|
57
|
+
var _a;
|
|
58
|
+
(_a = this.index.get(path)) === null || _a === void 0 ? void 0 : _a.update(stats);
|
|
59
|
+
await super.sync(path, data, stats);
|
|
60
|
+
}
|
|
61
|
+
syncSync(path, data, stats) {
|
|
62
|
+
var _a;
|
|
63
|
+
(_a = this.index.get(path)) === null || _a === void 0 ? void 0 : _a.update(stats);
|
|
64
|
+
super.syncSync(path, data, stats);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/* node:coverage enable */
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { Stats, type StatsLike } from '../../stats.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Root inode
|
|
4
4
|
* @hidden
|
|
5
5
|
*/
|
|
6
|
-
export declare const rootIno
|
|
6
|
+
export declare const rootIno = 0;
|
|
7
|
+
export interface InodeFields {
|
|
8
|
+
data?: number;
|
|
9
|
+
flags?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface InodeLike extends StatsLike<number>, InodeFields {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @internal @hidden
|
|
15
|
+
*/
|
|
16
|
+
export declare const _inode_fields: readonly ["ino", "data", "size", "mode", "flags", "nlink", "uid", "gid", "atimeMs", "birthtimeMs", "mtimeMs", "ctimeMs"];
|
|
7
17
|
/**
|
|
8
18
|
* Generic inode definition that can easily be serialized.
|
|
9
19
|
* @internal
|
|
10
20
|
* @todo [BREAKING] Remove 58 byte Inode upgrade path
|
|
11
21
|
*/
|
|
12
|
-
export declare class Inode implements
|
|
13
|
-
constructor(
|
|
14
|
-
data:
|
|
22
|
+
export declare class Inode implements InodeLike {
|
|
23
|
+
constructor(data?: ArrayBufferLike | ArrayBufferView | Readonly<InodeLike>);
|
|
24
|
+
data: number;
|
|
25
|
+
/** For future use */
|
|
26
|
+
__data_old: number;
|
|
15
27
|
size: number;
|
|
16
28
|
mode: number;
|
|
17
29
|
nlink: number;
|
|
@@ -21,7 +33,13 @@ export declare class Inode implements StatsLike {
|
|
|
21
33
|
birthtimeMs: number;
|
|
22
34
|
mtimeMs: number;
|
|
23
35
|
ctimeMs: number;
|
|
24
|
-
ino:
|
|
36
|
+
ino: number;
|
|
37
|
+
/** For future use */
|
|
38
|
+
__ino_old: number;
|
|
39
|
+
flags: number;
|
|
40
|
+
/** For future use */
|
|
41
|
+
__padding: number;
|
|
42
|
+
toJSON(): InodeLike;
|
|
25
43
|
/**
|
|
26
44
|
* Handy function that converts the Inode to a Node Stats object.
|
|
27
45
|
*/
|
|
@@ -34,7 +52,7 @@ export declare class Inode implements StatsLike {
|
|
|
34
52
|
* metadata changes locally -- typically in a Stats object.
|
|
35
53
|
* - Program closes file. File object's metadata changes are synced with the
|
|
36
54
|
* file system.
|
|
37
|
-
* @
|
|
55
|
+
* @returns whether any changes have occurred.
|
|
38
56
|
*/
|
|
39
|
-
update(
|
|
57
|
+
update(data?: Partial<Readonly<InodeLike>>): boolean;
|
|
40
58
|
}
|
|
@@ -36,21 +36,25 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
|
|
|
36
36
|
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
37
37
|
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
38
38
|
};
|
|
39
|
-
import { deserialize, sizeof, struct, types as t } from 'utilium';
|
|
39
|
+
import { deserialize, pick, randomInt, sizeof, struct, types as t } from 'utilium';
|
|
40
40
|
import { Stats } from '../../stats.js';
|
|
41
|
-
import {
|
|
41
|
+
import { size_max } from '../../vfs/constants.js';
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Root inode
|
|
44
44
|
* @hidden
|
|
45
45
|
*/
|
|
46
|
-
export const rootIno =
|
|
46
|
+
export const rootIno = 0;
|
|
47
|
+
/**
|
|
48
|
+
* @internal @hidden
|
|
49
|
+
*/
|
|
50
|
+
export const _inode_fields = ['ino', 'data', 'size', 'mode', 'flags', 'nlink', 'uid', 'gid', 'atimeMs', 'birthtimeMs', 'mtimeMs', 'ctimeMs'];
|
|
47
51
|
/**
|
|
48
52
|
* Generic inode definition that can easily be serialized.
|
|
49
53
|
* @internal
|
|
50
54
|
* @todo [BREAKING] Remove 58 byte Inode upgrade path
|
|
51
55
|
*/
|
|
52
56
|
let Inode = (() => {
|
|
53
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
57
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
54
58
|
let _classDecorators = [struct()];
|
|
55
59
|
let _classDescriptor;
|
|
56
60
|
let _classExtraInitializers = [];
|
|
@@ -58,6 +62,9 @@ let Inode = (() => {
|
|
|
58
62
|
let _data_decorators;
|
|
59
63
|
let _data_initializers = [];
|
|
60
64
|
let _data_extraInitializers = [];
|
|
65
|
+
let ___data_old_decorators;
|
|
66
|
+
let ___data_old_initializers = [];
|
|
67
|
+
let ___data_old_extraInitializers = [];
|
|
61
68
|
let _size_decorators;
|
|
62
69
|
let _size_initializers = [];
|
|
63
70
|
let _size_extraInitializers = [];
|
|
@@ -88,52 +95,56 @@ let Inode = (() => {
|
|
|
88
95
|
let _ino_decorators;
|
|
89
96
|
let _ino_initializers = [];
|
|
90
97
|
let _ino_extraInitializers = [];
|
|
98
|
+
let ___ino_old_decorators;
|
|
99
|
+
let ___ino_old_initializers = [];
|
|
100
|
+
let ___ino_old_extraInitializers = [];
|
|
101
|
+
let _flags_decorators;
|
|
102
|
+
let _flags_initializers = [];
|
|
103
|
+
let _flags_extraInitializers = [];
|
|
104
|
+
let ___padding_decorators;
|
|
105
|
+
let ___padding_initializers = [];
|
|
106
|
+
let ___padding_extraInitializers = [];
|
|
91
107
|
var Inode = _classThis = class {
|
|
92
|
-
constructor(
|
|
93
|
-
this.data = __runInitializers(this, _data_initializers,
|
|
94
|
-
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
104
|
-
__runInitializers(this,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
newBuffer.set(new Uint8Array(buf));
|
|
117
|
-
/* Add a random ino.
|
|
118
|
-
This will be different from the actual one,
|
|
119
|
-
but `ino` isn't used anywhere so it should be fine.
|
|
120
|
-
*/
|
|
121
|
-
new DataView(newBuffer.buffer).setBigUint64(sz_inode - 1, randomBigInt());
|
|
122
|
-
buffer = newBuffer;
|
|
123
|
-
}
|
|
124
|
-
deserialize(this, buffer);
|
|
108
|
+
constructor(data) {
|
|
109
|
+
this.data = __runInitializers(this, _data_initializers, randomInt(0, size_max));
|
|
110
|
+
/** For future use */
|
|
111
|
+
this.__data_old = (__runInitializers(this, _data_extraInitializers), __runInitializers(this, ___data_old_initializers, 0));
|
|
112
|
+
this.size = (__runInitializers(this, ___data_old_extraInitializers), __runInitializers(this, _size_initializers, 4096));
|
|
113
|
+
this.mode = (__runInitializers(this, _size_extraInitializers), __runInitializers(this, _mode_initializers, 0));
|
|
114
|
+
this.nlink = (__runInitializers(this, _mode_extraInitializers), __runInitializers(this, _nlink_initializers, 1));
|
|
115
|
+
this.uid = (__runInitializers(this, _nlink_extraInitializers), __runInitializers(this, _uid_initializers, 0));
|
|
116
|
+
this.gid = (__runInitializers(this, _uid_extraInitializers), __runInitializers(this, _gid_initializers, 0));
|
|
117
|
+
this.atimeMs = (__runInitializers(this, _gid_extraInitializers), __runInitializers(this, _atimeMs_initializers, Date.now()));
|
|
118
|
+
this.birthtimeMs = (__runInitializers(this, _atimeMs_extraInitializers), __runInitializers(this, _birthtimeMs_initializers, Date.now()));
|
|
119
|
+
this.mtimeMs = (__runInitializers(this, _birthtimeMs_extraInitializers), __runInitializers(this, _mtimeMs_initializers, Date.now()));
|
|
120
|
+
this.ctimeMs = (__runInitializers(this, _mtimeMs_extraInitializers), __runInitializers(this, _ctimeMs_initializers, Date.now()));
|
|
121
|
+
this.ino = (__runInitializers(this, _ctimeMs_extraInitializers), __runInitializers(this, _ino_initializers, randomInt(0, size_max)));
|
|
122
|
+
/** For future use */
|
|
123
|
+
this.__ino_old = (__runInitializers(this, _ino_extraInitializers), __runInitializers(this, ___ino_old_initializers, 0));
|
|
124
|
+
this.flags = (__runInitializers(this, ___ino_old_extraInitializers), __runInitializers(this, _flags_initializers, 0));
|
|
125
|
+
/** For future use */
|
|
126
|
+
this.__padding = (__runInitializers(this, _flags_extraInitializers), __runInitializers(this, ___padding_initializers, 0));
|
|
127
|
+
__runInitializers(this, ___padding_extraInitializers);
|
|
128
|
+
if (!data)
|
|
129
|
+
return;
|
|
130
|
+
if (!('byteLength' in data)) {
|
|
131
|
+
Object.assign(this, data);
|
|
125
132
|
return;
|
|
126
133
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
if (data.byteLength < 58) {
|
|
135
|
+
throw new RangeError('Can not create an inode from a buffer less than 58 bytes');
|
|
136
|
+
}
|
|
137
|
+
// Expand the buffer so it is the right size
|
|
138
|
+
if (data.byteLength < sz_inode) {
|
|
139
|
+
const buf = ArrayBuffer.isView(data) ? data.buffer : data;
|
|
140
|
+
const newBuffer = new Uint8Array(sz_inode);
|
|
141
|
+
newBuffer.set(new Uint8Array(buf));
|
|
142
|
+
data = newBuffer;
|
|
143
|
+
}
|
|
144
|
+
deserialize(this, data);
|
|
145
|
+
}
|
|
146
|
+
toJSON() {
|
|
147
|
+
return pick(this, _inode_fields);
|
|
137
148
|
}
|
|
138
149
|
/**
|
|
139
150
|
* Handy function that converts the Inode to a Node Stats object.
|
|
@@ -149,40 +160,21 @@ let Inode = (() => {
|
|
|
149
160
|
* metadata changes locally -- typically in a Stats object.
|
|
150
161
|
* - Program closes file. File object's metadata changes are synced with the
|
|
151
162
|
* file system.
|
|
152
|
-
* @
|
|
163
|
+
* @returns whether any changes have occurred.
|
|
153
164
|
*/
|
|
154
|
-
update(
|
|
165
|
+
update(data) {
|
|
166
|
+
if (!data)
|
|
167
|
+
return false;
|
|
155
168
|
let hasChanged = false;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.nlink = stats.nlink;
|
|
166
|
-
hasChanged = true;
|
|
167
|
-
}
|
|
168
|
-
if (this.uid !== stats.uid) {
|
|
169
|
-
this.uid = stats.uid;
|
|
170
|
-
hasChanged = true;
|
|
171
|
-
}
|
|
172
|
-
if (this.gid !== stats.gid) {
|
|
173
|
-
this.gid = stats.gid;
|
|
174
|
-
hasChanged = true;
|
|
175
|
-
}
|
|
176
|
-
if (this.atimeMs !== stats.atimeMs) {
|
|
177
|
-
this.atimeMs = stats.atimeMs;
|
|
178
|
-
hasChanged = true;
|
|
179
|
-
}
|
|
180
|
-
if (this.mtimeMs !== stats.mtimeMs) {
|
|
181
|
-
this.mtimeMs = stats.mtimeMs;
|
|
182
|
-
hasChanged = true;
|
|
183
|
-
}
|
|
184
|
-
if (this.ctimeMs !== stats.ctimeMs) {
|
|
185
|
-
this.ctimeMs = stats.ctimeMs;
|
|
169
|
+
for (const key of _inode_fields) {
|
|
170
|
+
if (data[key] === undefined)
|
|
171
|
+
continue;
|
|
172
|
+
// When multiple StoreFSes are used in a single stack, the differing IDs end up here.
|
|
173
|
+
if (key == 'ino' || key == 'data')
|
|
174
|
+
continue;
|
|
175
|
+
if (this[key] === data[key])
|
|
176
|
+
continue;
|
|
177
|
+
this[key] = data[key];
|
|
186
178
|
hasChanged = true;
|
|
187
179
|
}
|
|
188
180
|
return hasChanged;
|
|
@@ -191,18 +183,23 @@ let Inode = (() => {
|
|
|
191
183
|
__setFunctionName(_classThis, "Inode");
|
|
192
184
|
(() => {
|
|
193
185
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
194
|
-
_data_decorators = [(_a = t).
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
186
|
+
_data_decorators = [(_a = t).uint32.bind(_a)];
|
|
187
|
+
___data_old_decorators = [(_b = t).uint32.bind(_b)];
|
|
188
|
+
_size_decorators = [(_c = t).uint32.bind(_c)];
|
|
189
|
+
_mode_decorators = [(_d = t).uint16.bind(_d)];
|
|
190
|
+
_nlink_decorators = [(_e = t).uint32.bind(_e)];
|
|
191
|
+
_uid_decorators = [(_f = t).uint32.bind(_f)];
|
|
192
|
+
_gid_decorators = [(_g = t).uint32.bind(_g)];
|
|
193
|
+
_atimeMs_decorators = [(_h = t).float64.bind(_h)];
|
|
194
|
+
_birthtimeMs_decorators = [(_j = t).float64.bind(_j)];
|
|
195
|
+
_mtimeMs_decorators = [(_k = t).float64.bind(_k)];
|
|
196
|
+
_ctimeMs_decorators = [(_l = t).float64.bind(_l)];
|
|
197
|
+
_ino_decorators = [(_m = t).uint32.bind(_m)];
|
|
198
|
+
___ino_old_decorators = [(_o = t).uint32.bind(_o)];
|
|
199
|
+
_flags_decorators = [(_p = t).uint32.bind(_p)];
|
|
200
|
+
___padding_decorators = [(_q = t).uint16.bind(_q)];
|
|
205
201
|
__esDecorate(null, null, _data_decorators, { kind: "field", name: "data", static: false, private: false, access: { has: obj => "data" in obj, get: obj => obj.data, set: (obj, value) => { obj.data = value; } }, metadata: _metadata }, _data_initializers, _data_extraInitializers);
|
|
202
|
+
__esDecorate(null, null, ___data_old_decorators, { kind: "field", name: "__data_old", static: false, private: false, access: { has: obj => "__data_old" in obj, get: obj => obj.__data_old, set: (obj, value) => { obj.__data_old = value; } }, metadata: _metadata }, ___data_old_initializers, ___data_old_extraInitializers);
|
|
206
203
|
__esDecorate(null, null, _size_decorators, { kind: "field", name: "size", static: false, private: false, access: { has: obj => "size" in obj, get: obj => obj.size, set: (obj, value) => { obj.size = value; } }, metadata: _metadata }, _size_initializers, _size_extraInitializers);
|
|
207
204
|
__esDecorate(null, null, _mode_decorators, { kind: "field", name: "mode", static: false, private: false, access: { has: obj => "mode" in obj, get: obj => obj.mode, set: (obj, value) => { obj.mode = value; } }, metadata: _metadata }, _mode_initializers, _mode_extraInitializers);
|
|
208
205
|
__esDecorate(null, null, _nlink_decorators, { kind: "field", name: "nlink", static: false, private: false, access: { has: obj => "nlink" in obj, get: obj => obj.nlink, set: (obj, value) => { obj.nlink = value; } }, metadata: _metadata }, _nlink_initializers, _nlink_extraInitializers);
|
|
@@ -213,6 +210,9 @@ let Inode = (() => {
|
|
|
213
210
|
__esDecorate(null, null, _mtimeMs_decorators, { kind: "field", name: "mtimeMs", static: false, private: false, access: { has: obj => "mtimeMs" in obj, get: obj => obj.mtimeMs, set: (obj, value) => { obj.mtimeMs = value; } }, metadata: _metadata }, _mtimeMs_initializers, _mtimeMs_extraInitializers);
|
|
214
211
|
__esDecorate(null, null, _ctimeMs_decorators, { kind: "field", name: "ctimeMs", static: false, private: false, access: { has: obj => "ctimeMs" in obj, get: obj => obj.ctimeMs, set: (obj, value) => { obj.ctimeMs = value; } }, metadata: _metadata }, _ctimeMs_initializers, _ctimeMs_extraInitializers);
|
|
215
212
|
__esDecorate(null, null, _ino_decorators, { kind: "field", name: "ino", static: false, private: false, access: { has: obj => "ino" in obj, get: obj => obj.ino, set: (obj, value) => { obj.ino = value; } }, metadata: _metadata }, _ino_initializers, _ino_extraInitializers);
|
|
213
|
+
__esDecorate(null, null, ___ino_old_decorators, { kind: "field", name: "__ino_old", static: false, private: false, access: { has: obj => "__ino_old" in obj, get: obj => obj.__ino_old, set: (obj, value) => { obj.__ino_old = value; } }, metadata: _metadata }, ___ino_old_initializers, ___ino_old_extraInitializers);
|
|
214
|
+
__esDecorate(null, null, _flags_decorators, { kind: "field", name: "flags", static: false, private: false, access: { has: obj => "flags" in obj, get: obj => obj.flags, set: (obj, value) => { obj.flags = value; } }, metadata: _metadata }, _flags_initializers, _flags_extraInitializers);
|
|
215
|
+
__esDecorate(null, null, ___padding_decorators, { kind: "field", name: "__padding", static: false, private: false, access: { has: obj => "__padding" in obj, get: obj => obj.__padding, set: (obj, value) => { obj.__padding = value; } }, metadata: _metadata }, ___padding_initializers, ___padding_extraInitializers);
|
|
216
216
|
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
217
217
|
Inode = _classThis = _classDescriptor.value;
|
|
218
218
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
@@ -221,3 +221,4 @@ let Inode = (() => {
|
|
|
221
221
|
return Inode = _classThis;
|
|
222
222
|
})();
|
|
223
223
|
export { Inode };
|
|
224
|
+
const sz_inode = sizeof(Inode);
|
|
@@ -3,10 +3,10 @@ import { SyncTransaction, type Store } from './store.js';
|
|
|
3
3
|
* An interface for simple synchronous stores that don't have special support for transactions and such.
|
|
4
4
|
*/
|
|
5
5
|
export interface SimpleSyncStore extends Store {
|
|
6
|
-
keys(): Iterable<
|
|
7
|
-
get(id:
|
|
8
|
-
set(id:
|
|
9
|
-
delete(id:
|
|
6
|
+
keys(): Iterable<number>;
|
|
7
|
+
get(id: number): Uint8Array | undefined;
|
|
8
|
+
set(id: number, data: Uint8Array, isMetadata?: boolean): void;
|
|
9
|
+
delete(id: number): void;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* An interface for simple asynchronous stores that don't have special support for transactions and such.
|
|
@@ -14,15 +14,15 @@ export interface SimpleSyncStore extends Store {
|
|
|
14
14
|
*/
|
|
15
15
|
export declare abstract class SimpleAsyncStore implements SimpleSyncStore {
|
|
16
16
|
abstract name: string;
|
|
17
|
-
protected cache: Map<
|
|
17
|
+
protected cache: Map<number, Uint8Array>;
|
|
18
18
|
protected queue: Set<Promise<unknown>>;
|
|
19
|
-
protected abstract entries(): Promise<Iterable<[
|
|
20
|
-
keys(): Iterable<
|
|
21
|
-
get(id:
|
|
22
|
-
set(id:
|
|
23
|
-
protected abstract _set(ino:
|
|
24
|
-
delete(id:
|
|
25
|
-
protected abstract _delete(ino:
|
|
19
|
+
protected abstract entries(): Promise<Iterable<[number, Uint8Array]>>;
|
|
20
|
+
keys(): Iterable<number>;
|
|
21
|
+
get(id: number): Uint8Array | undefined;
|
|
22
|
+
set(id: number, data: Uint8Array): void;
|
|
23
|
+
protected abstract _set(ino: number, data: Uint8Array): Promise<void>;
|
|
24
|
+
delete(id: number): void;
|
|
25
|
+
protected abstract _delete(ino: number): Promise<void>;
|
|
26
26
|
clearSync(): void;
|
|
27
27
|
abstract clear(): Promise<void>;
|
|
28
28
|
sync(): Promise<void>;
|
|
@@ -38,16 +38,16 @@ export declare class SimpleTransaction extends SyncTransaction<SimpleSyncStore>
|
|
|
38
38
|
* Stores data in the keys we modify prior to modifying them.
|
|
39
39
|
* Allows us to roll back commits.
|
|
40
40
|
*/
|
|
41
|
-
protected originalData: Map<
|
|
41
|
+
protected originalData: Map<number, Uint8Array | void>;
|
|
42
42
|
/**
|
|
43
43
|
* List of keys modified in this transaction, if any.
|
|
44
44
|
*/
|
|
45
|
-
protected modifiedKeys: Set<
|
|
45
|
+
protected modifiedKeys: Set<number>;
|
|
46
46
|
protected store: SimpleSyncStore;
|
|
47
|
-
keysSync(): Iterable<
|
|
48
|
-
getSync(id:
|
|
49
|
-
setSync(id:
|
|
50
|
-
removeSync(id:
|
|
47
|
+
keysSync(): Iterable<number>;
|
|
48
|
+
getSync(id: number): Uint8Array;
|
|
49
|
+
setSync(id: number, data: Uint8Array, isMetadata?: boolean): void;
|
|
50
|
+
removeSync(id: number): void;
|
|
51
51
|
commitSync(): void;
|
|
52
52
|
abortSync(): void;
|
|
53
53
|
/**
|
|
@@ -56,10 +56,10 @@ export declare class SimpleTransaction extends SyncTransaction<SimpleSyncStore>
|
|
|
56
56
|
* prevent needless `get` requests if the program modifies the data later
|
|
57
57
|
* on during the transaction.
|
|
58
58
|
*/
|
|
59
|
-
protected stashOldValue(id:
|
|
59
|
+
protected stashOldValue(id: number, value?: Uint8Array): void;
|
|
60
60
|
/**
|
|
61
61
|
* Marks `ino` as modified, and stashes its value if it has not been
|
|
62
62
|
* stashed already.
|
|
63
63
|
*/
|
|
64
|
-
protected markModified(id:
|
|
64
|
+
protected markModified(id: number): void;
|
|
65
65
|
}
|
|
@@ -66,9 +66,9 @@ export class SimpleTransaction extends SyncTransaction {
|
|
|
66
66
|
this.stashOldValue(id, val);
|
|
67
67
|
return val;
|
|
68
68
|
}
|
|
69
|
-
setSync(id, data) {
|
|
69
|
+
setSync(id, data, isMetadata) {
|
|
70
70
|
this.markModified(id);
|
|
71
|
-
return this.store.set(id, data);
|
|
71
|
+
return this.store.set(id, data, isMetadata);
|
|
72
72
|
}
|
|
73
73
|
removeSync(id) {
|
|
74
74
|
this.markModified(id);
|
|
@@ -78,9 +78,8 @@ export class SimpleTransaction extends SyncTransaction {
|
|
|
78
78
|
this.done = true;
|
|
79
79
|
}
|
|
80
80
|
abortSync() {
|
|
81
|
-
if (
|
|
81
|
+
if (this.done)
|
|
82
82
|
return;
|
|
83
|
-
}
|
|
84
83
|
// Rollback old values.
|
|
85
84
|
for (const key of this.modifiedKeys) {
|
|
86
85
|
const value = this.originalData.get(key);
|
|
@@ -37,45 +37,45 @@ export declare abstract class Transaction<T extends Store = Store> {
|
|
|
37
37
|
/**
|
|
38
38
|
* Gets all of the keys
|
|
39
39
|
*/
|
|
40
|
-
abstract keys(): Promise<Iterable<
|
|
40
|
+
abstract keys(): Promise<Iterable<number>>;
|
|
41
41
|
/**
|
|
42
42
|
* Gets all of the keys
|
|
43
43
|
*/
|
|
44
|
-
abstract keysSync(): Iterable<
|
|
44
|
+
abstract keysSync(): Iterable<number>;
|
|
45
45
|
/**
|
|
46
46
|
* Retrieves data.
|
|
47
47
|
* @param id The key to look under for data.
|
|
48
48
|
*/
|
|
49
|
-
abstract get(id:
|
|
49
|
+
abstract get(id: number): Promise<Uint8Array>;
|
|
50
50
|
/**
|
|
51
51
|
* Retrieves data.
|
|
52
52
|
* Throws an error if an error occurs or if the key does not exist.
|
|
53
53
|
* @param id The key to look under for data.
|
|
54
54
|
* @return The data stored under the key, or undefined if not present.
|
|
55
55
|
*/
|
|
56
|
-
abstract getSync(id:
|
|
56
|
+
abstract getSync(id: number): Uint8Array;
|
|
57
57
|
/**
|
|
58
58
|
* Adds the data to the store under an id. Overwrites any existing data.
|
|
59
59
|
* @param id The key to add the data under.
|
|
60
60
|
* @param data The data to add to the store.
|
|
61
61
|
*/
|
|
62
|
-
abstract set(id:
|
|
62
|
+
abstract set(id: number, data: Uint8Array, isMetadata?: boolean): Promise<void>;
|
|
63
63
|
/**
|
|
64
64
|
* Adds the data to the store under and id.
|
|
65
65
|
* @param id The key to add the data under.
|
|
66
66
|
* @param data The data to add to the store.
|
|
67
67
|
*/
|
|
68
|
-
abstract setSync(id:
|
|
68
|
+
abstract setSync(id: number, data: Uint8Array, isMetadata?: boolean): void;
|
|
69
69
|
/**
|
|
70
70
|
* Deletes the data at `ino`.
|
|
71
71
|
* @param id The key to delete from the store.
|
|
72
72
|
*/
|
|
73
|
-
abstract remove(id:
|
|
73
|
+
abstract remove(id: number): Promise<void>;
|
|
74
74
|
/**
|
|
75
75
|
* Deletes the data at `ino`.
|
|
76
76
|
* @param id The key to delete from the store.
|
|
77
77
|
*/
|
|
78
|
-
abstract removeSync(id:
|
|
78
|
+
abstract removeSync(id: number): void;
|
|
79
79
|
/**
|
|
80
80
|
* Commits the transaction.
|
|
81
81
|
*/
|
|
@@ -99,10 +99,10 @@ export declare abstract class Transaction<T extends Store = Store> {
|
|
|
99
99
|
* Transaction that implements asynchronous operations with synchronous ones
|
|
100
100
|
*/
|
|
101
101
|
export declare abstract class SyncTransaction<T extends Store = Store> extends Transaction<T> {
|
|
102
|
-
keys(): Promise<Iterable<
|
|
103
|
-
get(id:
|
|
104
|
-
set(id:
|
|
105
|
-
remove(id:
|
|
102
|
+
keys(): Promise<Iterable<number>>;
|
|
103
|
+
get(id: number): Promise<Uint8Array>;
|
|
104
|
+
set(id: number, data: Uint8Array, isMetadata?: boolean): Promise<void>;
|
|
105
|
+
remove(id: number): Promise<void>;
|
|
106
106
|
commit(): Promise<void>;
|
|
107
107
|
abort(): Promise<void>;
|
|
108
108
|
}
|
|
@@ -12,15 +12,13 @@ export class Transaction {
|
|
|
12
12
|
this.done = false;
|
|
13
13
|
}
|
|
14
14
|
async [Symbol.asyncDispose]() {
|
|
15
|
-
if (this.done)
|
|
15
|
+
if (this.done)
|
|
16
16
|
return;
|
|
17
|
-
}
|
|
18
17
|
await this.abort();
|
|
19
18
|
}
|
|
20
19
|
[Symbol.dispose]() {
|
|
21
|
-
if (this.done)
|
|
20
|
+
if (this.done)
|
|
22
21
|
return;
|
|
23
|
-
}
|
|
24
22
|
this.abortSync();
|
|
25
23
|
}
|
|
26
24
|
}
|
|
@@ -35,8 +33,8 @@ export class SyncTransaction extends Transaction {
|
|
|
35
33
|
async get(id) {
|
|
36
34
|
return this.getSync(id);
|
|
37
35
|
}
|
|
38
|
-
async set(id, data) {
|
|
39
|
-
return this.setSync(id, data);
|
|
36
|
+
async set(id, data, isMetadata) {
|
|
37
|
+
return this.setSync(id, data, isMetadata);
|
|
40
38
|
}
|
|
41
39
|
async remove(id) {
|
|
42
40
|
return this.removeSync(id);
|