@zenfs/core 2.2.2 → 2.3.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.
Files changed (60) hide show
  1. package/dist/backends/backend.js +6 -9
  2. package/dist/backends/cow.js +4 -4
  3. package/dist/backends/fetch.js +8 -6
  4. package/dist/backends/memory.js +4 -2
  5. package/dist/backends/passthrough.js +2 -0
  6. package/dist/backends/port.d.ts +16 -89
  7. package/dist/backends/port.js +35 -171
  8. package/dist/backends/single_buffer.d.ts +4 -2
  9. package/dist/backends/single_buffer.js +169 -195
  10. package/dist/backends/store/fs.js +50 -73
  11. package/dist/backends/store/map.js +1 -2
  12. package/dist/backends/store/store.js +23 -27
  13. package/dist/config.js +2 -3
  14. package/dist/context.js +2 -2
  15. package/dist/internal/credentials.d.ts +6 -0
  16. package/dist/internal/credentials.js +10 -0
  17. package/dist/internal/devices.js +7 -10
  18. package/dist/internal/file_index.js +3 -8
  19. package/dist/internal/filesystem.js +19 -12
  20. package/dist/internal/index_fs.js +3 -4
  21. package/dist/internal/inode.d.ts +2 -0
  22. package/dist/internal/inode.js +148 -185
  23. package/dist/internal/rpc.d.ts +143 -0
  24. package/dist/internal/rpc.js +251 -0
  25. package/dist/mixins/async.js +5 -6
  26. package/dist/mixins/mutexed.js +16 -10
  27. package/dist/path.js +3 -4
  28. package/dist/polyfills.js +51 -22
  29. package/dist/readline.js +32 -30
  30. package/dist/utils.d.ts +3 -2
  31. package/dist/utils.js +11 -5
  32. package/dist/vfs/acl.d.ts +2 -0
  33. package/dist/vfs/acl.js +48 -66
  34. package/dist/vfs/async.js +4 -4
  35. package/dist/vfs/dir.d.ts +4 -3
  36. package/dist/vfs/dir.js +16 -10
  37. package/dist/vfs/file.js +22 -18
  38. package/dist/vfs/ioctl.js +39 -62
  39. package/dist/vfs/promises.d.ts +33 -25
  40. package/dist/vfs/promises.js +56 -47
  41. package/dist/vfs/shared.js +7 -7
  42. package/dist/vfs/stats.js +104 -77
  43. package/dist/vfs/streams.js +11 -8
  44. package/dist/vfs/sync.d.ts +22 -11
  45. package/dist/vfs/sync.js +24 -27
  46. package/dist/vfs/types.d.ts +3 -8
  47. package/dist/vfs/watchers.js +9 -3
  48. package/dist/vfs/xattr.js +6 -12
  49. package/package.json +2 -2
  50. package/scripts/test.js +14 -7
  51. package/tests/backend/fetch.test.ts +14 -14
  52. package/tests/backend/port.test.ts +25 -17
  53. package/tests/common/context.test.ts +14 -0
  54. package/tests/common/handle.test.ts +5 -3
  55. package/tests/fetch/run.sh +2 -1
  56. package/tests/fs/scaling.test.ts +32 -0
  57. package/tests/fs/watch.test.ts +2 -5
  58. package/tests/setup/single-buffer.ts +1 -1
  59. package/tests/tsconfig.json +3 -2
  60. package/types/uint8array.d.ts +64 -0
package/dist/readline.js CHANGED
@@ -3,55 +3,57 @@
3
3
  import { EventEmitter } from 'eventemitter3';
4
4
  import { warn } from 'kerium/log';
5
5
  export class Interface extends EventEmitter {
6
+ input;
7
+ output;
8
+ terminal;
9
+ line = '';
10
+ _cursor = 0;
6
11
  get cursor() {
7
12
  return this._cursor;
8
13
  }
14
+ _buffer = '';
15
+ _closed = false;
16
+ _paused = false;
17
+ _prompt = '';
18
+ _history = [];
19
+ _historyIndex = -1;
20
+ _currentLine = '';
9
21
  constructor(input, output, completer, terminal = false) {
10
22
  super();
11
23
  this.input = input;
12
24
  this.output = output;
13
25
  this.terminal = terminal;
14
- this.line = '';
15
- this._cursor = 0;
16
- this._buffer = '';
17
- this._closed = false;
18
- this._paused = false;
19
- this._prompt = '';
20
- this._history = [];
21
- this._historyIndex = -1;
22
- this._currentLine = '';
23
- this._onData = (data) => {
24
- if (this._paused || this._closed)
25
- return;
26
- this._buffer += typeof data === 'string' ? data : data.toString('utf8');
27
- for (let lineEnd = this._buffer.indexOf('\n'); lineEnd >= 0; lineEnd = this._buffer.indexOf('\n')) {
28
- let line = this._buffer.substring(0, lineEnd);
29
- if (line.endsWith('\r')) {
30
- line = line.substring(0, line.length - 1);
31
- }
32
- this._buffer = this._buffer.substring(lineEnd + 1);
33
- this.line = line;
34
- if (line.trim() && !line.trim().match(/^\s*$/) && this._history.at(-1) != line) {
35
- this._history.push(line);
36
- this._historyIndex = this._history.length;
37
- this.emit('history', this._history);
38
- }
39
- this.emit('line', line);
40
- }
41
- };
42
26
  this.input.on('data', this._onData);
43
27
  this.input.on('end', this.close.bind(this));
44
28
  this.input.on('close', this.close.bind(this));
45
29
  }
30
+ _onData = (data) => {
31
+ if (this._paused || this._closed)
32
+ return;
33
+ this._buffer += typeof data === 'string' ? data : data.toString('utf8');
34
+ for (let lineEnd = this._buffer.indexOf('\n'); lineEnd >= 0; lineEnd = this._buffer.indexOf('\n')) {
35
+ let line = this._buffer.substring(0, lineEnd);
36
+ if (line.endsWith('\r')) {
37
+ line = line.substring(0, line.length - 1);
38
+ }
39
+ this._buffer = this._buffer.substring(lineEnd + 1);
40
+ this.line = line;
41
+ if (line.trim() && !line.trim().match(/^\s*$/) && this._history.at(-1) != line) {
42
+ this._history.push(line);
43
+ this._historyIndex = this._history.length;
44
+ this.emit('history', this._history);
45
+ }
46
+ this.emit('line', line);
47
+ }
48
+ };
46
49
  /**
47
50
  * Closes the interface and removes all event listeners
48
51
  */
49
52
  close() {
50
- var _a, _b;
51
53
  if (this._closed)
52
54
  return;
53
55
  this._closed = true;
54
- (_b = (_a = this.input) === null || _a === void 0 ? void 0 : _a.removeAllListeners) === null || _b === void 0 ? void 0 : _b.call(_a);
56
+ this.input?.removeAllListeners?.();
55
57
  if (this._buffer.length) {
56
58
  const line = this._buffer;
57
59
  this._buffer = '';
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type Exception } from 'kerium';
2
2
  import type * as fs from 'node:fs';
3
+ import type { Worker as NodeWorker } from 'node:worker_threads';
3
4
  import { type OptionalTuple } from 'utilium';
4
5
  declare global {
5
6
  function atob(data: string): string;
@@ -48,8 +49,7 @@ export declare function normalizePath(p: fs.PathLike, noResolve?: boolean): stri
48
49
  */
49
50
  export declare function normalizeOptions(options: fs.WriteFileOptions | (fs.EncodingOption & {
50
51
  flag?: fs.OpenMode;
51
- }) | undefined, encoding: (BufferEncoding | null) | undefined, flag: string, mode?: number): {
52
- encoding?: BufferEncoding | null;
52
+ }) | undefined, encoding: (BufferEncoding | null) | undefined, flag: string, mode?: number): fs.ObjectEncodingOptions & {
53
53
  flag: string;
54
54
  mode: number;
55
55
  };
@@ -58,3 +58,4 @@ export declare function normalizeOptions(options: fs.WriteFileOptions | (fs.Enco
58
58
  * @internal
59
59
  */
60
60
  export declare function globToRegex(pattern: string): RegExp;
61
+ export declare function waitOnline(worker: NodeWorker): Promise<void>;
package/dist/utils.js CHANGED
@@ -31,7 +31,7 @@ export function normalizeMode(mode, def) {
31
31
  }
32
32
  if (typeof def == 'number')
33
33
  return def;
34
- throw withErrno('EINVAL', 'Invalid mode: ' + (mode === null || mode === void 0 ? void 0 : mode.toString()));
34
+ throw withErrno('EINVAL', 'Invalid mode: ' + mode?.toString());
35
35
  }
36
36
  /**
37
37
  * Normalizes a time
@@ -85,15 +85,15 @@ export function normalizePath(p, noResolve = false) {
85
85
  export function normalizeOptions(options, encoding = 'utf8', flag, mode = 0) {
86
86
  if (typeof options != 'object' || options === null) {
87
87
  return {
88
- encoding: typeof options == 'string' ? options : (encoding !== null && encoding !== void 0 ? encoding : null),
88
+ encoding: typeof options == 'string' ? options : (encoding ?? null),
89
89
  flag,
90
90
  mode,
91
91
  };
92
92
  }
93
93
  return {
94
- encoding: typeof (options === null || options === void 0 ? void 0 : options.encoding) == 'string' ? options.encoding : (encoding !== null && encoding !== void 0 ? encoding : null),
95
- flag: typeof (options === null || options === void 0 ? void 0 : options.flag) == 'string' ? options.flag : flag,
96
- mode: normalizeMode('mode' in options ? options === null || options === void 0 ? void 0 : options.mode : null, mode),
94
+ encoding: typeof options?.encoding == 'string' ? options.encoding : (encoding ?? null),
95
+ flag: typeof options?.flag == 'string' ? options.flag : flag,
96
+ mode: normalizeMode('mode' in options ? options?.mode : null, mode),
97
97
  };
98
98
  }
99
99
  /**
@@ -108,3 +108,9 @@ export function globToRegex(pattern) {
108
108
  .replace(/\?/g, '.');
109
109
  return new RegExp(`^${pattern}$`);
110
110
  }
111
+ export async function waitOnline(worker) {
112
+ const online = Promise.withResolvers();
113
+ setTimeout(() => online.reject(withErrno('ETIMEDOUT')), 500);
114
+ worker.on('online', online.resolve);
115
+ await online.promise;
116
+ }
package/dist/vfs/acl.d.ts CHANGED
@@ -18,11 +18,13 @@ export declare const enum Tag {
18
18
  _None = 0
19
19
  }
20
20
  export declare class Entry extends BufferView {
21
+ static readonly name = "Entry";
21
22
  accessor tag: Tag;
22
23
  accessor perm: number;
23
24
  accessor id: number;
24
25
  }
25
26
  export declare class ACL extends BufferView {
27
+ static readonly name = "ACL";
26
28
  accessor version: number;
27
29
  entries: Entry[];
28
30
  constructor(...args: ConstructorParameters<typeof BufferView>);
package/dist/vfs/acl.js CHANGED
@@ -32,21 +32,6 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
32
32
  }
33
33
  return useValue ? value : void 0;
34
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
- };
39
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
40
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
41
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
42
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
43
- };
44
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
45
- if (kind === "m") throw new TypeError("Private method is not writable");
46
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
47
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
48
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
49
- };
50
35
  /*
51
36
  Access Control Lists.
52
37
  At the moment, they are only intended for internal use.
@@ -81,7 +66,6 @@ export var Tag;
81
66
  Tag[Tag["_None"] = 0] = "_None";
82
67
  })(Tag || (Tag = {}));
83
68
  let Entry = (() => {
84
- var _Entry_tag_accessor_storage, _Entry_perm_accessor_storage, _Entry_id_accessor_storage;
85
69
  var _a, _b, _c;
86
70
  let _classDecorators = [struct(packed)];
87
71
  let _classDescriptor;
@@ -97,44 +81,42 @@ let Entry = (() => {
97
81
  let _id_decorators;
98
82
  let _id_initializers = [];
99
83
  let _id_extraInitializers = [];
100
- var Entry = _classThis = class extends _classSuper {
101
- get tag() { return __classPrivateFieldGet(this, _Entry_tag_accessor_storage, "f"); }
102
- set tag(value) { __classPrivateFieldSet(this, _Entry_tag_accessor_storage, value, "f"); }
103
- get perm() { return __classPrivateFieldGet(this, _Entry_perm_accessor_storage, "f"); }
104
- set perm(value) { __classPrivateFieldSet(this, _Entry_perm_accessor_storage, value, "f"); }
105
- get id() { return __classPrivateFieldGet(this, _Entry_id_accessor_storage, "f"); }
106
- set id(value) { __classPrivateFieldSet(this, _Entry_id_accessor_storage, value, "f"); }
84
+ var Entry = class extends _classSuper {
85
+ static { _classThis = this; }
86
+ static {
87
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
88
+ _tag_decorators = [(_a = t).uint16.bind(_a)];
89
+ _perm_decorators = [(_b = t).uint16.bind(_b)];
90
+ _id_decorators = [(_c = t).uint32.bind(_c)];
91
+ __esDecorate(this, null, _tag_decorators, { kind: "accessor", name: "tag", static: false, private: false, access: { has: obj => "tag" in obj, get: obj => obj.tag, set: (obj, value) => { obj.tag = value; } }, metadata: _metadata }, _tag_initializers, _tag_extraInitializers);
92
+ __esDecorate(this, null, _perm_decorators, { kind: "accessor", name: "perm", static: false, private: false, access: { has: obj => "perm" in obj, get: obj => obj.perm, set: (obj, value) => { obj.perm = value; } }, metadata: _metadata }, _perm_initializers, _perm_extraInitializers);
93
+ __esDecorate(this, null, _id_decorators, { kind: "accessor", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
94
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
95
+ Entry = _classThis = _classDescriptor.value;
96
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
97
+ }
98
+ static name = 'Entry';
99
+ #tag_accessor_storage = __runInitializers(this, _tag_initializers, void 0);
100
+ get tag() { return this.#tag_accessor_storage; }
101
+ set tag(value) { this.#tag_accessor_storage = value; }
102
+ #perm_accessor_storage = (__runInitializers(this, _tag_extraInitializers), __runInitializers(this, _perm_initializers, void 0));
103
+ get perm() { return this.#perm_accessor_storage; }
104
+ set perm(value) { this.#perm_accessor_storage = value; }
105
+ #id_accessor_storage = (__runInitializers(this, _perm_extraInitializers), __runInitializers(this, _id_initializers, void 0));
106
+ get id() { return this.#id_accessor_storage; }
107
+ set id(value) { this.#id_accessor_storage = value; }
107
108
  constructor() {
108
109
  super(...arguments);
109
- _Entry_tag_accessor_storage.set(this, __runInitializers(this, _tag_initializers, void 0));
110
- _Entry_perm_accessor_storage.set(this, (__runInitializers(this, _tag_extraInitializers), __runInitializers(this, _perm_initializers, void 0)));
111
- _Entry_id_accessor_storage.set(this, (__runInitializers(this, _perm_extraInitializers), __runInitializers(this, _id_initializers, void 0)));
112
110
  __runInitializers(this, _id_extraInitializers);
113
111
  }
112
+ static {
113
+ __runInitializers(_classThis, _classExtraInitializers);
114
+ }
114
115
  };
115
- _Entry_tag_accessor_storage = new WeakMap();
116
- _Entry_perm_accessor_storage = new WeakMap();
117
- _Entry_id_accessor_storage = new WeakMap();
118
- __setFunctionName(_classThis, "Entry");
119
- (() => {
120
- var _a;
121
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
122
- _tag_decorators = [(_a = t).uint16.bind(_a)];
123
- _perm_decorators = [(_b = t).uint16.bind(_b)];
124
- _id_decorators = [(_c = t).uint32.bind(_c)];
125
- __esDecorate(_classThis, null, _tag_decorators, { kind: "accessor", name: "tag", static: false, private: false, access: { has: obj => "tag" in obj, get: obj => obj.tag, set: (obj, value) => { obj.tag = value; } }, metadata: _metadata }, _tag_initializers, _tag_extraInitializers);
126
- __esDecorate(_classThis, null, _perm_decorators, { kind: "accessor", name: "perm", static: false, private: false, access: { has: obj => "perm" in obj, get: obj => obj.perm, set: (obj, value) => { obj.perm = value; } }, metadata: _metadata }, _perm_initializers, _perm_extraInitializers);
127
- __esDecorate(_classThis, null, _id_decorators, { kind: "accessor", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
128
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
129
- Entry = _classThis = _classDescriptor.value;
130
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
131
- __runInitializers(_classThis, _classExtraInitializers);
132
- })();
133
116
  return Entry = _classThis;
134
117
  })();
135
118
  export { Entry };
136
119
  let ACL = (() => {
137
- var _ACL_version_accessor_storage;
138
120
  var _a;
139
121
  let _classDecorators = [struct(packed)];
140
122
  let _classDescriptor;
@@ -144,14 +126,24 @@ let ACL = (() => {
144
126
  let _version_decorators;
145
127
  let _version_initializers = [];
146
128
  let _version_extraInitializers = [];
147
- var ACL = _classThis = class extends _classSuper {
148
- get version() { return __classPrivateFieldGet(this, _ACL_version_accessor_storage, "f"); }
149
- set version(value) { __classPrivateFieldSet(this, _ACL_version_accessor_storage, value, "f"); }
129
+ var ACL = class extends _classSuper {
130
+ static { _classThis = this; }
131
+ static {
132
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
133
+ _version_decorators = [(_a = t).uint32.bind(_a)];
134
+ __esDecorate(this, null, _version_decorators, { kind: "accessor", name: "version", static: false, private: false, access: { has: obj => "version" in obj, get: obj => obj.version, set: (obj, value) => { obj.version = value; } }, metadata: _metadata }, _version_initializers, _version_extraInitializers);
135
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
136
+ ACL = _classThis = _classDescriptor.value;
137
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
138
+ }
139
+ static name = 'ACL';
140
+ #version_accessor_storage = __runInitializers(this, _version_initializers, void 0);
141
+ get version() { return this.#version_accessor_storage; }
142
+ set version(value) { this.#version_accessor_storage = value; }
143
+ entries = (__runInitializers(this, _version_extraInitializers), []);
150
144
  constructor(...args) {
151
145
  super(...args);
152
- _ACL_version_accessor_storage.set(this, __runInitializers(this, _version_initializers, void 0));
153
- this.entries = (__runInitializers(this, _version_extraInitializers), []);
154
- this.version || (this.version = version);
146
+ this.version ||= version;
155
147
  if (this.version != version)
156
148
  throw err(withErrno('EINVAL', 'Invalid ACL version'));
157
149
  for (let offset = sizeof(ACL); offset < this.byteLength; offset += sizeof(Entry)) {
@@ -160,19 +152,10 @@ let ACL = (() => {
160
152
  this.entries.push(new Entry(this.buffer, offset));
161
153
  }
162
154
  }
155
+ static {
156
+ __runInitializers(_classThis, _classExtraInitializers);
157
+ }
163
158
  };
164
- _ACL_version_accessor_storage = new WeakMap();
165
- __setFunctionName(_classThis, "ACL");
166
- (() => {
167
- var _a;
168
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
169
- _version_decorators = [(_a = t).uint32.bind(_a)];
170
- __esDecorate(_classThis, null, _version_decorators, { kind: "accessor", name: "version", static: false, private: false, access: { has: obj => "version" in obj, get: obj => obj.version, set: (obj, value) => { obj.version = value; } }, metadata: _metadata }, _version_initializers, _version_extraInitializers);
171
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
172
- ACL = _classThis = _classDescriptor.value;
173
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
174
- __runInitializers(_classThis, _classExtraInitializers);
175
- })();
176
159
  return ACL = _classThis;
177
160
  })();
178
161
  export { ACL };
@@ -224,11 +207,10 @@ export function setChecks(enabled) {
224
207
  * @param access The requested access, combination of `W_OK`, `R_OK`, and `X_OK`
225
208
  */
226
209
  export function check($, inode, access) {
227
- var _a, _b;
228
210
  if (!shouldCheck)
229
211
  return true;
230
- (_a = inode.attributes) !== null && _a !== void 0 ? _a : (inode.attributes = new Attributes());
231
- const { euid, egid } = (_b = $ === null || $ === void 0 ? void 0 : $.credentials) !== null && _b !== void 0 ? _b : defaultContext.credentials;
212
+ inode.attributes ??= new Attributes();
213
+ const { euid, egid } = $?.credentials ?? defaultContext.credentials;
232
214
  const data = inode.attributes.get('system.posix_acl_access');
233
215
  if (!data)
234
216
  return true;
package/dist/vfs/async.js CHANGED
@@ -109,7 +109,7 @@ export function fstat(fd, options, cb = nop) {
109
109
  cb = typeof options == 'function' ? options : cb;
110
110
  new promises.FileHandle(this, fd)
111
111
  .stat()
112
- .then(stats => cb(undefined, typeof options == 'object' && (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : stats))
112
+ .then(stats => cb(undefined, typeof options == 'object' && options?.bigint ? new BigIntStats(stats) : stats))
113
113
  .catch(cb);
114
114
  }
115
115
  fstat;
@@ -420,7 +420,7 @@ watch;
420
420
  */
421
421
  export function createReadStream(path, options) {
422
422
  options = typeof options == 'object' ? options : { encoding: options };
423
- const _handle = promises.open.call(this, path, 'r', options === null || options === void 0 ? void 0 : options.mode);
423
+ const _handle = promises.open.call(this, path, 'r', options?.mode);
424
424
  return new ReadStream({ ...options, autoClose: true }, _handle);
425
425
  }
426
426
  createReadStream;
@@ -433,7 +433,7 @@ createReadStream;
433
433
  */
434
434
  export function createWriteStream(path, options) {
435
435
  options = typeof options == 'object' ? options : { encoding: options };
436
- const _handle = promises.open.call(this, path, 'w', options === null || options === void 0 ? void 0 : options.mode);
436
+ const _handle = promises.open.call(this, path, 'w', options?.mode);
437
437
  return new WriteStream(options, _handle);
438
438
  }
439
439
  createWriteStream;
@@ -512,7 +512,7 @@ export function glob(pattern, options, callback = nop) {
512
512
  callback = typeof options == 'function' ? options : callback;
513
513
  const it = promises.glob.call(this, pattern, typeof options === 'function' ? undefined : options);
514
514
  collectAsyncIterator(it)
515
- .then(results => { var _a; return callback(null, (_a = results) !== null && _a !== void 0 ? _a : []); })
515
+ .then(results => callback(null, results ?? []))
516
516
  .catch((e) => callback(e));
517
517
  }
518
518
  glob;
package/dist/vfs/dir.d.ts CHANGED
@@ -2,11 +2,12 @@ import type { Dir as _Dir, Dirent as _Dirent } from 'node:fs';
2
2
  import type { V_Context } from '../context.js';
3
3
  import type { InodeLike } from '../internal/inode.js';
4
4
  import type { Callback } from '../utils.js';
5
- export declare class Dirent implements _Dirent {
5
+ export declare class Dirent<Name extends string | Buffer = string> implements _Dirent<Name> {
6
6
  path: string;
7
7
  protected stats: InodeLike;
8
- get name(): string;
9
- constructor(path: string, stats: InodeLike);
8
+ protected readonly encoding?: (BufferEncoding | "buffer" | null) | undefined;
9
+ get name(): Name;
10
+ constructor(path: string, stats: InodeLike, encoding?: (BufferEncoding | "buffer" | null) | undefined);
10
11
  get parentPath(): string;
11
12
  isFile(): boolean;
12
13
  isDirectory(): boolean;
package/dist/vfs/dir.js CHANGED
@@ -4,12 +4,17 @@ import { basename } from '../path.js';
4
4
  import { readdir } from './promises.js';
5
5
  import { readdirSync } from './sync.js';
6
6
  export class Dirent {
7
+ path;
8
+ stats;
9
+ encoding;
7
10
  get name() {
8
- return basename(this.path);
11
+ const name = Buffer.from(basename(this.path));
12
+ return (this.encoding == 'buffer' ? name : name.toString(this.encoding));
9
13
  }
10
- constructor(path, stats) {
14
+ constructor(path, stats, encoding) {
11
15
  this.path = path;
12
16
  this.stats = stats;
17
+ this.encoding = encoding;
13
18
  }
14
19
  get parentPath() {
15
20
  return this.path;
@@ -40,14 +45,17 @@ export class Dirent {
40
45
  * A class representing a directory stream.
41
46
  */
42
47
  export class Dir {
48
+ path;
49
+ context;
50
+ closed = false;
43
51
  checkClosed() {
44
52
  if (this.closed)
45
53
  throw withErrno('EBADF', 'Can not use closed Dir');
46
54
  }
55
+ _entries;
47
56
  constructor(path, context) {
48
57
  this.path = path;
49
58
  this.context = context;
50
- this.closed = false;
51
59
  }
52
60
  close(cb) {
53
61
  this.closed = true;
@@ -64,14 +72,13 @@ export class Dir {
64
72
  this.closed = true;
65
73
  }
66
74
  async _read() {
67
- var _a, _b;
68
75
  this.checkClosed();
69
- (_a = this._entries) !== null && _a !== void 0 ? _a : (this._entries = await readdir.call(this.context, this.path, {
76
+ this._entries ??= await readdir.call(this.context, this.path, {
70
77
  withFileTypes: true,
71
- }));
78
+ });
72
79
  if (!this._entries.length)
73
80
  return null;
74
- return (_b = this._entries.shift()) !== null && _b !== void 0 ? _b : null;
81
+ return this._entries.shift() ?? null;
75
82
  }
76
83
  read(cb) {
77
84
  if (!cb) {
@@ -85,12 +92,11 @@ export class Dir {
85
92
  * Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
86
93
  */
87
94
  readSync() {
88
- var _a, _b;
89
95
  this.checkClosed();
90
- (_a = this._entries) !== null && _a !== void 0 ? _a : (this._entries = readdirSync.call(this.context, this.path, { withFileTypes: true }));
96
+ this._entries ??= readdirSync.call(this.context, this.path, { withFileTypes: true });
91
97
  if (!this._entries.length)
92
98
  return null;
93
- return (_b = this._entries.shift()) !== null && _b !== void 0 ? _b : null;
99
+ return this._entries.shift() ?? null;
94
100
  }
95
101
  async next() {
96
102
  const value = await this._read();
package/dist/vfs/file.js CHANGED
@@ -8,6 +8,17 @@ import { _chown } from './stats.js';
8
8
  * @internal
9
9
  */
10
10
  export class SyncHandle {
11
+ context;
12
+ path;
13
+ fs;
14
+ internalPath;
15
+ flag;
16
+ inode;
17
+ _buffer;
18
+ /**
19
+ * Current position
20
+ */
21
+ _position = 0;
11
22
  /**
12
23
  * Get the current file position.
13
24
  *
@@ -23,6 +34,14 @@ export class SyncHandle {
23
34
  set position(value) {
24
35
  this._position = value;
25
36
  }
37
+ /**
38
+ * Whether the file has changes which have not been written to the FS
39
+ */
40
+ dirty = false;
41
+ /**
42
+ * Whether the file is open or closed
43
+ */
44
+ closed = false;
26
45
  /**
27
46
  * Creates a file with `path` and, optionally, the given contents.
28
47
  * Note that, if contents is specified, it will be mutated by the file.
@@ -34,18 +53,6 @@ export class SyncHandle {
34
53
  this.internalPath = internalPath;
35
54
  this.flag = flag;
36
55
  this.inode = inode;
37
- /**
38
- * Current position
39
- */
40
- this._position = 0;
41
- /**
42
- * Whether the file has changes which have not been written to the FS
43
- */
44
- this.dirty = false;
45
- /**
46
- * Whether the file is open or closed
47
- */
48
- this.closed = false;
49
56
  }
50
57
  [Symbol.dispose]() {
51
58
  this.close();
@@ -221,8 +228,7 @@ export class SyncHandle {
221
228
  * @internal @hidden
222
229
  */
223
230
  export function toFD(file) {
224
- var _a, _b;
225
- const map = (_b = (_a = file.context) === null || _a === void 0 ? void 0 : _a.descriptors) !== null && _b !== void 0 ? _b : defaultContext.descriptors;
231
+ const map = file.context?.descriptors ?? defaultContext.descriptors;
226
232
  const fd = Math.max(map.size ? Math.max(...map.keys()) + 1 : 0, 4);
227
233
  map.set(fd, file);
228
234
  return fd;
@@ -231,14 +237,12 @@ export function toFD(file) {
231
237
  * @internal @hidden
232
238
  */
233
239
  export function fromFD($, fd) {
234
- var _a;
235
- const map = (_a = $ === null || $ === void 0 ? void 0 : $.descriptors) !== null && _a !== void 0 ? _a : defaultContext.descriptors;
240
+ const map = $?.descriptors ?? defaultContext.descriptors;
236
241
  const value = map.get(fd);
237
242
  if (!value)
238
243
  throw withErrno('EBADF');
239
244
  return value;
240
245
  }
241
246
  export function deleteFD($, fd) {
242
- var _a;
243
- return ((_a = $ === null || $ === void 0 ? void 0 : $.descriptors) !== null && _a !== void 0 ? _a : defaultContext.descriptors).delete(fd);
247
+ return ($?.descriptors ?? defaultContext.descriptors).delete(fd);
244
248
  }