@zenfs/core 1.0.2 → 1.0.4
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/file_index.d.ts +1 -1
- package/dist/backends/port/fs.d.ts +1 -1
- package/dist/backends/port/rpc.js +1 -1
- package/dist/browser.min.js +5 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/inode.d.ts +10 -22
- package/dist/inode.js +188 -168
- package/dist/mixins/index.d.ts +1 -0
- package/dist/mixins/index.js +1 -0
- package/dist/mixins/shared.d.ts +5 -1
- package/eslint.shared.js +0 -4
- package/package.json +2 -3
- package/scripts/build.js +27 -24
- package/src/backends/port/rpc.ts +1 -1
- package/src/inode.ts +18 -128
- package/src/mixins/index.ts +1 -0
- package/src/mixins/shared.ts +5 -1
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
|
|
43
|
+
return serialize(this);
|
|
80
44
|
}
|
|
81
45
|
|
|
82
|
-
protected view: DataView;
|
|
83
|
-
|
|
84
46
|
public constructor(buffer?: ArrayBufferLike) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
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
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
public
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
public
|
|
117
|
-
|
|
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.
|
package/src/mixins/index.ts
CHANGED
package/src/mixins/shared.ts
CHANGED
|
@@ -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
|
-
* @
|
|
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>;
|