@zenfs/core 1.0.2 → 1.0.3

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/inode.d.ts CHANGED
@@ -23,30 +23,18 @@ export declare function randomIno(): Ino;
23
23
  * Generic inode definition that can easily be serialized.
24
24
  */
25
25
  export declare class Inode implements StatsLike {
26
- readonly buffer: ArrayBufferLike;
27
26
  get data(): Uint8Array;
28
- protected view: DataView;
29
27
  constructor(buffer?: ArrayBufferLike);
30
- get ino(): Ino;
31
- set ino(value: Ino);
32
- get size(): number;
33
- set size(value: number);
34
- get mode(): number;
35
- set mode(value: number);
36
- get nlink(): number;
37
- set nlink(value: number);
38
- get uid(): number;
39
- set uid(value: number);
40
- get gid(): number;
41
- set gid(value: number);
42
- get atimeMs(): number;
43
- set atimeMs(value: number);
44
- get birthtimeMs(): number;
45
- set birthtimeMs(value: number);
46
- get mtimeMs(): number;
47
- set mtimeMs(value: number);
48
- get ctimeMs(): number;
49
- set ctimeMs(value: number);
28
+ ino: Ino;
29
+ size: number;
30
+ mode: number;
31
+ nlink: number;
32
+ uid: number;
33
+ gid: number;
34
+ atimeMs: number;
35
+ birthtimeMs: number;
36
+ mtimeMs: number;
37
+ ctimeMs: number;
50
38
  /**
51
39
  * Handy function that converts the Inode to a Node Stats object.
52
40
  */
package/dist/inode.js CHANGED
@@ -1,4 +1,43 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
36
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
37
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
38
+ };
1
39
  import { Stats } from './stats.js';
40
+ import { types as t, struct, sizeof, serialize, deserialize } from 'utilium';
2
41
  /**
3
42
  * Max 32-bit integer
4
43
  * @hidden
@@ -22,178 +61,159 @@ function _random() {
22
61
  export function randomIno() {
23
62
  return BigInt('0x' + _random() + _random());
24
63
  }
25
- /**
26
- * Offsets for inode members
27
- */
28
- const offsets = {
29
- ino: 0,
30
- size: 8,
31
- mode: 12,
32
- nlink: 14,
33
- uid: 18,
34
- gid: 22,
35
- atime: 26,
36
- birthtime: 34,
37
- mtime: 42,
38
- ctime: 50,
39
- end: 58,
40
- };
41
- /**
42
- * Offsets for a 64-bit inode's members
43
- * Currently unused
44
- */
45
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
- const offsets_64 = {
47
- ino: 0,
48
- size: 8,
49
- mode: 16,
50
- nlink: 18,
51
- uid: 22,
52
- gid: 26,
53
- atime: 30,
54
- birthtime: 38,
55
- mtime: 46,
56
- ctime: 54,
57
- end: 62,
58
- };
59
64
  /**
60
65
  * Generic inode definition that can easily be serialized.
61
66
  */
62
- export class Inode {
63
- get data() {
64
- return new Uint8Array(this.buffer);
65
- }
66
- constructor(buffer) {
67
- const setDefaults = !buffer;
68
- buffer ?? (buffer = new ArrayBuffer(offsets.end));
69
- if (buffer?.byteLength < offsets.end) {
70
- throw new RangeError(`Can not create an inode from a buffer less than ${offsets.end} bytes`);
71
- }
72
- this.view = new DataView(buffer);
73
- this.buffer = buffer;
74
- if (!setDefaults) {
75
- return;
76
- }
77
- // set defaults on a fresh inode
78
- this.ino = randomIno();
79
- this.nlink = 1;
80
- this.size = 4096;
81
- const now = Date.now();
82
- this.atimeMs = now;
83
- this.mtimeMs = now;
84
- this.ctimeMs = now;
85
- this.birthtimeMs = now;
86
- }
87
- get ino() {
88
- return this.view.getBigUint64(offsets.ino, true);
89
- }
90
- set ino(value) {
91
- this.view.setBigUint64(offsets.ino, value, true);
92
- }
93
- get size() {
94
- return this.view.getUint32(offsets.size, true);
95
- }
96
- set size(value) {
97
- this.view.setUint32(offsets.size, value, true);
98
- }
99
- get mode() {
100
- return this.view.getUint16(offsets.mode, true);
101
- }
102
- set mode(value) {
103
- this.view.setUint16(offsets.mode, value, true);
104
- }
105
- get nlink() {
106
- return this.view.getUint32(offsets.nlink, true);
107
- }
108
- set nlink(value) {
109
- this.view.setUint32(offsets.nlink, value, true);
110
- }
111
- get uid() {
112
- return this.view.getUint32(offsets.uid, true);
113
- }
114
- set uid(value) {
115
- this.view.setUint32(offsets.uid, value, true);
116
- }
117
- get gid() {
118
- return this.view.getUint32(offsets.gid, true);
119
- }
120
- set gid(value) {
121
- this.view.setUint32(offsets.gid, value, true);
122
- }
123
- get atimeMs() {
124
- return this.view.getFloat64(offsets.atime, true);
125
- }
126
- set atimeMs(value) {
127
- this.view.setFloat64(offsets.atime, value, true);
128
- }
129
- get birthtimeMs() {
130
- return this.view.getFloat64(offsets.birthtime, true);
131
- }
132
- set birthtimeMs(value) {
133
- this.view.setFloat64(offsets.birthtime, value, true);
134
- }
135
- get mtimeMs() {
136
- return this.view.getFloat64(offsets.mtime, true);
137
- }
138
- set mtimeMs(value) {
139
- this.view.setFloat64(offsets.mtime, value, true);
140
- }
141
- get ctimeMs() {
142
- return this.view.getFloat64(offsets.ctime, true);
143
- }
144
- set ctimeMs(value) {
145
- this.view.setFloat64(offsets.ctime, value, true);
146
- }
147
- /**
148
- * Handy function that converts the Inode to a Node Stats object.
149
- */
150
- toStats() {
151
- return new Stats(this);
152
- }
153
- /**
154
- * Updates the Inode using information from the stats object. Used by file
155
- * systems at sync time, e.g.:
156
- * - Program opens file and gets a File object.
157
- * - Program mutates file. File object is responsible for maintaining
158
- * metadata changes locally -- typically in a Stats object.
159
- * - Program closes file. File object's metadata changes are synced with the
160
- * file system.
161
- * @return True if any changes have occurred.
162
- */
163
- update(stats) {
164
- let hasChanged = false;
165
- if (this.size !== stats.size) {
166
- this.size = stats.size;
167
- hasChanged = true;
168
- }
169
- if (this.mode !== stats.mode) {
170
- this.mode = stats.mode;
171
- hasChanged = true;
67
+ let Inode = (() => {
68
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
69
+ let _classDecorators = [struct()];
70
+ let _classDescriptor;
71
+ let _classExtraInitializers = [];
72
+ let _classThis;
73
+ let _ino_decorators;
74
+ let _ino_initializers = [];
75
+ let _ino_extraInitializers = [];
76
+ let _size_decorators;
77
+ let _size_initializers = [];
78
+ let _size_extraInitializers = [];
79
+ let _mode_decorators;
80
+ let _mode_initializers = [];
81
+ let _mode_extraInitializers = [];
82
+ let _nlink_decorators;
83
+ let _nlink_initializers = [];
84
+ let _nlink_extraInitializers = [];
85
+ let _uid_decorators;
86
+ let _uid_initializers = [];
87
+ let _uid_extraInitializers = [];
88
+ let _gid_decorators;
89
+ let _gid_initializers = [];
90
+ let _gid_extraInitializers = [];
91
+ let _atimeMs_decorators;
92
+ let _atimeMs_initializers = [];
93
+ let _atimeMs_extraInitializers = [];
94
+ let _birthtimeMs_decorators;
95
+ let _birthtimeMs_initializers = [];
96
+ let _birthtimeMs_extraInitializers = [];
97
+ let _mtimeMs_decorators;
98
+ let _mtimeMs_initializers = [];
99
+ let _mtimeMs_extraInitializers = [];
100
+ let _ctimeMs_decorators;
101
+ let _ctimeMs_initializers = [];
102
+ let _ctimeMs_extraInitializers = [];
103
+ var Inode = _classThis = class {
104
+ get data() {
105
+ return serialize(this);
172
106
  }
173
- if (this.nlink !== stats.nlink) {
174
- this.nlink = stats.nlink;
175
- hasChanged = true;
107
+ constructor(buffer) {
108
+ this.ino = __runInitializers(this, _ino_initializers, void 0);
109
+ this.size = (__runInitializers(this, _ino_extraInitializers), __runInitializers(this, _size_initializers, void 0));
110
+ this.mode = (__runInitializers(this, _size_extraInitializers), __runInitializers(this, _mode_initializers, void 0));
111
+ this.nlink = (__runInitializers(this, _mode_extraInitializers), __runInitializers(this, _nlink_initializers, void 0));
112
+ this.uid = (__runInitializers(this, _nlink_extraInitializers), __runInitializers(this, _uid_initializers, void 0));
113
+ this.gid = (__runInitializers(this, _uid_extraInitializers), __runInitializers(this, _gid_initializers, void 0));
114
+ this.atimeMs = (__runInitializers(this, _gid_extraInitializers), __runInitializers(this, _atimeMs_initializers, void 0));
115
+ this.birthtimeMs = (__runInitializers(this, _atimeMs_extraInitializers), __runInitializers(this, _birthtimeMs_initializers, void 0));
116
+ this.mtimeMs = (__runInitializers(this, _birthtimeMs_extraInitializers), __runInitializers(this, _mtimeMs_initializers, void 0));
117
+ this.ctimeMs = (__runInitializers(this, _mtimeMs_extraInitializers), __runInitializers(this, _ctimeMs_initializers, void 0));
118
+ __runInitializers(this, _ctimeMs_extraInitializers);
119
+ if (buffer) {
120
+ if (buffer.byteLength < sizeof(Inode)) {
121
+ throw new RangeError(`Can not create an inode from a buffer less than ${sizeof(Inode)} bytes`);
122
+ }
123
+ deserialize(this, buffer);
124
+ return;
125
+ }
126
+ // set defaults on a fresh inode
127
+ this.ino = randomIno();
128
+ this.nlink = 1;
129
+ this.size = 4096;
130
+ const now = Date.now();
131
+ this.atimeMs = now;
132
+ this.mtimeMs = now;
133
+ this.ctimeMs = now;
134
+ this.birthtimeMs = now;
176
135
  }
177
- if (this.uid !== stats.uid) {
178
- this.uid = stats.uid;
179
- hasChanged = true;
136
+ /**
137
+ * Handy function that converts the Inode to a Node Stats object.
138
+ */
139
+ toStats() {
140
+ return new Stats(this);
180
141
  }
181
- if (this.uid !== stats.uid) {
182
- this.uid = stats.uid;
183
- hasChanged = true;
142
+ /**
143
+ * Updates the Inode using information from the stats object. Used by file
144
+ * systems at sync time, e.g.:
145
+ * - Program opens file and gets a File object.
146
+ * - Program mutates file. File object is responsible for maintaining
147
+ * metadata changes locally -- typically in a Stats object.
148
+ * - Program closes file. File object's metadata changes are synced with the
149
+ * file system.
150
+ * @return True if any changes have occurred.
151
+ */
152
+ update(stats) {
153
+ let hasChanged = false;
154
+ if (this.size !== stats.size) {
155
+ this.size = stats.size;
156
+ hasChanged = true;
157
+ }
158
+ if (this.mode !== stats.mode) {
159
+ this.mode = stats.mode;
160
+ hasChanged = true;
161
+ }
162
+ if (this.nlink !== stats.nlink) {
163
+ this.nlink = stats.nlink;
164
+ hasChanged = true;
165
+ }
166
+ if (this.uid !== stats.uid) {
167
+ this.uid = stats.uid;
168
+ hasChanged = true;
169
+ }
170
+ if (this.uid !== stats.uid) {
171
+ this.uid = stats.uid;
172
+ hasChanged = true;
173
+ }
174
+ if (this.atimeMs !== stats.atimeMs) {
175
+ this.atimeMs = stats.atimeMs;
176
+ hasChanged = true;
177
+ }
178
+ if (this.mtimeMs !== stats.mtimeMs) {
179
+ this.mtimeMs = stats.mtimeMs;
180
+ hasChanged = true;
181
+ }
182
+ if (this.ctimeMs !== stats.ctimeMs) {
183
+ this.ctimeMs = stats.ctimeMs;
184
+ hasChanged = true;
185
+ }
186
+ return hasChanged;
184
187
  }
185
- if (this.atimeMs !== stats.atimeMs) {
186
- this.atimeMs = stats.atimeMs;
187
- hasChanged = true;
188
- }
189
- if (this.mtimeMs !== stats.mtimeMs) {
190
- this.mtimeMs = stats.mtimeMs;
191
- hasChanged = true;
192
- }
193
- if (this.ctimeMs !== stats.ctimeMs) {
194
- this.ctimeMs = stats.ctimeMs;
195
- hasChanged = true;
196
- }
197
- return hasChanged;
198
- }
199
- }
188
+ };
189
+ __setFunctionName(_classThis, "Inode");
190
+ (() => {
191
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
192
+ _ino_decorators = [(_a = t).uint64.bind(_a)];
193
+ _size_decorators = [(_b = t).uint32.bind(_b)];
194
+ _mode_decorators = [(_c = t).uint16.bind(_c)];
195
+ _nlink_decorators = [(_d = t).uint32.bind(_d)];
196
+ _uid_decorators = [(_e = t).uint32.bind(_e)];
197
+ _gid_decorators = [(_f = t).uint32.bind(_f)];
198
+ _atimeMs_decorators = [(_g = t).float64.bind(_g)];
199
+ _birthtimeMs_decorators = [(_h = t).float64.bind(_h)];
200
+ _mtimeMs_decorators = [(_j = t).float64.bind(_j)];
201
+ _ctimeMs_decorators = [(_k = t).float64.bind(_k)];
202
+ __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);
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);
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);
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);
206
+ __esDecorate(null, null, _uid_decorators, { kind: "field", name: "uid", static: false, private: false, access: { has: obj => "uid" in obj, get: obj => obj.uid, set: (obj, value) => { obj.uid = value; } }, metadata: _metadata }, _uid_initializers, _uid_extraInitializers);
207
+ __esDecorate(null, null, _gid_decorators, { kind: "field", name: "gid", static: false, private: false, access: { has: obj => "gid" in obj, get: obj => obj.gid, set: (obj, value) => { obj.gid = value; } }, metadata: _metadata }, _gid_initializers, _gid_extraInitializers);
208
+ __esDecorate(null, null, _atimeMs_decorators, { kind: "field", name: "atimeMs", static: false, private: false, access: { has: obj => "atimeMs" in obj, get: obj => obj.atimeMs, set: (obj, value) => { obj.atimeMs = value; } }, metadata: _metadata }, _atimeMs_initializers, _atimeMs_extraInitializers);
209
+ __esDecorate(null, null, _birthtimeMs_decorators, { kind: "field", name: "birthtimeMs", static: false, private: false, access: { has: obj => "birthtimeMs" in obj, get: obj => obj.birthtimeMs, set: (obj, value) => { obj.birthtimeMs = value; } }, metadata: _metadata }, _birthtimeMs_initializers, _birthtimeMs_extraInitializers);
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);
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);
212
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
213
+ Inode = _classThis = _classDescriptor.value;
214
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
215
+ __runInitializers(_classThis, _classExtraInitializers);
216
+ })();
217
+ return Inode = _classThis;
218
+ })();
219
+ export { Inode };
@@ -1,4 +1,5 @@
1
1
  export * from './async.js';
2
2
  export * from './mutexed.js';
3
3
  export * from './readonly.js';
4
+ export * from './shared.js';
4
5
  export * from './sync.js';
@@ -1,4 +1,5 @@
1
1
  export * from './async.js';
2
2
  export * from './mutexed.js';
3
3
  export * from './readonly.js';
4
+ export * from './shared.js';
4
5
  export * from './sync.js';
@@ -7,7 +7,11 @@ import type { FileSystem } from '../filesystem.js';
7
7
  export type Mixin<TBase extends typeof FileSystem, TMixin> = (abstract new (...args: any[]) => TMixin) & TBase;
8
8
  /**
9
9
  * Asynchronous `FileSystem` methods. This is a convience type.
10
- * @internal
10
+ * @hidden
11
11
  */
12
12
  export type _AsyncFSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<unknown>>;
13
+ /**
14
+ * Concrete `FileSystem`. This is a convience type.
15
+ * @internal
16
+ */
13
17
  export type ConcreteFS = ExtractProperties<FileSystem, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "A filesystem, anywhere",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -66,7 +66,7 @@
66
66
  "eventemitter3": "^5.0.1",
67
67
  "minimatch": "^9.0.3",
68
68
  "readable-stream": "^4.5.2",
69
- "utilium": "^0.7.0"
69
+ "utilium": "^0.7.2"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@eslint/js": "^9.8.0",
@@ -84,7 +84,7 @@ export function request<const TRequest extends Request, TValue>(
84
84
  request: Omit<TRequest, 'id' | 'stack' | '_zenfs'>,
85
85
  { port, timeout = 1000, fs }: Partial<Options> & { fs?: PortFS } = {}
86
86
  ): Promise<TValue> {
87
- const stack = new Error().stack!.slice('Error:'.length);
87
+ const stack = '\n' + new Error().stack!.slice('Error:'.length);
88
88
  if (!port) {
89
89
  throw ErrnoError.With('EINVAL');
90
90
  }
package/src/inode.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Stats, type StatsLike } from './stats.js';
2
+ import { types as t, struct, sizeof, serialize, deserialize } from 'utilium';
2
3
 
3
4
  /**
4
5
  * Alias for an ino.
@@ -33,64 +34,22 @@ export function randomIno(): Ino {
33
34
  return BigInt('0x' + _random() + _random());
34
35
  }
35
36
 
36
- /**
37
- * Offsets for inode members
38
- */
39
- const offsets = {
40
- ino: 0,
41
- size: 8,
42
- mode: 12,
43
- nlink: 14,
44
- uid: 18,
45
- gid: 22,
46
- atime: 26,
47
- birthtime: 34,
48
- mtime: 42,
49
- ctime: 50,
50
- end: 58,
51
- };
52
-
53
- /**
54
- * Offsets for a 64-bit inode's members
55
- * Currently unused
56
- */
57
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
- const offsets_64 = {
59
- ino: 0,
60
- size: 8,
61
- mode: 16,
62
- nlink: 18,
63
- uid: 22,
64
- gid: 26,
65
- atime: 30,
66
- birthtime: 38,
67
- mtime: 46,
68
- ctime: 54,
69
- end: 62,
70
- };
71
-
72
37
  /**
73
38
  * Generic inode definition that can easily be serialized.
74
39
  */
40
+ @struct()
75
41
  export class Inode implements StatsLike {
76
- public readonly buffer: ArrayBufferLike;
77
-
78
42
  public get data(): Uint8Array {
79
- return new Uint8Array(this.buffer);
43
+ return serialize(this);
80
44
  }
81
45
 
82
- protected view: DataView;
83
-
84
46
  public constructor(buffer?: ArrayBufferLike) {
85
- const setDefaults = !buffer;
86
- buffer ??= new ArrayBuffer(offsets.end);
87
- if (buffer?.byteLength < offsets.end) {
88
- throw new RangeError(`Can not create an inode from a buffer less than ${offsets.end} bytes`);
89
- }
90
- this.view = new DataView(buffer);
91
- this.buffer = buffer;
47
+ if (buffer) {
48
+ if (buffer.byteLength < sizeof(Inode)) {
49
+ throw new RangeError(`Can not create an inode from a buffer less than ${sizeof(Inode)} bytes`);
50
+ }
92
51
 
93
- if (!setDefaults) {
52
+ deserialize(this, buffer);
94
53
  return;
95
54
  }
96
55
 
@@ -105,85 +64,16 @@ export class Inode implements StatsLike {
105
64
  this.birthtimeMs = now;
106
65
  }
107
66
 
108
- public get ino(): Ino {
109
- return this.view.getBigUint64(offsets.ino, true);
110
- }
111
-
112
- public set ino(value: Ino) {
113
- this.view.setBigUint64(offsets.ino, value, true);
114
- }
115
-
116
- public get size(): number {
117
- return this.view.getUint32(offsets.size, true);
118
- }
119
-
120
- public set size(value: number) {
121
- this.view.setUint32(offsets.size, value, true);
122
- }
123
-
124
- public get mode(): number {
125
- return this.view.getUint16(offsets.mode, true);
126
- }
127
-
128
- public set mode(value: number) {
129
- this.view.setUint16(offsets.mode, value, true);
130
- }
131
-
132
- public get nlink(): number {
133
- return this.view.getUint32(offsets.nlink, true);
134
- }
135
-
136
- public set nlink(value: number) {
137
- this.view.setUint32(offsets.nlink, value, true);
138
- }
139
-
140
- public get uid(): number {
141
- return this.view.getUint32(offsets.uid, true);
142
- }
143
-
144
- public set uid(value: number) {
145
- this.view.setUint32(offsets.uid, value, true);
146
- }
147
-
148
- public get gid(): number {
149
- return this.view.getUint32(offsets.gid, true);
150
- }
151
-
152
- public set gid(value: number) {
153
- this.view.setUint32(offsets.gid, value, true);
154
- }
155
-
156
- public get atimeMs(): number {
157
- return this.view.getFloat64(offsets.atime, true);
158
- }
159
-
160
- public set atimeMs(value: number) {
161
- this.view.setFloat64(offsets.atime, value, true);
162
- }
163
-
164
- public get birthtimeMs(): number {
165
- return this.view.getFloat64(offsets.birthtime, true);
166
- }
167
-
168
- public set birthtimeMs(value: number) {
169
- this.view.setFloat64(offsets.birthtime, value, true);
170
- }
171
-
172
- public get mtimeMs(): number {
173
- return this.view.getFloat64(offsets.mtime, true);
174
- }
175
-
176
- public set mtimeMs(value: number) {
177
- this.view.setFloat64(offsets.mtime, value, true);
178
- }
179
-
180
- public get ctimeMs(): number {
181
- return this.view.getFloat64(offsets.ctime, true);
182
- }
183
-
184
- public set ctimeMs(value: number) {
185
- this.view.setFloat64(offsets.ctime, value, true);
186
- }
67
+ @t.uint64 public ino!: Ino;
68
+ @t.uint32 public size!: number;
69
+ @t.uint16 public mode!: number;
70
+ @t.uint32 public nlink!: number;
71
+ @t.uint32 public uid!: number;
72
+ @t.uint32 public gid!: number;
73
+ @t.float64 public atimeMs!: number;
74
+ @t.float64 public birthtimeMs!: number;
75
+ @t.float64 public mtimeMs!: number;
76
+ @t.float64 public ctimeMs!: number;
187
77
 
188
78
  /**
189
79
  * Handy function that converts the Inode to a Node Stats object.
@@ -1,4 +1,5 @@
1
1
  export * from './async.js';
2
2
  export * from './mutexed.js';
3
3
  export * from './readonly.js';
4
+ export * from './shared.js';
4
5
  export * from './sync.js';
@@ -14,8 +14,12 @@ export type Mixin<TBase extends typeof FileSystem, TMixin> = (abstract new (...a
14
14
 
15
15
  /**
16
16
  * Asynchronous `FileSystem` methods. This is a convience type.
17
- * @internal
17
+ * @hidden
18
18
  */
19
19
  export type _AsyncFSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<unknown>>;
20
20
 
21
+ /**
22
+ * Concrete `FileSystem`. This is a convience type.
23
+ * @internal
24
+ */
21
25
  export type ConcreteFS = ExtractProperties<FileSystem, any>;