@zenfs/core 1.8.7 → 1.8.8

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.
@@ -66,21 +66,21 @@ import { join } from '../vfs/path.js';
66
66
  */
67
67
  export function Async(FS) {
68
68
  class AsyncFS extends FS {
69
- get _queueRunning() {
70
- return !!this._queue.length;
69
+ async done() {
70
+ await this._promise;
71
71
  }
72
72
  queueDone() {
73
- return new Promise(resolve => {
74
- const check = () => (this._queueRunning ? setTimeout(check) : resolve());
75
- check();
76
- });
73
+ return this.done();
74
+ }
75
+ _async(promise) {
76
+ if (!this._promise) {
77
+ this._promise = promise;
78
+ return;
79
+ }
80
+ this._promise = this._promise.then(() => promise);
77
81
  }
78
82
  constructor(...args) {
79
83
  super(...args);
80
- /**
81
- * Queue of pending asynchronous operations.
82
- */
83
- this._queue = [];
84
84
  this._isInitialized = false;
85
85
  this._patchAsync();
86
86
  }
@@ -124,7 +124,7 @@ export function Async(FS) {
124
124
  renameSync(oldPath, newPath) {
125
125
  this.checkSync(oldPath, 'rename');
126
126
  this._sync.renameSync(oldPath, newPath);
127
- this.queue('rename', oldPath, newPath);
127
+ this._async(this.rename(oldPath, newPath));
128
128
  }
129
129
  statSync(path) {
130
130
  this.checkSync(path, 'stat');
@@ -133,7 +133,7 @@ export function Async(FS) {
133
133
  createFileSync(path, flag, mode, options) {
134
134
  this.checkSync(path, 'createFile');
135
135
  this._sync.createFileSync(path, flag, mode, options);
136
- this.queue('createFile', path, flag, mode, options);
136
+ this._async(this.createFile(path, flag, mode, options));
137
137
  return this.openFileSync(path, flag);
138
138
  }
139
139
  openFileSync(path, flag) {
@@ -144,17 +144,17 @@ export function Async(FS) {
144
144
  unlinkSync(path) {
145
145
  this.checkSync(path, 'unlinkSync');
146
146
  this._sync.unlinkSync(path);
147
- this.queue('unlink', path);
147
+ this._async(this.unlink(path));
148
148
  }
149
149
  rmdirSync(path) {
150
150
  this.checkSync(path, 'rmdir');
151
151
  this._sync.rmdirSync(path);
152
- this.queue('rmdir', path);
152
+ this._async(this.rmdir(path));
153
153
  }
154
154
  mkdirSync(path, mode, options) {
155
155
  this.checkSync(path, 'mkdir');
156
156
  this._sync.mkdirSync(path, mode, options);
157
- this.queue('mkdir', path, mode, options);
157
+ this._async(this.mkdir(path, mode, options));
158
158
  }
159
159
  readdirSync(path) {
160
160
  this.checkSync(path, 'readdir');
@@ -163,12 +163,12 @@ export function Async(FS) {
163
163
  linkSync(srcpath, dstpath) {
164
164
  this.checkSync(srcpath, 'link');
165
165
  this._sync.linkSync(srcpath, dstpath);
166
- this.queue('link', srcpath, dstpath);
166
+ this._async(this.link(srcpath, dstpath));
167
167
  }
168
168
  syncSync(path, data, stats) {
169
169
  this.checkSync(path, 'sync');
170
170
  this._sync.syncSync(path, data, stats);
171
- this.queue('sync', path, data, stats);
171
+ this._async(this.sync(path, data, stats));
172
172
  }
173
173
  existsSync(path) {
174
174
  this.checkSync(path, 'exists');
@@ -181,7 +181,7 @@ export function Async(FS) {
181
181
  writeSync(path, buffer, offset) {
182
182
  this.checkSync(path, 'write');
183
183
  this._sync.writeSync(path, buffer, offset);
184
- this.queue('write', path, buffer, offset);
184
+ this._async(this.write(path, buffer, offset));
185
185
  }
186
186
  /**
187
187
  * @internal
@@ -219,25 +219,6 @@ export function Async(FS) {
219
219
  }
220
220
  await Promise.all(promises);
221
221
  }
222
- /**
223
- * @internal
224
- */
225
- async _next() {
226
- if (!this._queueRunning) {
227
- return;
228
- }
229
- const [method, ...args] = this._queue.shift();
230
- // @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)
231
- await this[method](...args);
232
- await this._next();
233
- }
234
- /**
235
- * @internal
236
- */
237
- queue(...op) {
238
- this._queue.push(op);
239
- void this._next();
240
- }
241
222
  /**
242
223
  * @internal
243
224
  * Patch all async methods to also call their synchronous counterparts unless called from the queue
@@ -263,7 +244,7 @@ export function Async(FS) {
263
244
  this[key] = async (...args) => {
264
245
  var _a, _b;
265
246
  const result = await originalMethod.apply(this, args);
266
- if (new Error().stack.includes(`at async ${this.constructor.name}._next`) || !this._isInitialized)
247
+ if (new Error().stack.includes(`at <computed> [as ${key}]`) || !this._isInitialized)
267
248
  return result;
268
249
  try {
269
250
  // @ts-expect-error 2556
@@ -37,6 +37,12 @@ export function Sync(FS) {
37
37
  async sync(path, data, stats) {
38
38
  return this.syncSync(path, data, stats);
39
39
  }
40
+ async read(path, buffer, offset, end) {
41
+ return this.readSync(path, buffer, offset, end);
42
+ }
43
+ async write(path, buffer, offset) {
44
+ return this.writeSync(path, buffer, offset);
45
+ }
40
46
  }
41
47
  return SyncFS;
42
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "1.8.7",
3
+ "version": "1.8.8",
4
4
  "description": "A filesystem, anywhere",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -29,7 +29,7 @@ suite('write', () => {
29
29
 
30
30
  await handle.close();
31
31
 
32
- assert((await fs.promises.readFile(fn)).equals(expected));
32
+ assert.deepEqual(await fs.promises.readFile(fn), expected);
33
33
 
34
34
  await fs.promises.unlink(fn);
35
35
  });