@zenfs/core 1.3.0 → 1.3.2

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/config.js CHANGED
@@ -93,29 +93,28 @@ export async function configure(configuration) {
93
93
  config.checkAccess = !configuration.disableAccessChecks;
94
94
  config.updateOnRead = !configuration.disableUpdateOnRead;
95
95
  config.syncImmediately = !configuration.onlySyncOnClose;
96
+ if (configuration.mounts) {
97
+ const toMount = [];
98
+ let unmountRoot = false;
99
+ for (const [point, mountConfig] of Object.entries(configuration.mounts)) {
100
+ if (!point.startsWith('/')) {
101
+ throw new ErrnoError(Errno.EINVAL, 'Mount points must have absolute paths');
102
+ }
103
+ if (isBackendConfig(mountConfig)) {
104
+ mountConfig.disableAsyncCache ?? (mountConfig.disableAsyncCache = configuration.disableAsyncCache || false);
105
+ }
106
+ if (point == '/')
107
+ unmountRoot = true;
108
+ toMount.push([point, await resolveMountConfig(mountConfig)]);
109
+ }
110
+ if (unmountRoot)
111
+ fs.umount('/');
112
+ await Promise.all(toMount.map(([point, fs]) => mount(point, fs)));
113
+ }
96
114
  if (configuration.addDevices) {
97
115
  const devfs = new DeviceFS();
98
116
  devfs.addDefaults();
99
117
  await devfs.ready();
100
118
  await mount('/dev', devfs);
101
119
  }
102
- if (!configuration.mounts) {
103
- return;
104
- }
105
- const toMount = [];
106
- let unmountRoot = false;
107
- for (const [point, mountConfig] of Object.entries(configuration.mounts)) {
108
- if (!point.startsWith('/')) {
109
- throw new ErrnoError(Errno.EINVAL, 'Mount points must have absolute paths');
110
- }
111
- if (isBackendConfig(mountConfig)) {
112
- mountConfig.disableAsyncCache ?? (mountConfig.disableAsyncCache = configuration.disableAsyncCache || false);
113
- }
114
- if (point == '/')
115
- unmountRoot = true;
116
- toMount.push([point, await resolveMountConfig(mountConfig)]);
117
- }
118
- if (unmountRoot)
119
- fs.umount('/');
120
- await Promise.all(toMount.map(([point, fs]) => mount(point, fs)));
121
120
  }
package/dist/index.d.ts CHANGED
@@ -22,3 +22,10 @@ export * from './emulation/index.js';
22
22
  import * as fs from './emulation/index.js';
23
23
  export { fs };
24
24
  export default fs;
25
+ declare global {
26
+ /**
27
+ * Global FS emulation. Do not use unless absolutely needed.
28
+ * @hidden
29
+ */
30
+ var __zenfs__: typeof fs;
31
+ }
package/dist/index.js CHANGED
@@ -22,3 +22,4 @@ export * from './emulation/index.js';
22
22
  import * as fs from './emulation/index.js';
23
23
  export { fs };
24
24
  export default fs;
25
+ globalThis.__zenfs__ = fs;
package/dist/inode.d.ts CHANGED
@@ -7,6 +7,7 @@ export declare const rootIno = 0n;
7
7
  /**
8
8
  * Generic inode definition that can easily be serialized.
9
9
  * @internal
10
+ * @todo [BREAKING]
10
11
  */
11
12
  export declare class Inode implements StatsLike {
12
13
  constructor(buffer?: ArrayBufferLike | ArrayBufferView);
package/dist/inode.js CHANGED
@@ -47,6 +47,7 @@ export const rootIno = 0n;
47
47
  /**
48
48
  * Generic inode definition that can easily be serialized.
49
49
  * @internal
50
+ * @todo [BREAKING]
50
51
  */
51
52
  let Inode = (() => {
52
53
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
@@ -102,8 +103,23 @@ let Inode = (() => {
102
103
  this.ino = (__runInitializers(this, _ctimeMs_extraInitializers), __runInitializers(this, _ino_initializers, void 0));
103
104
  __runInitializers(this, _ino_extraInitializers);
104
105
  if (buffer) {
105
- if (buffer.byteLength < sizeof(Inode)) {
106
- throw new RangeError(`Can not create an inode from a buffer less than ${sizeof(Inode)} bytes`);
106
+ const sz_inode = sizeof(Inode);
107
+ const oldSize = sz_inode - sizeof('uint64');
108
+ if (buffer.byteLength < oldSize) {
109
+ throw new RangeError(`Can not create an inode from a buffer less than ${oldSize} bytes`);
110
+ }
111
+ // Expand the buffer so it is the right size
112
+ if (buffer.byteLength < sz_inode) {
113
+ const newBuffer = new Uint8Array(sz_inode);
114
+ // Fill the new buffer with current data
115
+ newBuffer.set(new Uint8Array(ArrayBuffer.isView(buffer) ? buffer.buffer : buffer));
116
+ /* Add a random ino.
117
+ This will be different from the actual one,
118
+ but `ino` isn't used anywhere so it should be fine.
119
+ */
120
+ const randomIno = crypto.getRandomValues(new Uint32Array(2));
121
+ newBuffer.set(randomIno, sz_inode - 2);
122
+ buffer = newBuffer;
107
123
  }
108
124
  deserialize(this, buffer);
109
125
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "A filesystem, anywhere",
5
5
  "funding": {
6
6
  "type": "individual",
package/src/config.ts CHANGED
@@ -196,34 +196,32 @@ export async function configure<T extends ConfigMounts>(configuration: Partial<C
196
196
  config.updateOnRead = !configuration.disableUpdateOnRead;
197
197
  config.syncImmediately = !configuration.onlySyncOnClose;
198
198
 
199
- if (configuration.addDevices) {
200
- const devfs = new DeviceFS();
201
- devfs.addDefaults();
202
- await devfs.ready();
203
- await mount('/dev', devfs);
204
- }
199
+ if (configuration.mounts) {
200
+ const toMount: [string, FileSystem][] = [];
201
+ let unmountRoot = false;
205
202
 
206
- if (!configuration.mounts) {
207
- return;
208
- }
203
+ for (const [point, mountConfig] of Object.entries(configuration.mounts)) {
204
+ if (!point.startsWith('/')) {
205
+ throw new ErrnoError(Errno.EINVAL, 'Mount points must have absolute paths');
206
+ }
209
207
 
210
- const toMount: [string, FileSystem][] = [];
211
- let unmountRoot = false;
208
+ if (isBackendConfig(mountConfig)) {
209
+ mountConfig.disableAsyncCache ??= configuration.disableAsyncCache || false;
210
+ }
212
211
 
213
- for (const [point, mountConfig] of Object.entries(configuration.mounts)) {
214
- if (!point.startsWith('/')) {
215
- throw new ErrnoError(Errno.EINVAL, 'Mount points must have absolute paths');
212
+ if (point == '/') unmountRoot = true;
213
+ toMount.push([point, await resolveMountConfig(mountConfig)]);
216
214
  }
217
215
 
218
- if (isBackendConfig(mountConfig)) {
219
- mountConfig.disableAsyncCache ??= configuration.disableAsyncCache || false;
220
- }
216
+ if (unmountRoot) fs.umount('/');
221
217
 
222
- if (point == '/') unmountRoot = true;
223
- toMount.push([point, await resolveMountConfig(mountConfig)]);
218
+ await Promise.all(toMount.map(([point, fs]) => mount(point, fs)));
224
219
  }
225
220
 
226
- if (unmountRoot) fs.umount('/');
227
-
228
- await Promise.all(toMount.map(([point, fs]) => mount(point, fs)));
221
+ if (configuration.addDevices) {
222
+ const devfs = new DeviceFS();
223
+ devfs.addDefaults();
224
+ await devfs.ready();
225
+ await mount('/dev', devfs);
226
+ }
229
227
  }
package/src/index.ts CHANGED
@@ -23,3 +23,13 @@ export * from './emulation/index.js';
23
23
  import * as fs from './emulation/index.js';
24
24
  export { fs };
25
25
  export default fs;
26
+
27
+ declare global {
28
+ /**
29
+ * Global FS emulation. Do not use unless absolutely needed.
30
+ * @hidden
31
+ */
32
+ // eslint-disable-next-line no-var
33
+ var __zenfs__: typeof fs;
34
+ }
35
+ globalThis.__zenfs__ = fs;
package/src/inode.ts CHANGED
@@ -11,13 +11,30 @@ export const rootIno = 0n;
11
11
  /**
12
12
  * Generic inode definition that can easily be serialized.
13
13
  * @internal
14
+ * @todo [BREAKING]
14
15
  */
15
16
  @struct()
16
17
  export class Inode implements StatsLike {
17
18
  public constructor(buffer?: ArrayBufferLike | ArrayBufferView) {
18
19
  if (buffer) {
19
- if (buffer.byteLength < sizeof(Inode)) {
20
- throw new RangeError(`Can not create an inode from a buffer less than ${sizeof(Inode)} bytes`);
20
+ const sz_inode = sizeof(Inode);
21
+ const oldSize = sz_inode - sizeof('uint64');
22
+ if (buffer.byteLength < oldSize) {
23
+ throw new RangeError(`Can not create an inode from a buffer less than ${oldSize} bytes`);
24
+ }
25
+
26
+ // Expand the buffer so it is the right size
27
+ if (buffer.byteLength < sz_inode) {
28
+ const newBuffer = new Uint8Array(sz_inode);
29
+ // Fill the new buffer with current data
30
+ newBuffer.set(new Uint8Array(ArrayBuffer.isView(buffer) ? buffer.buffer : buffer));
31
+ /* Add a random ino.
32
+ This will be different from the actual one,
33
+ but `ino` isn't used anywhere so it should be fine.
34
+ */
35
+ const randomIno = crypto.getRandomValues(new Uint32Array(2));
36
+ newBuffer.set(randomIno, sz_inode - 2);
37
+ buffer = newBuffer;
21
38
  }
22
39
 
23
40
  deserialize(this, buffer);