@componentor/fs 3.0.26 → 3.0.28
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/index.d.mts +308 -60
- package/dist/index.js +951 -164
- package/dist/index.js.map +1 -1
- package/dist/workers/repair.worker.js +1 -2
- package/dist/workers/repair.worker.js.map +1 -1
- package/dist/workers/server.worker.js +1 -2
- package/dist/workers/server.worker.js.map +1 -1
- package/dist/workers/sync-relay.worker.js +14 -5
- package/dist/workers/sync-relay.worker.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,6 +4,306 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
+
// src/node-streams.ts
|
|
8
|
+
var SimpleEventEmitter = class {
|
|
9
|
+
_listeners = /* @__PURE__ */ new Map();
|
|
10
|
+
_onceSet = /* @__PURE__ */ new WeakSet();
|
|
11
|
+
on(event, fn) {
|
|
12
|
+
let arr = this._listeners.get(event);
|
|
13
|
+
if (!arr) {
|
|
14
|
+
arr = [];
|
|
15
|
+
this._listeners.set(event, arr);
|
|
16
|
+
}
|
|
17
|
+
arr.push(fn);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
addListener(event, fn) {
|
|
21
|
+
return this.on(event, fn);
|
|
22
|
+
}
|
|
23
|
+
once(event, fn) {
|
|
24
|
+
this._onceSet.add(fn);
|
|
25
|
+
return this.on(event, fn);
|
|
26
|
+
}
|
|
27
|
+
off(event, fn) {
|
|
28
|
+
const arr = this._listeners.get(event);
|
|
29
|
+
if (arr) {
|
|
30
|
+
const idx = arr.indexOf(fn);
|
|
31
|
+
if (idx !== -1) arr.splice(idx, 1);
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
removeListener(event, fn) {
|
|
36
|
+
return this.off(event, fn);
|
|
37
|
+
}
|
|
38
|
+
removeAllListeners(event) {
|
|
39
|
+
if (event !== void 0) {
|
|
40
|
+
this._listeners.delete(event);
|
|
41
|
+
} else {
|
|
42
|
+
this._listeners.clear();
|
|
43
|
+
}
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
emit(event, ...args) {
|
|
47
|
+
const arr = this._listeners.get(event);
|
|
48
|
+
if (!arr || arr.length === 0) return false;
|
|
49
|
+
const copy = arr.slice();
|
|
50
|
+
for (const fn of copy) {
|
|
51
|
+
if (this._onceSet.has(fn)) {
|
|
52
|
+
this._onceSet.delete(fn);
|
|
53
|
+
this.off(event, fn);
|
|
54
|
+
}
|
|
55
|
+
fn(...args);
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
listenerCount(event) {
|
|
60
|
+
return this._listeners.get(event)?.length ?? 0;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var NodeReadable = class extends SimpleEventEmitter {
|
|
64
|
+
constructor(_readFn, destroyFn) {
|
|
65
|
+
super();
|
|
66
|
+
this._readFn = _readFn;
|
|
67
|
+
if (destroyFn) this._destroyFn = destroyFn;
|
|
68
|
+
}
|
|
69
|
+
_paused = true;
|
|
70
|
+
_destroyed = false;
|
|
71
|
+
_ended = false;
|
|
72
|
+
_reading = false;
|
|
73
|
+
_readBuffer = null;
|
|
74
|
+
_encoding = null;
|
|
75
|
+
/** Whether the stream is still readable (not ended or destroyed). */
|
|
76
|
+
readable = true;
|
|
77
|
+
/** The file path this stream reads from (set externally). */
|
|
78
|
+
path = "";
|
|
79
|
+
/** Total bytes read so far. */
|
|
80
|
+
bytesRead = 0;
|
|
81
|
+
/** Optional cleanup callback invoked on destroy (e.g. close file handle). */
|
|
82
|
+
_destroyFn = null;
|
|
83
|
+
// ---- Flow control (override on to auto-resume) ----
|
|
84
|
+
on(event, fn) {
|
|
85
|
+
super.on(event, fn);
|
|
86
|
+
if (event === "data" && this._paused) {
|
|
87
|
+
this.resume();
|
|
88
|
+
}
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
pause() {
|
|
92
|
+
this._paused = true;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
resume() {
|
|
96
|
+
if (this._destroyed || this._ended) return this;
|
|
97
|
+
this._paused = false;
|
|
98
|
+
this._drain();
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Set the character encoding for data read from this stream.
|
|
103
|
+
* When set, 'data' events emit strings instead of Uint8Array.
|
|
104
|
+
*/
|
|
105
|
+
setEncoding(encoding) {
|
|
106
|
+
this._encoding = encoding;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Non-flowing read — returns the last buffered chunk or null.
|
|
111
|
+
* Node.js has a complex buffer system; we keep it simple here.
|
|
112
|
+
*/
|
|
113
|
+
read(_size) {
|
|
114
|
+
const buf = this._readBuffer;
|
|
115
|
+
this._readBuffer = null;
|
|
116
|
+
return buf;
|
|
117
|
+
}
|
|
118
|
+
/** Destroy the stream, optionally with an error. */
|
|
119
|
+
destroy(err) {
|
|
120
|
+
if (this._destroyed) return this;
|
|
121
|
+
this._destroyed = true;
|
|
122
|
+
this.readable = false;
|
|
123
|
+
if (err) {
|
|
124
|
+
this.emit("error", err);
|
|
125
|
+
}
|
|
126
|
+
if (this._destroyFn) {
|
|
127
|
+
this._destroyFn().then(
|
|
128
|
+
() => this.emit("close"),
|
|
129
|
+
() => this.emit("close")
|
|
130
|
+
);
|
|
131
|
+
} else {
|
|
132
|
+
this.emit("close");
|
|
133
|
+
}
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
// ---- pipe ----
|
|
137
|
+
pipe(dest) {
|
|
138
|
+
if (isNodeWritableInstance(dest)) {
|
|
139
|
+
this.on("data", (chunk) => {
|
|
140
|
+
dest.write(chunk);
|
|
141
|
+
});
|
|
142
|
+
this.on("end", () => {
|
|
143
|
+
if (typeof dest.end === "function") {
|
|
144
|
+
dest.end();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
this.on("error", (err) => {
|
|
148
|
+
if (typeof dest.destroy === "function") {
|
|
149
|
+
dest.destroy(err);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
} else {
|
|
153
|
+
const writer = dest.getWriter();
|
|
154
|
+
this.on("data", (chunk) => {
|
|
155
|
+
writer.write(chunk);
|
|
156
|
+
});
|
|
157
|
+
this.on("end", () => {
|
|
158
|
+
writer.close();
|
|
159
|
+
});
|
|
160
|
+
this.on("error", (err) => {
|
|
161
|
+
writer.abort(err);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (this._paused) {
|
|
165
|
+
this.resume();
|
|
166
|
+
}
|
|
167
|
+
return dest;
|
|
168
|
+
}
|
|
169
|
+
// ---- Internal ----
|
|
170
|
+
async _drain() {
|
|
171
|
+
if (this._reading || this._destroyed || this._ended) return;
|
|
172
|
+
this._reading = true;
|
|
173
|
+
try {
|
|
174
|
+
while (!this._paused && !this._destroyed && !this._ended) {
|
|
175
|
+
const result = await this._readFn();
|
|
176
|
+
if (this._destroyed) break;
|
|
177
|
+
if (result.done || !result.value || result.value.byteLength === 0) {
|
|
178
|
+
this._ended = true;
|
|
179
|
+
this.readable = false;
|
|
180
|
+
this.emit("end");
|
|
181
|
+
this.emit("close");
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
this.bytesRead += result.value.byteLength;
|
|
185
|
+
this._readBuffer = result.value;
|
|
186
|
+
if (this._encoding) {
|
|
187
|
+
this.emit("data", new TextDecoder(this._encoding).decode(result.value));
|
|
188
|
+
} else {
|
|
189
|
+
this.emit("data", result.value);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} catch (err) {
|
|
193
|
+
if (!this._destroyed) {
|
|
194
|
+
this.destroy(err);
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
this._reading = false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var NodeWritable = class extends SimpleEventEmitter {
|
|
202
|
+
constructor(path, _writeFn, _closeFn) {
|
|
203
|
+
super();
|
|
204
|
+
this._writeFn = _writeFn;
|
|
205
|
+
this._closeFn = _closeFn;
|
|
206
|
+
this.path = path;
|
|
207
|
+
}
|
|
208
|
+
/** Total bytes written so far. */
|
|
209
|
+
bytesWritten = 0;
|
|
210
|
+
/** The file path this stream was created for. */
|
|
211
|
+
path;
|
|
212
|
+
/** Whether this stream is still writable. */
|
|
213
|
+
writable = true;
|
|
214
|
+
_destroyed = false;
|
|
215
|
+
_finished = false;
|
|
216
|
+
_writing = false;
|
|
217
|
+
_corked = false;
|
|
218
|
+
// -- public API -----------------------------------------------------------
|
|
219
|
+
/**
|
|
220
|
+
* Buffer all writes until `uncork()` is called.
|
|
221
|
+
* In this minimal implementation we only track the flag for compatibility.
|
|
222
|
+
*/
|
|
223
|
+
cork() {
|
|
224
|
+
this._corked = true;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Flush buffered writes (clears the cork flag).
|
|
228
|
+
* In this minimal implementation we only track the flag for compatibility.
|
|
229
|
+
*/
|
|
230
|
+
uncork() {
|
|
231
|
+
this._corked = false;
|
|
232
|
+
}
|
|
233
|
+
write(chunk, encodingOrCb, cb) {
|
|
234
|
+
const callback = typeof encodingOrCb === "function" ? encodingOrCb : cb;
|
|
235
|
+
if (this._destroyed || this._finished) {
|
|
236
|
+
const err = new Error("write after end");
|
|
237
|
+
if (callback) callback(err);
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
const data = typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
|
|
241
|
+
this._writing = true;
|
|
242
|
+
this._writeFn(data).then(() => {
|
|
243
|
+
this.bytesWritten += data.byteLength;
|
|
244
|
+
this._writing = false;
|
|
245
|
+
if (callback) callback();
|
|
246
|
+
this.emit("drain");
|
|
247
|
+
}).catch((err) => {
|
|
248
|
+
this._writing = false;
|
|
249
|
+
if (callback) callback(err);
|
|
250
|
+
this.emit("error", err);
|
|
251
|
+
});
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
end(chunk, encodingOrCb, cb) {
|
|
255
|
+
let callback;
|
|
256
|
+
let finalChunk;
|
|
257
|
+
if (typeof chunk === "function") {
|
|
258
|
+
callback = chunk;
|
|
259
|
+
finalChunk = void 0;
|
|
260
|
+
} else {
|
|
261
|
+
finalChunk = chunk;
|
|
262
|
+
if (typeof encodingOrCb === "function") {
|
|
263
|
+
callback = encodingOrCb;
|
|
264
|
+
} else {
|
|
265
|
+
callback = cb;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (this._finished) {
|
|
269
|
+
if (callback) callback();
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
this.writable = false;
|
|
273
|
+
const finish = () => {
|
|
274
|
+
this._closeFn().then(() => {
|
|
275
|
+
this._finished = true;
|
|
276
|
+
this.emit("finish");
|
|
277
|
+
this.emit("close");
|
|
278
|
+
if (callback) callback();
|
|
279
|
+
}).catch((err) => {
|
|
280
|
+
this.emit("error", err);
|
|
281
|
+
if (callback) callback(err);
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
if (finalChunk !== void 0 && finalChunk !== null) {
|
|
285
|
+
this.write(finalChunk, void 0, () => finish());
|
|
286
|
+
} else {
|
|
287
|
+
finish();
|
|
288
|
+
}
|
|
289
|
+
return this;
|
|
290
|
+
}
|
|
291
|
+
destroy(err) {
|
|
292
|
+
if (this._destroyed) return this;
|
|
293
|
+
this._destroyed = true;
|
|
294
|
+
this.writable = false;
|
|
295
|
+
this._closeFn().catch(() => {
|
|
296
|
+
}).finally(() => {
|
|
297
|
+
if (err) this.emit("error", err);
|
|
298
|
+
this.emit("close");
|
|
299
|
+
});
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
function isNodeWritableInstance(obj) {
|
|
304
|
+
return obj !== null && typeof obj === "object" && typeof obj.write === "function" && !("getWriter" in obj);
|
|
305
|
+
}
|
|
306
|
+
|
|
7
307
|
// src/protocol/opcodes.ts
|
|
8
308
|
var OP = {
|
|
9
309
|
READ: 1,
|
|
@@ -279,7 +579,7 @@ function decodeStats(data) {
|
|
|
279
579
|
isSymbolicLink: () => isSymlink,
|
|
280
580
|
isFIFO: () => false,
|
|
281
581
|
isSocket: () => false,
|
|
282
|
-
dev:
|
|
582
|
+
dev: 1,
|
|
283
583
|
ino,
|
|
284
584
|
mode,
|
|
285
585
|
nlink,
|
|
@@ -296,7 +596,11 @@ function decodeStats(data) {
|
|
|
296
596
|
atime: new Date(atimeMs),
|
|
297
597
|
mtime: new Date(mtimeMs),
|
|
298
598
|
ctime: new Date(ctimeMs),
|
|
299
|
-
birthtime: new Date(ctimeMs)
|
|
599
|
+
birthtime: new Date(ctimeMs),
|
|
600
|
+
atimeNs: atimeMs * 1e6,
|
|
601
|
+
mtimeNs: mtimeMs * 1e6,
|
|
602
|
+
ctimeNs: ctimeMs * 1e6,
|
|
603
|
+
birthtimeNs: ctimeMs * 1e6
|
|
300
604
|
};
|
|
301
605
|
}
|
|
302
606
|
function decodeStatsBigInt(data) {
|
|
@@ -325,7 +629,7 @@ function decodeStatsBigInt(data) {
|
|
|
325
629
|
isSymbolicLink: () => isSymlink,
|
|
326
630
|
isFIFO: () => false,
|
|
327
631
|
isSocket: () => false,
|
|
328
|
-
dev:
|
|
632
|
+
dev: 1n,
|
|
329
633
|
ino: BigInt(ino),
|
|
330
634
|
mode: BigInt(mode),
|
|
331
635
|
nlink: BigInt(nlink),
|
|
@@ -413,7 +717,13 @@ var constants = {
|
|
|
413
717
|
O_EXCL: 128,
|
|
414
718
|
O_TRUNC: 512,
|
|
415
719
|
O_APPEND: 1024,
|
|
720
|
+
O_NOCTTY: 256,
|
|
721
|
+
O_NONBLOCK: 2048,
|
|
416
722
|
O_SYNC: 4096,
|
|
723
|
+
O_DSYNC: 4096,
|
|
724
|
+
O_DIRECTORY: 65536,
|
|
725
|
+
O_NOFOLLOW: 131072,
|
|
726
|
+
O_NOATIME: 262144,
|
|
417
727
|
// File type constants
|
|
418
728
|
S_IFMT: 61440,
|
|
419
729
|
S_IFREG: 32768,
|
|
@@ -481,29 +791,53 @@ function closeSync(syncRequest, fd) {
|
|
|
481
791
|
const { status } = syncRequest(buf);
|
|
482
792
|
if (status !== 0) throw statusToError(status, "close", String(fd));
|
|
483
793
|
}
|
|
484
|
-
function readSync(syncRequest, fd,
|
|
794
|
+
function readSync(syncRequest, fd, bufferOrOptions, offsetOrOptions, length, position) {
|
|
795
|
+
let buffer;
|
|
796
|
+
let off, len, pos;
|
|
797
|
+
if (bufferOrOptions instanceof Uint8Array) {
|
|
798
|
+
buffer = bufferOrOptions;
|
|
799
|
+
if (offsetOrOptions != null && typeof offsetOrOptions === "object") {
|
|
800
|
+
off = offsetOrOptions.offset ?? 0;
|
|
801
|
+
len = offsetOrOptions.length ?? buffer.byteLength;
|
|
802
|
+
pos = offsetOrOptions.position ?? null;
|
|
803
|
+
} else {
|
|
804
|
+
off = offsetOrOptions ?? 0;
|
|
805
|
+
len = length ?? buffer.byteLength;
|
|
806
|
+
pos = position ?? null;
|
|
807
|
+
}
|
|
808
|
+
} else {
|
|
809
|
+
buffer = bufferOrOptions.buffer;
|
|
810
|
+
off = bufferOrOptions.offset ?? 0;
|
|
811
|
+
len = bufferOrOptions.length ?? buffer.byteLength;
|
|
812
|
+
pos = bufferOrOptions.position ?? null;
|
|
813
|
+
}
|
|
485
814
|
const fdBuf = new Uint8Array(16);
|
|
486
815
|
const dv = new DataView(fdBuf.buffer);
|
|
487
816
|
dv.setUint32(0, fd, true);
|
|
488
|
-
dv.setUint32(4,
|
|
489
|
-
dv.setFloat64(8,
|
|
817
|
+
dv.setUint32(4, len, true);
|
|
818
|
+
dv.setFloat64(8, pos ?? -1, true);
|
|
490
819
|
const buf = encodeRequest(OP.FREAD, "", 0, fdBuf);
|
|
491
820
|
const { status, data } = syncRequest(buf);
|
|
492
821
|
if (status !== 0) throw statusToError(status, "read", String(fd));
|
|
493
822
|
if (data) {
|
|
494
|
-
buffer.set(data.subarray(0, Math.min(data.byteLength,
|
|
823
|
+
buffer.set(data.subarray(0, Math.min(data.byteLength, len)), off);
|
|
495
824
|
return data.byteLength;
|
|
496
825
|
}
|
|
497
826
|
return 0;
|
|
498
827
|
}
|
|
499
|
-
function writeSyncFd(syncRequest, fd, bufferOrString,
|
|
828
|
+
function writeSyncFd(syncRequest, fd, bufferOrString, offsetOrPositionOrOptions, lengthOrEncoding, position) {
|
|
500
829
|
let writeData;
|
|
501
830
|
let pos;
|
|
502
831
|
if (typeof bufferOrString === "string") {
|
|
503
832
|
writeData = encoder2.encode(bufferOrString);
|
|
504
|
-
pos =
|
|
833
|
+
pos = offsetOrPositionOrOptions != null && typeof offsetOrPositionOrOptions === "number" ? offsetOrPositionOrOptions : null;
|
|
834
|
+
} else if (offsetOrPositionOrOptions != null && typeof offsetOrPositionOrOptions === "object") {
|
|
835
|
+
const offset = offsetOrPositionOrOptions.offset ?? 0;
|
|
836
|
+
const length = offsetOrPositionOrOptions.length ?? bufferOrString.byteLength;
|
|
837
|
+
pos = offsetOrPositionOrOptions.position ?? null;
|
|
838
|
+
writeData = bufferOrString.subarray(offset, offset + length);
|
|
505
839
|
} else {
|
|
506
|
-
const offset =
|
|
840
|
+
const offset = offsetOrPositionOrOptions ?? 0;
|
|
507
841
|
const length = lengthOrEncoding != null ? lengthOrEncoding : bufferOrString.byteLength;
|
|
508
842
|
pos = position ?? null;
|
|
509
843
|
writeData = bufferOrString.subarray(offset, offset + length);
|
|
@@ -550,24 +884,49 @@ async function open(asyncRequest, filePath, flags, _mode) {
|
|
|
550
884
|
function createFileHandle(fd, asyncRequest) {
|
|
551
885
|
return {
|
|
552
886
|
fd,
|
|
553
|
-
async read(
|
|
554
|
-
|
|
887
|
+
async read(bufferOrOptions, offsetOrOptions, length, position) {
|
|
888
|
+
let buffer;
|
|
889
|
+
let off, len, pos;
|
|
890
|
+
if (bufferOrOptions instanceof Uint8Array) {
|
|
891
|
+
buffer = bufferOrOptions;
|
|
892
|
+
if (offsetOrOptions != null && typeof offsetOrOptions === "object") {
|
|
893
|
+
off = offsetOrOptions.offset ?? 0;
|
|
894
|
+
len = offsetOrOptions.length ?? buffer.byteLength;
|
|
895
|
+
pos = offsetOrOptions.position ?? null;
|
|
896
|
+
} else {
|
|
897
|
+
off = offsetOrOptions ?? 0;
|
|
898
|
+
len = length ?? buffer.byteLength;
|
|
899
|
+
pos = position ?? null;
|
|
900
|
+
}
|
|
901
|
+
} else {
|
|
902
|
+
buffer = bufferOrOptions.buffer;
|
|
903
|
+
off = bufferOrOptions.offset ?? 0;
|
|
904
|
+
len = bufferOrOptions.length ?? buffer.byteLength;
|
|
905
|
+
pos = bufferOrOptions.position ?? null;
|
|
906
|
+
}
|
|
907
|
+
const { status, data } = await asyncRequest(OP.FREAD, "", 0, null, void 0, { fd, length: len, position: pos ?? -1 });
|
|
555
908
|
if (status !== 0) throw statusToError(status, "read", String(fd));
|
|
556
909
|
const bytesRead = data ? data.byteLength : 0;
|
|
557
|
-
if (data) buffer.set(data.subarray(0, Math.min(bytesRead,
|
|
910
|
+
if (data) buffer.set(data.subarray(0, Math.min(bytesRead, len)), off);
|
|
558
911
|
return { bytesRead, buffer };
|
|
559
912
|
},
|
|
560
|
-
async write(bufferOrString,
|
|
913
|
+
async write(bufferOrString, offsetOrPositionOrOptions, lengthOrEncoding, position) {
|
|
561
914
|
let writeData;
|
|
562
915
|
let pos;
|
|
563
916
|
let resultBuffer;
|
|
564
917
|
if (typeof bufferOrString === "string") {
|
|
565
918
|
resultBuffer = encoder2.encode(bufferOrString);
|
|
566
919
|
writeData = resultBuffer;
|
|
567
|
-
pos =
|
|
920
|
+
pos = offsetOrPositionOrOptions != null && typeof offsetOrPositionOrOptions === "number" ? offsetOrPositionOrOptions : -1;
|
|
921
|
+
} else if (offsetOrPositionOrOptions != null && typeof offsetOrPositionOrOptions === "object") {
|
|
922
|
+
resultBuffer = bufferOrString;
|
|
923
|
+
const offset = offsetOrPositionOrOptions.offset ?? 0;
|
|
924
|
+
const length = offsetOrPositionOrOptions.length ?? bufferOrString.byteLength;
|
|
925
|
+
pos = offsetOrPositionOrOptions.position != null ? offsetOrPositionOrOptions.position : -1;
|
|
926
|
+
writeData = bufferOrString.subarray(offset, offset + length);
|
|
568
927
|
} else {
|
|
569
928
|
resultBuffer = bufferOrString;
|
|
570
|
-
const offset =
|
|
929
|
+
const offset = offsetOrPositionOrOptions ?? 0;
|
|
571
930
|
const length = lengthOrEncoding != null ? lengthOrEncoding : bufferOrString.byteLength;
|
|
572
931
|
pos = position != null ? position : -1;
|
|
573
932
|
writeData = bufferOrString.subarray(offset, offset + length);
|
|
@@ -577,6 +936,27 @@ function createFileHandle(fd, asyncRequest) {
|
|
|
577
936
|
const bytesWritten = data ? new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(0, true) : 0;
|
|
578
937
|
return { bytesWritten, buffer: resultBuffer };
|
|
579
938
|
},
|
|
939
|
+
async readv(buffers, position) {
|
|
940
|
+
let totalRead = 0;
|
|
941
|
+
let pos = position ?? null;
|
|
942
|
+
for (const buf of buffers) {
|
|
943
|
+
const { bytesRead } = await this.read(buf, 0, buf.byteLength, pos);
|
|
944
|
+
totalRead += bytesRead;
|
|
945
|
+
if (pos !== null) pos += bytesRead;
|
|
946
|
+
if (bytesRead < buf.byteLength) break;
|
|
947
|
+
}
|
|
948
|
+
return { bytesRead: totalRead, buffers };
|
|
949
|
+
},
|
|
950
|
+
async writev(buffers, position) {
|
|
951
|
+
let totalWritten = 0;
|
|
952
|
+
let pos = position ?? null;
|
|
953
|
+
for (const buf of buffers) {
|
|
954
|
+
const { bytesWritten } = await this.write(buf, 0, buf.byteLength, pos);
|
|
955
|
+
totalWritten += bytesWritten;
|
|
956
|
+
if (pos !== null) pos += bytesWritten;
|
|
957
|
+
}
|
|
958
|
+
return { bytesWritten: totalWritten, buffers };
|
|
959
|
+
},
|
|
580
960
|
async readFile(options) {
|
|
581
961
|
const encoding = typeof options === "string" ? options : options?.encoding;
|
|
582
962
|
const { status, data } = await asyncRequest(OP.FREAD, "", 0, null, void 0, { fd, length: Number.MAX_SAFE_INTEGER, position: 0 });
|
|
@@ -599,6 +979,16 @@ function createFileHandle(fd, asyncRequest) {
|
|
|
599
979
|
if (status !== 0) throw statusToError(status, "fstat", String(fd));
|
|
600
980
|
return decodeStats(data);
|
|
601
981
|
},
|
|
982
|
+
async appendFile(data, _options) {
|
|
983
|
+
const encoded = typeof data === "string" ? encoder2.encode(data) : data;
|
|
984
|
+
const st = await this.stat();
|
|
985
|
+
const { status } = await asyncRequest(OP.FWRITE, "", 0, null, void 0, { fd, data: encoded, position: st.size });
|
|
986
|
+
if (status !== 0) throw statusToError(status, "write", String(fd));
|
|
987
|
+
},
|
|
988
|
+
async chmod(_mode) {
|
|
989
|
+
},
|
|
990
|
+
async chown(_uid, _gid) {
|
|
991
|
+
},
|
|
602
992
|
async sync() {
|
|
603
993
|
await asyncRequest(OP.FSYNC, "");
|
|
604
994
|
},
|
|
@@ -608,6 +998,9 @@ function createFileHandle(fd, asyncRequest) {
|
|
|
608
998
|
async close() {
|
|
609
999
|
const { status } = await asyncRequest(OP.CLOSE, "", 0, null, void 0, { fd });
|
|
610
1000
|
if (status !== 0) throw statusToError(status, "close", String(fd));
|
|
1001
|
+
},
|
|
1002
|
+
[Symbol.asyncDispose]() {
|
|
1003
|
+
return this.close();
|
|
611
1004
|
}
|
|
612
1005
|
};
|
|
613
1006
|
}
|
|
@@ -714,6 +1107,10 @@ new TextDecoder();
|
|
|
714
1107
|
function readFileSync(syncRequest, filePath, options) {
|
|
715
1108
|
const encoding = typeof options === "string" ? options : options?.encoding;
|
|
716
1109
|
const flag = typeof options === "string" ? void 0 : options?.flag;
|
|
1110
|
+
const signal = typeof options === "string" ? void 0 : options?.signal;
|
|
1111
|
+
if (signal?.aborted) {
|
|
1112
|
+
throw new DOMException("The operation was aborted", "AbortError");
|
|
1113
|
+
}
|
|
717
1114
|
if (!flag || flag === "r") {
|
|
718
1115
|
const buf = encodeRequest(OP.READ, filePath);
|
|
719
1116
|
const { status, data } = syncRequest(buf);
|
|
@@ -757,8 +1154,13 @@ function readFileSync(syncRequest, filePath, options) {
|
|
|
757
1154
|
async function readFile(asyncRequest, filePath, options) {
|
|
758
1155
|
const encoding = typeof options === "string" ? options : options?.encoding;
|
|
759
1156
|
const flag = typeof options === "string" ? void 0 : options?.flag;
|
|
1157
|
+
const signal = typeof options === "string" ? void 0 : options?.signal;
|
|
1158
|
+
if (signal?.aborted) {
|
|
1159
|
+
throw new DOMException("The operation was aborted", "AbortError");
|
|
1160
|
+
}
|
|
760
1161
|
if (!flag || flag === "r") {
|
|
761
1162
|
const { status, data } = await asyncRequest(OP.READ, filePath);
|
|
1163
|
+
if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
|
|
762
1164
|
if (status !== 0) throw statusToError(status, "read", filePath);
|
|
763
1165
|
const result = data ?? new Uint8Array(0);
|
|
764
1166
|
if (encoding) return decodeBuffer(result, encoding);
|
|
@@ -767,6 +1169,7 @@ async function readFile(asyncRequest, filePath, options) {
|
|
|
767
1169
|
const handle = await open(asyncRequest, filePath, flag);
|
|
768
1170
|
try {
|
|
769
1171
|
const result = await handle.readFile(encoding ? encoding : void 0);
|
|
1172
|
+
if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
|
|
770
1173
|
return result;
|
|
771
1174
|
} finally {
|
|
772
1175
|
await handle.close();
|
|
@@ -779,6 +1182,10 @@ function writeFileSync(syncRequest, filePath, data, options) {
|
|
|
779
1182
|
const opts = typeof options === "string" ? { encoding: options } : options;
|
|
780
1183
|
const encoded = typeof data === "string" ? opts?.encoding ? encodeString(data, opts.encoding) : encoder3.encode(data) : data;
|
|
781
1184
|
const flag = opts?.flag;
|
|
1185
|
+
const signal = opts?.signal;
|
|
1186
|
+
if (signal?.aborted) {
|
|
1187
|
+
throw new DOMException("The operation was aborted", "AbortError");
|
|
1188
|
+
}
|
|
782
1189
|
if (!flag || flag === "w") {
|
|
783
1190
|
const flags = opts?.flush === true ? 1 : 0;
|
|
784
1191
|
const buf = encodeRequest(OP.WRITE, filePath, flags, encoded);
|
|
@@ -797,15 +1204,21 @@ async function writeFile(asyncRequest, filePath, data, options) {
|
|
|
797
1204
|
const opts = typeof options === "string" ? { encoding: options } : options;
|
|
798
1205
|
const encoded = typeof data === "string" ? opts?.encoding ? encodeString(data, opts.encoding) : encoder3.encode(data) : data;
|
|
799
1206
|
const flag = opts?.flag;
|
|
1207
|
+
const signal = opts?.signal;
|
|
1208
|
+
if (signal?.aborted) {
|
|
1209
|
+
throw new DOMException("The operation was aborted", "AbortError");
|
|
1210
|
+
}
|
|
800
1211
|
if (!flag || flag === "w") {
|
|
801
1212
|
const flags = opts?.flush === true ? 1 : 0;
|
|
802
1213
|
const { status } = await asyncRequest(OP.WRITE, filePath, flags, encoded);
|
|
1214
|
+
if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
|
|
803
1215
|
if (status !== 0) throw statusToError(status, "write", filePath);
|
|
804
1216
|
return;
|
|
805
1217
|
}
|
|
806
1218
|
const handle = await open(asyncRequest, filePath, flag);
|
|
807
1219
|
try {
|
|
808
1220
|
await handle.writeFile(encoded);
|
|
1221
|
+
if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
|
|
809
1222
|
} finally {
|
|
810
1223
|
await handle.close();
|
|
811
1224
|
}
|
|
@@ -868,7 +1281,11 @@ async function rmdir(asyncRequest, filePath, options) {
|
|
|
868
1281
|
}
|
|
869
1282
|
|
|
870
1283
|
// src/methods/rm.ts
|
|
871
|
-
|
|
1284
|
+
var RETRYABLE_CODES = /* @__PURE__ */ new Set(["EBUSY", "ENOTEMPTY", "EPERM"]);
|
|
1285
|
+
function isRetryable(e) {
|
|
1286
|
+
return e instanceof FSError && RETRYABLE_CODES.has(e.code);
|
|
1287
|
+
}
|
|
1288
|
+
function rmSyncCore(syncRequest, filePath, options) {
|
|
872
1289
|
const flags = (options?.recursive ? 1 : 0) | (options?.force ? 2 : 0);
|
|
873
1290
|
const buf = encodeRequest(OP.UNLINK, filePath, flags);
|
|
874
1291
|
const { status } = syncRequest(buf);
|
|
@@ -886,7 +1303,24 @@ function rmSync(syncRequest, filePath, options) {
|
|
|
886
1303
|
throw statusToError(status, "rm", filePath);
|
|
887
1304
|
}
|
|
888
1305
|
}
|
|
889
|
-
|
|
1306
|
+
function rmSync(syncRequest, filePath, options) {
|
|
1307
|
+
const maxRetries = options?.maxRetries ?? 0;
|
|
1308
|
+
let lastError;
|
|
1309
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1310
|
+
try {
|
|
1311
|
+
rmSyncCore(syncRequest, filePath, options);
|
|
1312
|
+
return;
|
|
1313
|
+
} catch (e) {
|
|
1314
|
+
lastError = e;
|
|
1315
|
+
if (attempt < maxRetries && isRetryable(e)) {
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
throw e;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
throw lastError;
|
|
1322
|
+
}
|
|
1323
|
+
async function rmAsyncCore(asyncRequest, filePath, options) {
|
|
890
1324
|
const flags = (options?.recursive ? 1 : 0) | (options?.force ? 2 : 0);
|
|
891
1325
|
const { status } = await asyncRequest(OP.UNLINK, filePath, flags);
|
|
892
1326
|
if (status === 3) {
|
|
@@ -902,6 +1336,28 @@ async function rm(asyncRequest, filePath, options) {
|
|
|
902
1336
|
throw statusToError(status, "rm", filePath);
|
|
903
1337
|
}
|
|
904
1338
|
}
|
|
1339
|
+
function delay(ms) {
|
|
1340
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
1341
|
+
}
|
|
1342
|
+
async function rm(asyncRequest, filePath, options) {
|
|
1343
|
+
const maxRetries = options?.maxRetries ?? 0;
|
|
1344
|
+
const retryDelay = options?.retryDelay ?? 100;
|
|
1345
|
+
let lastError;
|
|
1346
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1347
|
+
try {
|
|
1348
|
+
await rmAsyncCore(asyncRequest, filePath, options);
|
|
1349
|
+
return;
|
|
1350
|
+
} catch (e) {
|
|
1351
|
+
lastError = e;
|
|
1352
|
+
if (attempt < maxRetries && isRetryable(e)) {
|
|
1353
|
+
await delay(retryDelay);
|
|
1354
|
+
continue;
|
|
1355
|
+
}
|
|
1356
|
+
throw e;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
throw lastError;
|
|
1360
|
+
}
|
|
905
1361
|
|
|
906
1362
|
// src/methods/unlink.ts
|
|
907
1363
|
function unlinkSync(syncRequest, filePath) {
|
|
@@ -930,14 +1386,18 @@ async function readdirBaseAsync(asyncRequest, filePath, withFileTypes) {
|
|
|
930
1386
|
if (!data) return [];
|
|
931
1387
|
return withFileTypes ? decodeDirents(data, filePath) : decodeNames(data);
|
|
932
1388
|
}
|
|
933
|
-
function readdirRecursiveSync(syncRequest, basePath, prefix, withFileTypes) {
|
|
1389
|
+
function readdirRecursiveSync(syncRequest, basePath, prefix, withFileTypes, rootPath) {
|
|
934
1390
|
const entries = readdirBaseSync(syncRequest, basePath, true);
|
|
935
1391
|
const results = [];
|
|
1392
|
+
const effectiveRoot = rootPath ?? basePath;
|
|
936
1393
|
for (const entry of entries) {
|
|
937
1394
|
const relativePath = prefix ? prefix + "/" + entry.name : entry.name;
|
|
938
1395
|
if (withFileTypes) {
|
|
1396
|
+
const parentPath = prefix || effectiveRoot;
|
|
939
1397
|
results.push({
|
|
940
1398
|
name: relativePath,
|
|
1399
|
+
parentPath,
|
|
1400
|
+
path: parentPath,
|
|
941
1401
|
isFile: entry.isFile,
|
|
942
1402
|
isDirectory: entry.isDirectory,
|
|
943
1403
|
isBlockDevice: entry.isBlockDevice,
|
|
@@ -952,20 +1412,24 @@ function readdirRecursiveSync(syncRequest, basePath, prefix, withFileTypes) {
|
|
|
952
1412
|
if (entry.isDirectory()) {
|
|
953
1413
|
const childPath = basePath + "/" + entry.name;
|
|
954
1414
|
results.push(
|
|
955
|
-
...readdirRecursiveSync(syncRequest, childPath, relativePath, withFileTypes)
|
|
1415
|
+
...readdirRecursiveSync(syncRequest, childPath, relativePath, withFileTypes, effectiveRoot)
|
|
956
1416
|
);
|
|
957
1417
|
}
|
|
958
1418
|
}
|
|
959
1419
|
return results;
|
|
960
1420
|
}
|
|
961
|
-
async function readdirRecursiveAsync(asyncRequest, basePath, prefix, withFileTypes) {
|
|
1421
|
+
async function readdirRecursiveAsync(asyncRequest, basePath, prefix, withFileTypes, rootPath) {
|
|
962
1422
|
const entries = await readdirBaseAsync(asyncRequest, basePath, true);
|
|
963
1423
|
const results = [];
|
|
1424
|
+
const effectiveRoot = rootPath ?? basePath;
|
|
964
1425
|
for (const entry of entries) {
|
|
965
1426
|
const relativePath = prefix ? prefix + "/" + entry.name : entry.name;
|
|
966
1427
|
if (withFileTypes) {
|
|
1428
|
+
const parentPath = prefix || effectiveRoot;
|
|
967
1429
|
results.push({
|
|
968
1430
|
name: relativePath,
|
|
1431
|
+
parentPath,
|
|
1432
|
+
path: parentPath,
|
|
969
1433
|
isFile: entry.isFile,
|
|
970
1434
|
isDirectory: entry.isDirectory,
|
|
971
1435
|
isBlockDevice: entry.isBlockDevice,
|
|
@@ -983,7 +1447,8 @@ async function readdirRecursiveAsync(asyncRequest, basePath, prefix, withFileTyp
|
|
|
983
1447
|
asyncRequest,
|
|
984
1448
|
childPath,
|
|
985
1449
|
relativePath,
|
|
986
|
-
withFileTypes
|
|
1450
|
+
withFileTypes,
|
|
1451
|
+
effectiveRoot
|
|
987
1452
|
);
|
|
988
1453
|
results.push(...children);
|
|
989
1454
|
}
|
|
@@ -1270,8 +1735,20 @@ __export(path_exports, {
|
|
|
1270
1735
|
parse: () => parse,
|
|
1271
1736
|
relative: () => relative,
|
|
1272
1737
|
resolve: () => resolve,
|
|
1273
|
-
sep: () => sep
|
|
1738
|
+
sep: () => sep,
|
|
1739
|
+
toPathString: () => toPathString
|
|
1274
1740
|
});
|
|
1741
|
+
function toPathString(p) {
|
|
1742
|
+
if (typeof p === "string") return p;
|
|
1743
|
+
if (p instanceof Uint8Array) return new TextDecoder().decode(p);
|
|
1744
|
+
if (typeof URL !== "undefined" && p instanceof URL) {
|
|
1745
|
+
if (p.protocol !== "file:") {
|
|
1746
|
+
throw new TypeError("The URL must use the file: protocol");
|
|
1747
|
+
}
|
|
1748
|
+
return decodeURIComponent(p.pathname);
|
|
1749
|
+
}
|
|
1750
|
+
return String(p);
|
|
1751
|
+
}
|
|
1275
1752
|
var sep = "/";
|
|
1276
1753
|
var delimiter = ":";
|
|
1277
1754
|
function normalize(p) {
|
|
@@ -1553,7 +2030,11 @@ function emptyStats() {
|
|
|
1553
2030
|
atime: zero,
|
|
1554
2031
|
mtime: zero,
|
|
1555
2032
|
ctime: zero,
|
|
1556
|
-
birthtime: zero
|
|
2033
|
+
birthtime: zero,
|
|
2034
|
+
atimeNs: 0,
|
|
2035
|
+
mtimeNs: 0,
|
|
2036
|
+
ctimeNs: 0,
|
|
2037
|
+
birthtimeNs: 0
|
|
1557
2038
|
};
|
|
1558
2039
|
}
|
|
1559
2040
|
async function* watchAsync(ns, _asyncRequest, filePath, options) {
|
|
@@ -2289,101 +2770,103 @@ var VFSFileSystem = class {
|
|
|
2289
2770
|
}
|
|
2290
2771
|
// ========== Sync API ==========
|
|
2291
2772
|
readFileSync(filePath, options) {
|
|
2292
|
-
return readFileSync(this._sync, filePath, options);
|
|
2773
|
+
return readFileSync(this._sync, toPathString(filePath), options);
|
|
2293
2774
|
}
|
|
2294
2775
|
writeFileSync(filePath, data, options) {
|
|
2295
|
-
writeFileSync(this._sync, filePath, data, options);
|
|
2776
|
+
writeFileSync(this._sync, toPathString(filePath), data, options);
|
|
2296
2777
|
}
|
|
2297
2778
|
appendFileSync(filePath, data, options) {
|
|
2298
|
-
appendFileSync(this._sync, filePath, data);
|
|
2779
|
+
appendFileSync(this._sync, toPathString(filePath), data);
|
|
2299
2780
|
}
|
|
2300
2781
|
existsSync(filePath) {
|
|
2301
|
-
return existsSync(this._sync, filePath);
|
|
2782
|
+
return existsSync(this._sync, toPathString(filePath));
|
|
2302
2783
|
}
|
|
2303
2784
|
mkdirSync(filePath, options) {
|
|
2304
|
-
return mkdirSync(this._sync, filePath, options);
|
|
2785
|
+
return mkdirSync(this._sync, toPathString(filePath), options);
|
|
2305
2786
|
}
|
|
2306
2787
|
rmdirSync(filePath, options) {
|
|
2307
|
-
rmdirSync(this._sync, filePath, options);
|
|
2788
|
+
rmdirSync(this._sync, toPathString(filePath), options);
|
|
2308
2789
|
}
|
|
2309
2790
|
rmSync(filePath, options) {
|
|
2310
|
-
rmSync(this._sync, filePath, options);
|
|
2791
|
+
rmSync(this._sync, toPathString(filePath), options);
|
|
2311
2792
|
}
|
|
2312
2793
|
unlinkSync(filePath) {
|
|
2313
|
-
unlinkSync(this._sync, filePath);
|
|
2794
|
+
unlinkSync(this._sync, toPathString(filePath));
|
|
2314
2795
|
}
|
|
2315
2796
|
readdirSync(filePath, options) {
|
|
2316
|
-
return readdirSync(this._sync, filePath, options);
|
|
2797
|
+
return readdirSync(this._sync, toPathString(filePath), options);
|
|
2317
2798
|
}
|
|
2318
2799
|
globSync(pattern, options) {
|
|
2319
2800
|
return globSync(this._sync, pattern, options);
|
|
2320
2801
|
}
|
|
2321
2802
|
statSync(filePath, options) {
|
|
2322
|
-
return statSync(this._sync, filePath, options);
|
|
2803
|
+
return statSync(this._sync, toPathString(filePath), options);
|
|
2323
2804
|
}
|
|
2324
2805
|
lstatSync(filePath, options) {
|
|
2325
|
-
return lstatSync(this._sync, filePath, options);
|
|
2806
|
+
return lstatSync(this._sync, toPathString(filePath), options);
|
|
2326
2807
|
}
|
|
2327
2808
|
renameSync(oldPath, newPath) {
|
|
2328
|
-
renameSync(this._sync, oldPath, newPath);
|
|
2809
|
+
renameSync(this._sync, toPathString(oldPath), toPathString(newPath));
|
|
2329
2810
|
}
|
|
2330
2811
|
copyFileSync(src, dest, mode) {
|
|
2331
|
-
copyFileSync(this._sync, src, dest, mode);
|
|
2812
|
+
copyFileSync(this._sync, toPathString(src), toPathString(dest), mode);
|
|
2332
2813
|
}
|
|
2333
2814
|
cpSync(src, dest, options) {
|
|
2815
|
+
const srcPath = toPathString(src);
|
|
2816
|
+
const destPath = toPathString(dest);
|
|
2334
2817
|
const force = options?.force !== false;
|
|
2335
2818
|
const errorOnExist = options?.errorOnExist ?? false;
|
|
2336
2819
|
const dereference = options?.dereference ?? false;
|
|
2337
2820
|
const preserveTimestamps = options?.preserveTimestamps ?? false;
|
|
2338
|
-
const srcStat = dereference ? this.statSync(
|
|
2821
|
+
const srcStat = dereference ? this.statSync(srcPath) : this.lstatSync(srcPath);
|
|
2339
2822
|
if (srcStat.isDirectory()) {
|
|
2340
2823
|
if (!options?.recursive) {
|
|
2341
|
-
throw createError("EISDIR", "cp",
|
|
2824
|
+
throw createError("EISDIR", "cp", srcPath);
|
|
2342
2825
|
}
|
|
2343
2826
|
try {
|
|
2344
|
-
this.mkdirSync(
|
|
2827
|
+
this.mkdirSync(destPath, { recursive: true });
|
|
2345
2828
|
} catch (e) {
|
|
2346
2829
|
if (e.code !== "EEXIST") throw e;
|
|
2347
2830
|
}
|
|
2348
|
-
const entries = this.readdirSync(
|
|
2831
|
+
const entries = this.readdirSync(srcPath, { withFileTypes: true });
|
|
2349
2832
|
for (const entry of entries) {
|
|
2350
|
-
const srcChild = join(
|
|
2351
|
-
const destChild = join(
|
|
2833
|
+
const srcChild = join(srcPath, entry.name);
|
|
2834
|
+
const destChild = join(destPath, entry.name);
|
|
2352
2835
|
this.cpSync(srcChild, destChild, options);
|
|
2353
2836
|
}
|
|
2354
2837
|
} else if (srcStat.isSymbolicLink() && !dereference) {
|
|
2355
|
-
const target = this.readlinkSync(
|
|
2838
|
+
const target = this.readlinkSync(srcPath);
|
|
2356
2839
|
let destExists = false;
|
|
2357
2840
|
try {
|
|
2358
|
-
this.lstatSync(
|
|
2841
|
+
this.lstatSync(destPath);
|
|
2359
2842
|
destExists = true;
|
|
2360
2843
|
} catch {
|
|
2361
2844
|
}
|
|
2362
2845
|
if (destExists) {
|
|
2363
|
-
if (errorOnExist) throw createError("EEXIST", "cp",
|
|
2846
|
+
if (errorOnExist) throw createError("EEXIST", "cp", destPath);
|
|
2364
2847
|
if (!force) return;
|
|
2365
|
-
this.unlinkSync(
|
|
2848
|
+
this.unlinkSync(destPath);
|
|
2366
2849
|
}
|
|
2367
|
-
this.symlinkSync(target,
|
|
2850
|
+
this.symlinkSync(target, destPath);
|
|
2368
2851
|
} else {
|
|
2369
2852
|
let destExists = false;
|
|
2370
2853
|
try {
|
|
2371
|
-
this.lstatSync(
|
|
2854
|
+
this.lstatSync(destPath);
|
|
2372
2855
|
destExists = true;
|
|
2373
2856
|
} catch {
|
|
2374
2857
|
}
|
|
2375
2858
|
if (destExists) {
|
|
2376
|
-
if (errorOnExist) throw createError("EEXIST", "cp",
|
|
2859
|
+
if (errorOnExist) throw createError("EEXIST", "cp", destPath);
|
|
2377
2860
|
if (!force) return;
|
|
2378
2861
|
}
|
|
2379
|
-
this.copyFileSync(
|
|
2862
|
+
this.copyFileSync(srcPath, destPath, errorOnExist ? constants.COPYFILE_EXCL : 0);
|
|
2380
2863
|
}
|
|
2381
2864
|
if (preserveTimestamps) {
|
|
2382
|
-
const st = this.statSync(
|
|
2383
|
-
this.utimesSync(
|
|
2865
|
+
const st = this.statSync(srcPath);
|
|
2866
|
+
this.utimesSync(destPath, st.atime, st.mtime);
|
|
2384
2867
|
}
|
|
2385
2868
|
}
|
|
2386
|
-
async
|
|
2869
|
+
async _cpAsync(src, dest, options) {
|
|
2387
2870
|
const force = options?.force !== false;
|
|
2388
2871
|
const errorOnExist = options?.errorOnExist ?? false;
|
|
2389
2872
|
const dereference = options?.dereference ?? false;
|
|
@@ -2402,7 +2885,7 @@ var VFSFileSystem = class {
|
|
|
2402
2885
|
for (const entry of entries) {
|
|
2403
2886
|
const srcChild = join(src, entry.name);
|
|
2404
2887
|
const destChild = join(dest, entry.name);
|
|
2405
|
-
await this.
|
|
2888
|
+
await this._cpAsync(srcChild, destChild, options);
|
|
2406
2889
|
}
|
|
2407
2890
|
} else if (srcStat.isSymbolicLink() && !dereference) {
|
|
2408
2891
|
const target = await this.promises.readlink(src);
|
|
@@ -2437,47 +2920,65 @@ var VFSFileSystem = class {
|
|
|
2437
2920
|
}
|
|
2438
2921
|
}
|
|
2439
2922
|
truncateSync(filePath, len) {
|
|
2440
|
-
truncateSync(this._sync, filePath, len);
|
|
2923
|
+
truncateSync(this._sync, toPathString(filePath), len);
|
|
2441
2924
|
}
|
|
2442
2925
|
accessSync(filePath, mode) {
|
|
2443
|
-
accessSync(this._sync, filePath, mode);
|
|
2926
|
+
accessSync(this._sync, toPathString(filePath), mode);
|
|
2444
2927
|
}
|
|
2445
2928
|
realpathSync(filePath) {
|
|
2446
|
-
return realpathSync(this._sync, filePath);
|
|
2929
|
+
return realpathSync(this._sync, toPathString(filePath));
|
|
2447
2930
|
}
|
|
2448
2931
|
chmodSync(filePath, mode) {
|
|
2932
|
+
chmodSync(this._sync, toPathString(filePath), mode);
|
|
2933
|
+
}
|
|
2934
|
+
/** Like chmodSync but operates on the symlink itself. In this VFS, delegates to chmodSync. */
|
|
2935
|
+
lchmodSync(filePath, mode) {
|
|
2449
2936
|
chmodSync(this._sync, filePath, mode);
|
|
2450
2937
|
}
|
|
2938
|
+
/** chmod on an open file descriptor. No-op in this VFS (permissions are cosmetic). */
|
|
2939
|
+
fchmodSync(_fd, _mode) {
|
|
2940
|
+
}
|
|
2451
2941
|
chownSync(filePath, uid, gid) {
|
|
2942
|
+
chownSync(this._sync, toPathString(filePath), uid, gid);
|
|
2943
|
+
}
|
|
2944
|
+
/** Like chownSync but operates on the symlink itself. In this VFS, delegates to chownSync. */
|
|
2945
|
+
lchownSync(filePath, uid, gid) {
|
|
2452
2946
|
chownSync(this._sync, filePath, uid, gid);
|
|
2453
2947
|
}
|
|
2948
|
+
/** chown on an open file descriptor. No-op in this VFS (permissions are cosmetic). */
|
|
2949
|
+
fchownSync(_fd, _uid, _gid) {
|
|
2950
|
+
}
|
|
2454
2951
|
utimesSync(filePath, atime, mtime) {
|
|
2952
|
+
utimesSync(this._sync, toPathString(filePath), atime, mtime);
|
|
2953
|
+
}
|
|
2954
|
+
/** Like utimesSync but operates on the symlink itself. In this VFS, delegates to utimesSync. */
|
|
2955
|
+
lutimesSync(filePath, atime, mtime) {
|
|
2455
2956
|
utimesSync(this._sync, filePath, atime, mtime);
|
|
2456
2957
|
}
|
|
2457
2958
|
symlinkSync(target, linkPath, type) {
|
|
2458
|
-
symlinkSync(this._sync, target, linkPath);
|
|
2959
|
+
symlinkSync(this._sync, toPathString(target), toPathString(linkPath));
|
|
2459
2960
|
}
|
|
2460
2961
|
readlinkSync(filePath, options) {
|
|
2461
|
-
return readlinkSync(this._sync, filePath, options);
|
|
2962
|
+
return readlinkSync(this._sync, toPathString(filePath), options);
|
|
2462
2963
|
}
|
|
2463
2964
|
linkSync(existingPath, newPath) {
|
|
2464
|
-
linkSync(this._sync, existingPath, newPath);
|
|
2965
|
+
linkSync(this._sync, toPathString(existingPath), toPathString(newPath));
|
|
2465
2966
|
}
|
|
2466
2967
|
mkdtempSync(prefix) {
|
|
2467
2968
|
return mkdtempSync(this._sync, prefix);
|
|
2468
2969
|
}
|
|
2469
2970
|
// ---- File descriptor sync methods ----
|
|
2470
2971
|
openSync(filePath, flags = "r", mode) {
|
|
2471
|
-
return openSync(this._sync, filePath, flags);
|
|
2972
|
+
return openSync(this._sync, toPathString(filePath), flags);
|
|
2472
2973
|
}
|
|
2473
2974
|
closeSync(fd) {
|
|
2474
2975
|
closeSync(this._sync, fd);
|
|
2475
2976
|
}
|
|
2476
|
-
readSync(fd,
|
|
2477
|
-
return readSync(this._sync, fd,
|
|
2977
|
+
readSync(fd, bufferOrOptions, offsetOrOptions, length, position) {
|
|
2978
|
+
return readSync(this._sync, fd, bufferOrOptions, offsetOrOptions, length, position);
|
|
2478
2979
|
}
|
|
2479
|
-
writeSync(fd, bufferOrString,
|
|
2480
|
-
return writeSyncFd(this._sync, fd, bufferOrString,
|
|
2980
|
+
writeSync(fd, bufferOrString, offsetOrPositionOrOptions, lengthOrEncoding, position) {
|
|
2981
|
+
return writeSyncFd(this._sync, fd, bufferOrString, offsetOrPositionOrOptions, lengthOrEncoding, position);
|
|
2481
2982
|
}
|
|
2482
2983
|
fstatSync(fd) {
|
|
2483
2984
|
return fstatSync(this._sync, fd);
|
|
@@ -2488,6 +2989,65 @@ var VFSFileSystem = class {
|
|
|
2488
2989
|
fdatasyncSync(fd) {
|
|
2489
2990
|
fdatasyncSync(this._sync, fd);
|
|
2490
2991
|
}
|
|
2992
|
+
fsyncSync(fd) {
|
|
2993
|
+
fdatasyncSync(this._sync, fd);
|
|
2994
|
+
}
|
|
2995
|
+
// ---- Vector I/O methods ----
|
|
2996
|
+
readvSync(fd, buffers, position) {
|
|
2997
|
+
let totalRead = 0;
|
|
2998
|
+
let pos = position ?? null;
|
|
2999
|
+
for (const buf of buffers) {
|
|
3000
|
+
const bytesRead = this.readSync(fd, buf, 0, buf.byteLength, pos);
|
|
3001
|
+
totalRead += bytesRead;
|
|
3002
|
+
if (pos !== null) pos += bytesRead;
|
|
3003
|
+
if (bytesRead < buf.byteLength) break;
|
|
3004
|
+
}
|
|
3005
|
+
return totalRead;
|
|
3006
|
+
}
|
|
3007
|
+
writevSync(fd, buffers, position) {
|
|
3008
|
+
let totalWritten = 0;
|
|
3009
|
+
let pos = position ?? null;
|
|
3010
|
+
for (const buf of buffers) {
|
|
3011
|
+
const bytesWritten = this.writeSync(fd, buf, 0, buf.byteLength, pos);
|
|
3012
|
+
totalWritten += bytesWritten;
|
|
3013
|
+
if (pos !== null) pos += bytesWritten;
|
|
3014
|
+
}
|
|
3015
|
+
return totalWritten;
|
|
3016
|
+
}
|
|
3017
|
+
readv(fd, buffers, positionOrCallback, callback) {
|
|
3018
|
+
let pos;
|
|
3019
|
+
let cb;
|
|
3020
|
+
if (typeof positionOrCallback === "function") {
|
|
3021
|
+
pos = void 0;
|
|
3022
|
+
cb = positionOrCallback;
|
|
3023
|
+
} else {
|
|
3024
|
+
pos = positionOrCallback;
|
|
3025
|
+
cb = callback;
|
|
3026
|
+
}
|
|
3027
|
+
try {
|
|
3028
|
+
const bytesRead = this.readvSync(fd, buffers, pos);
|
|
3029
|
+
cb(null, bytesRead, buffers);
|
|
3030
|
+
} catch (err) {
|
|
3031
|
+
cb(err);
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
writev(fd, buffers, positionOrCallback, callback) {
|
|
3035
|
+
let pos;
|
|
3036
|
+
let cb;
|
|
3037
|
+
if (typeof positionOrCallback === "function") {
|
|
3038
|
+
pos = void 0;
|
|
3039
|
+
cb = positionOrCallback;
|
|
3040
|
+
} else {
|
|
3041
|
+
pos = positionOrCallback;
|
|
3042
|
+
cb = callback;
|
|
3043
|
+
}
|
|
3044
|
+
try {
|
|
3045
|
+
const bytesWritten = this.writevSync(fd, buffers, pos);
|
|
3046
|
+
cb(null, bytesWritten, buffers);
|
|
3047
|
+
} catch (err) {
|
|
3048
|
+
cb(err);
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
2491
3051
|
// ---- statfs methods ----
|
|
2492
3052
|
statfsSync(_path) {
|
|
2493
3053
|
return {
|
|
@@ -2515,22 +3075,29 @@ var VFSFileSystem = class {
|
|
|
2515
3075
|
}
|
|
2516
3076
|
// ---- Watch methods ----
|
|
2517
3077
|
watch(filePath, options, listener) {
|
|
2518
|
-
return watch(this.ns, filePath, options, listener);
|
|
3078
|
+
return watch(this.ns, toPathString(filePath), options, listener);
|
|
2519
3079
|
}
|
|
2520
3080
|
watchFile(filePath, optionsOrListener, listener) {
|
|
2521
|
-
watchFile(this.ns, this._sync, filePath, optionsOrListener, listener);
|
|
3081
|
+
watchFile(this.ns, this._sync, toPathString(filePath), optionsOrListener, listener);
|
|
2522
3082
|
}
|
|
2523
3083
|
unwatchFile(filePath, listener) {
|
|
2524
|
-
unwatchFile(this.ns, filePath, listener);
|
|
3084
|
+
unwatchFile(this.ns, toPathString(filePath), listener);
|
|
3085
|
+
}
|
|
3086
|
+
// ---- openAsBlob (Node.js 19+) ----
|
|
3087
|
+
async openAsBlob(filePath, options) {
|
|
3088
|
+
const data = await this.promises.readFile(filePath);
|
|
3089
|
+
const bytes = data instanceof Uint8Array ? data : new TextEncoder().encode(data);
|
|
3090
|
+
return new Blob([bytes], { type: options?.type ?? "" });
|
|
2525
3091
|
}
|
|
2526
3092
|
// ---- Stream methods ----
|
|
2527
3093
|
createReadStream(filePath, options) {
|
|
2528
|
-
const opts = typeof options === "string" ? {
|
|
3094
|
+
const opts = typeof options === "string" ? { } : options;
|
|
2529
3095
|
const start = opts?.start ?? 0;
|
|
2530
3096
|
const end = opts?.end;
|
|
2531
3097
|
const highWaterMark = opts?.highWaterMark ?? 64 * 1024;
|
|
2532
3098
|
let position = start;
|
|
2533
3099
|
let handle = null;
|
|
3100
|
+
let finished = false;
|
|
2534
3101
|
const cleanup = async () => {
|
|
2535
3102
|
if (handle) {
|
|
2536
3103
|
try {
|
|
@@ -2540,69 +3107,57 @@ var VFSFileSystem = class {
|
|
|
2540
3107
|
handle = null;
|
|
2541
3108
|
}
|
|
2542
3109
|
};
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
await cleanup();
|
|
2552
|
-
controller.close();
|
|
2553
|
-
return;
|
|
2554
|
-
}
|
|
2555
|
-
const buffer = new Uint8Array(readLen);
|
|
2556
|
-
const { bytesRead } = await handle.read(buffer, 0, readLen, position);
|
|
2557
|
-
if (bytesRead === 0) {
|
|
2558
|
-
await cleanup();
|
|
2559
|
-
controller.close();
|
|
2560
|
-
return;
|
|
2561
|
-
}
|
|
2562
|
-
controller.enqueue(buffer.subarray(0, bytesRead));
|
|
2563
|
-
position += bytesRead;
|
|
2564
|
-
if (end !== void 0 && position > end) {
|
|
2565
|
-
await cleanup();
|
|
2566
|
-
controller.close();
|
|
2567
|
-
}
|
|
2568
|
-
} catch (err) {
|
|
2569
|
-
await cleanup();
|
|
2570
|
-
controller.error(err);
|
|
2571
|
-
}
|
|
2572
|
-
},
|
|
2573
|
-
cancel: async () => {
|
|
3110
|
+
const readFn = async () => {
|
|
3111
|
+
if (finished) return { done: true };
|
|
3112
|
+
if (!handle) {
|
|
3113
|
+
handle = await this.promises.open(toPathString(filePath), opts?.flags ?? "r");
|
|
3114
|
+
}
|
|
3115
|
+
const readLen = end !== void 0 ? Math.min(highWaterMark, end - position + 1) : highWaterMark;
|
|
3116
|
+
if (readLen <= 0) {
|
|
3117
|
+
finished = true;
|
|
2574
3118
|
await cleanup();
|
|
3119
|
+
return { done: true };
|
|
2575
3120
|
}
|
|
2576
|
-
|
|
3121
|
+
const buffer = new Uint8Array(readLen);
|
|
3122
|
+
const { bytesRead } = await handle.read(buffer, 0, readLen, position);
|
|
3123
|
+
if (bytesRead === 0) {
|
|
3124
|
+
finished = true;
|
|
3125
|
+
await cleanup();
|
|
3126
|
+
return { done: true };
|
|
3127
|
+
}
|
|
3128
|
+
position += bytesRead;
|
|
3129
|
+
if (end !== void 0 && position > end) {
|
|
3130
|
+
finished = true;
|
|
3131
|
+
await cleanup();
|
|
3132
|
+
return { done: false, value: buffer.subarray(0, bytesRead) };
|
|
3133
|
+
}
|
|
3134
|
+
return { done: false, value: buffer.subarray(0, bytesRead) };
|
|
3135
|
+
};
|
|
3136
|
+
const stream = new NodeReadable(readFn, cleanup);
|
|
3137
|
+
stream.path = toPathString(filePath);
|
|
3138
|
+
return stream;
|
|
2577
3139
|
}
|
|
2578
3140
|
createWriteStream(filePath, options) {
|
|
2579
3141
|
const opts = typeof options === "string" ? { } : options;
|
|
2580
3142
|
let position = opts?.start ?? 0;
|
|
2581
3143
|
let handle = null;
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
if (
|
|
2592
|
-
|
|
2593
|
-
await handle.sync();
|
|
2594
|
-
}
|
|
2595
|
-
await handle.close();
|
|
2596
|
-
handle = null;
|
|
2597
|
-
}
|
|
2598
|
-
},
|
|
2599
|
-
abort: async () => {
|
|
2600
|
-
if (handle) {
|
|
2601
|
-
await handle.close();
|
|
2602
|
-
handle = null;
|
|
3144
|
+
const writeFn = async (chunk) => {
|
|
3145
|
+
if (!handle) {
|
|
3146
|
+
handle = await this.promises.open(toPathString(filePath), opts?.flags ?? "w");
|
|
3147
|
+
}
|
|
3148
|
+
const { bytesWritten } = await handle.write(chunk, 0, chunk.byteLength, position);
|
|
3149
|
+
position += bytesWritten;
|
|
3150
|
+
};
|
|
3151
|
+
const closeFn = async () => {
|
|
3152
|
+
if (handle) {
|
|
3153
|
+
if (opts?.flush) {
|
|
3154
|
+
await handle.sync();
|
|
2603
3155
|
}
|
|
3156
|
+
await handle.close();
|
|
3157
|
+
handle = null;
|
|
2604
3158
|
}
|
|
2605
|
-
}
|
|
3159
|
+
};
|
|
3160
|
+
return new NodeWritable(toPathString(filePath), writeFn, closeFn);
|
|
2606
3161
|
}
|
|
2607
3162
|
// ---- Utility methods ----
|
|
2608
3163
|
flushSync() {
|
|
@@ -2708,6 +3263,208 @@ var VFSFileSystem = class {
|
|
|
2708
3263
|
}
|
|
2709
3264
|
return this.readyPromise;
|
|
2710
3265
|
}
|
|
3266
|
+
readFile(filePath, optionsOrCallback, callback) {
|
|
3267
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3268
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3269
|
+
this.promises.readFile(filePath, opts).then(
|
|
3270
|
+
(result) => setTimeout(() => cb(null, result), 0),
|
|
3271
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3272
|
+
);
|
|
3273
|
+
}
|
|
3274
|
+
writeFile(filePath, data, optionsOrCallback, callback) {
|
|
3275
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3276
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3277
|
+
this.promises.writeFile(filePath, data, opts).then(
|
|
3278
|
+
() => setTimeout(() => cb(null), 0),
|
|
3279
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3280
|
+
);
|
|
3281
|
+
}
|
|
3282
|
+
appendFile(filePath, data, optionsOrCallback, callback) {
|
|
3283
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3284
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3285
|
+
this.promises.appendFile(filePath, data, opts).then(
|
|
3286
|
+
() => setTimeout(() => cb(null), 0),
|
|
3287
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3288
|
+
);
|
|
3289
|
+
}
|
|
3290
|
+
mkdir(filePath, optionsOrCallback, callback) {
|
|
3291
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3292
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3293
|
+
this.promises.mkdir(filePath, opts).then(
|
|
3294
|
+
(result) => setTimeout(() => cb(null, result), 0),
|
|
3295
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3296
|
+
);
|
|
3297
|
+
}
|
|
3298
|
+
rmdir(filePath, optionsOrCallback, callback) {
|
|
3299
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3300
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3301
|
+
this.promises.rmdir(filePath, opts).then(
|
|
3302
|
+
() => setTimeout(() => cb(null), 0),
|
|
3303
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3304
|
+
);
|
|
3305
|
+
}
|
|
3306
|
+
rm(filePath, optionsOrCallback, callback) {
|
|
3307
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3308
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3309
|
+
this.promises.rm(filePath, opts).then(
|
|
3310
|
+
() => setTimeout(() => cb(null), 0),
|
|
3311
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3312
|
+
);
|
|
3313
|
+
}
|
|
3314
|
+
unlink(filePath, callback) {
|
|
3315
|
+
this.promises.unlink(filePath).then(
|
|
3316
|
+
() => setTimeout(() => callback(null), 0),
|
|
3317
|
+
(err) => setTimeout(() => callback(err), 0)
|
|
3318
|
+
);
|
|
3319
|
+
}
|
|
3320
|
+
readdir(filePath, optionsOrCallback, callback) {
|
|
3321
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3322
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3323
|
+
this.promises.readdir(filePath, opts).then(
|
|
3324
|
+
(result) => setTimeout(() => cb(null, result), 0),
|
|
3325
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3326
|
+
);
|
|
3327
|
+
}
|
|
3328
|
+
stat(filePath, optionsOrCallback, callback) {
|
|
3329
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3330
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3331
|
+
this.promises.stat(filePath, opts).then(
|
|
3332
|
+
(result) => setTimeout(() => cb(null, result), 0),
|
|
3333
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3334
|
+
);
|
|
3335
|
+
}
|
|
3336
|
+
lstat(filePath, optionsOrCallback, callback) {
|
|
3337
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3338
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3339
|
+
this.promises.lstat(filePath, opts).then(
|
|
3340
|
+
(result) => setTimeout(() => cb(null, result), 0),
|
|
3341
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3342
|
+
);
|
|
3343
|
+
}
|
|
3344
|
+
access(filePath, modeOrCallback, callback) {
|
|
3345
|
+
const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
|
|
3346
|
+
const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
|
|
3347
|
+
this.promises.access(filePath, mode).then(
|
|
3348
|
+
() => setTimeout(() => cb(null), 0),
|
|
3349
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3350
|
+
);
|
|
3351
|
+
}
|
|
3352
|
+
rename(oldPath, newPath, callback) {
|
|
3353
|
+
this.promises.rename(oldPath, newPath).then(
|
|
3354
|
+
() => setTimeout(() => callback(null), 0),
|
|
3355
|
+
(err) => setTimeout(() => callback(err), 0)
|
|
3356
|
+
);
|
|
3357
|
+
}
|
|
3358
|
+
copyFile(src, dest, modeOrCallback, callback) {
|
|
3359
|
+
const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
|
|
3360
|
+
const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
|
|
3361
|
+
this.promises.copyFile(src, dest, mode).then(
|
|
3362
|
+
() => setTimeout(() => cb(null), 0),
|
|
3363
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3364
|
+
);
|
|
3365
|
+
}
|
|
3366
|
+
truncate(filePath, lenOrCallback, callback) {
|
|
3367
|
+
const cb = typeof lenOrCallback === "function" ? lenOrCallback : callback;
|
|
3368
|
+
const len = typeof lenOrCallback === "function" ? void 0 : lenOrCallback;
|
|
3369
|
+
this.promises.truncate(filePath, len).then(
|
|
3370
|
+
() => setTimeout(() => cb(null), 0),
|
|
3371
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3372
|
+
);
|
|
3373
|
+
}
|
|
3374
|
+
realpath(filePath, callback) {
|
|
3375
|
+
this.promises.realpath(filePath).then(
|
|
3376
|
+
(result) => setTimeout(() => callback(null, result), 0),
|
|
3377
|
+
(err) => setTimeout(() => callback(err), 0)
|
|
3378
|
+
);
|
|
3379
|
+
}
|
|
3380
|
+
chmod(filePath, mode, callback) {
|
|
3381
|
+
this.promises.chmod(filePath, mode).then(
|
|
3382
|
+
() => setTimeout(() => callback(null), 0),
|
|
3383
|
+
(err) => setTimeout(() => callback(err), 0)
|
|
3384
|
+
);
|
|
3385
|
+
}
|
|
3386
|
+
chown(filePath, uid, gid, callback) {
|
|
3387
|
+
this.promises.chown(filePath, uid, gid).then(
|
|
3388
|
+
() => setTimeout(() => callback(null), 0),
|
|
3389
|
+
(err) => setTimeout(() => callback(err), 0)
|
|
3390
|
+
);
|
|
3391
|
+
}
|
|
3392
|
+
utimes(filePath, atime, mtime, callback) {
|
|
3393
|
+
this.promises.utimes(filePath, atime, mtime).then(
|
|
3394
|
+
() => setTimeout(() => callback(null), 0),
|
|
3395
|
+
(err) => setTimeout(() => callback(err), 0)
|
|
3396
|
+
);
|
|
3397
|
+
}
|
|
3398
|
+
symlink(target, linkPath, typeOrCallback, callback) {
|
|
3399
|
+
const cb = typeof typeOrCallback === "function" ? typeOrCallback : callback;
|
|
3400
|
+
const type = typeof typeOrCallback === "function" ? void 0 : typeOrCallback;
|
|
3401
|
+
this.promises.symlink(target, linkPath, type).then(
|
|
3402
|
+
() => setTimeout(() => cb(null), 0),
|
|
3403
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3404
|
+
);
|
|
3405
|
+
}
|
|
3406
|
+
readlink(filePath, optionsOrCallback, callback) {
|
|
3407
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3408
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3409
|
+
this.promises.readlink(filePath, opts).then(
|
|
3410
|
+
(result) => setTimeout(() => cb(null, result), 0),
|
|
3411
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3412
|
+
);
|
|
3413
|
+
}
|
|
3414
|
+
link(existingPath, newPath, callback) {
|
|
3415
|
+
this.promises.link(existingPath, newPath).then(
|
|
3416
|
+
() => setTimeout(() => callback(null), 0),
|
|
3417
|
+
(err) => setTimeout(() => callback(err), 0)
|
|
3418
|
+
);
|
|
3419
|
+
}
|
|
3420
|
+
open(filePath, flags, modeOrCallback, callback) {
|
|
3421
|
+
const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
|
|
3422
|
+
const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
|
|
3423
|
+
this.promises.open(filePath, flags, mode).then(
|
|
3424
|
+
(handle) => setTimeout(() => cb(null, handle.fd), 0),
|
|
3425
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3426
|
+
);
|
|
3427
|
+
}
|
|
3428
|
+
mkdtemp(prefix, callback) {
|
|
3429
|
+
this.promises.mkdtemp(prefix).then(
|
|
3430
|
+
(result) => setTimeout(() => callback(null, result), 0),
|
|
3431
|
+
(err) => setTimeout(() => callback(err), 0)
|
|
3432
|
+
);
|
|
3433
|
+
}
|
|
3434
|
+
cp(src, dest, optionsOrCallback, callback) {
|
|
3435
|
+
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
3436
|
+
const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
|
|
3437
|
+
if (cb) {
|
|
3438
|
+
this._cpAsync(src, dest, opts).then(
|
|
3439
|
+
() => setTimeout(() => cb(null), 0),
|
|
3440
|
+
(err) => setTimeout(() => cb(err), 0)
|
|
3441
|
+
);
|
|
3442
|
+
return;
|
|
3443
|
+
}
|
|
3444
|
+
return this._cpAsync(src, dest, opts);
|
|
3445
|
+
}
|
|
3446
|
+
fdatasync(fd, callback) {
|
|
3447
|
+
try {
|
|
3448
|
+
this.fdatasyncSync(fd);
|
|
3449
|
+
callback(null);
|
|
3450
|
+
} catch (err) {
|
|
3451
|
+
callback(err);
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
fsync(fd, callback) {
|
|
3455
|
+
try {
|
|
3456
|
+
this.fsyncSync(fd);
|
|
3457
|
+
callback(null);
|
|
3458
|
+
} catch (err) {
|
|
3459
|
+
callback(err);
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
exists(filePath, callback) {
|
|
3463
|
+
this.promises.exists(filePath).then(
|
|
3464
|
+
(result) => setTimeout(() => callback(result), 0),
|
|
3465
|
+
() => setTimeout(() => callback(false), 0)
|
|
3466
|
+
);
|
|
3467
|
+
}
|
|
2711
3468
|
};
|
|
2712
3469
|
var VFSPromises = class {
|
|
2713
3470
|
_async;
|
|
@@ -2717,136 +3474,161 @@ var VFSPromises = class {
|
|
|
2717
3474
|
this._ns = ns;
|
|
2718
3475
|
}
|
|
2719
3476
|
readFile(filePath, options) {
|
|
2720
|
-
return readFile(this._async, filePath, options);
|
|
3477
|
+
return readFile(this._async, toPathString(filePath), options);
|
|
2721
3478
|
}
|
|
2722
3479
|
writeFile(filePath, data, options) {
|
|
2723
|
-
return writeFile(this._async, filePath, data, options);
|
|
3480
|
+
return writeFile(this._async, toPathString(filePath), data, options);
|
|
2724
3481
|
}
|
|
2725
3482
|
appendFile(filePath, data, options) {
|
|
2726
|
-
return appendFile(this._async, filePath, data);
|
|
3483
|
+
return appendFile(this._async, toPathString(filePath), data);
|
|
2727
3484
|
}
|
|
2728
3485
|
mkdir(filePath, options) {
|
|
2729
|
-
return mkdir(this._async, filePath, options);
|
|
3486
|
+
return mkdir(this._async, toPathString(filePath), options);
|
|
2730
3487
|
}
|
|
2731
3488
|
rmdir(filePath, options) {
|
|
2732
|
-
return rmdir(this._async, filePath, options);
|
|
3489
|
+
return rmdir(this._async, toPathString(filePath), options);
|
|
2733
3490
|
}
|
|
2734
3491
|
rm(filePath, options) {
|
|
2735
|
-
return rm(this._async, filePath, options);
|
|
3492
|
+
return rm(this._async, toPathString(filePath), options);
|
|
2736
3493
|
}
|
|
2737
3494
|
unlink(filePath) {
|
|
2738
|
-
return unlink(this._async, filePath);
|
|
3495
|
+
return unlink(this._async, toPathString(filePath));
|
|
2739
3496
|
}
|
|
2740
3497
|
readdir(filePath, options) {
|
|
2741
|
-
return readdir(this._async, filePath, options);
|
|
3498
|
+
return readdir(this._async, toPathString(filePath), options);
|
|
2742
3499
|
}
|
|
2743
3500
|
glob(pattern, options) {
|
|
2744
3501
|
return glob(this._async, pattern, options);
|
|
2745
3502
|
}
|
|
2746
3503
|
stat(filePath, options) {
|
|
2747
|
-
return stat(this._async, filePath, options);
|
|
3504
|
+
return stat(this._async, toPathString(filePath), options);
|
|
2748
3505
|
}
|
|
2749
3506
|
lstat(filePath, options) {
|
|
2750
|
-
return lstat(this._async, filePath, options);
|
|
3507
|
+
return lstat(this._async, toPathString(filePath), options);
|
|
2751
3508
|
}
|
|
2752
3509
|
access(filePath, mode) {
|
|
2753
|
-
return access(this._async, filePath, mode);
|
|
3510
|
+
return access(this._async, toPathString(filePath), mode);
|
|
2754
3511
|
}
|
|
2755
3512
|
rename(oldPath, newPath) {
|
|
2756
|
-
return rename(this._async, oldPath, newPath);
|
|
3513
|
+
return rename(this._async, toPathString(oldPath), toPathString(newPath));
|
|
2757
3514
|
}
|
|
2758
3515
|
copyFile(src, dest, mode) {
|
|
2759
|
-
return copyFile(this._async, src, dest, mode);
|
|
3516
|
+
return copyFile(this._async, toPathString(src), toPathString(dest), mode);
|
|
2760
3517
|
}
|
|
2761
3518
|
async cp(src, dest, options) {
|
|
3519
|
+
const srcPath = toPathString(src);
|
|
3520
|
+
const destPath = toPathString(dest);
|
|
2762
3521
|
const force = options?.force !== false;
|
|
2763
3522
|
const errorOnExist = options?.errorOnExist ?? false;
|
|
2764
3523
|
const dereference = options?.dereference ?? false;
|
|
2765
3524
|
const preserveTimestamps = options?.preserveTimestamps ?? false;
|
|
2766
|
-
const srcStat = dereference ? await this.stat(
|
|
3525
|
+
const srcStat = dereference ? await this.stat(srcPath) : await this.lstat(srcPath);
|
|
2767
3526
|
if (srcStat.isDirectory()) {
|
|
2768
3527
|
if (!options?.recursive) {
|
|
2769
|
-
throw createError("EISDIR", "cp",
|
|
3528
|
+
throw createError("EISDIR", "cp", srcPath);
|
|
2770
3529
|
}
|
|
2771
3530
|
try {
|
|
2772
|
-
await this.mkdir(
|
|
3531
|
+
await this.mkdir(destPath, { recursive: true });
|
|
2773
3532
|
} catch (e) {
|
|
2774
3533
|
if (e.code !== "EEXIST") throw e;
|
|
2775
3534
|
}
|
|
2776
|
-
const entries = await this.readdir(
|
|
3535
|
+
const entries = await this.readdir(srcPath, { withFileTypes: true });
|
|
2777
3536
|
for (const entry of entries) {
|
|
2778
|
-
const srcChild = join(
|
|
2779
|
-
const destChild = join(
|
|
3537
|
+
const srcChild = join(srcPath, entry.name);
|
|
3538
|
+
const destChild = join(destPath, entry.name);
|
|
2780
3539
|
await this.cp(srcChild, destChild, options);
|
|
2781
3540
|
}
|
|
2782
3541
|
} else if (srcStat.isSymbolicLink() && !dereference) {
|
|
2783
|
-
const target = await this.readlink(
|
|
3542
|
+
const target = await this.readlink(srcPath);
|
|
2784
3543
|
let destExists = false;
|
|
2785
3544
|
try {
|
|
2786
|
-
await this.lstat(
|
|
3545
|
+
await this.lstat(destPath);
|
|
2787
3546
|
destExists = true;
|
|
2788
3547
|
} catch {
|
|
2789
3548
|
}
|
|
2790
3549
|
if (destExists) {
|
|
2791
|
-
if (errorOnExist) throw createError("EEXIST", "cp",
|
|
3550
|
+
if (errorOnExist) throw createError("EEXIST", "cp", destPath);
|
|
2792
3551
|
if (!force) return;
|
|
2793
|
-
await this.unlink(
|
|
3552
|
+
await this.unlink(destPath);
|
|
2794
3553
|
}
|
|
2795
|
-
await this.symlink(target,
|
|
3554
|
+
await this.symlink(target, destPath);
|
|
2796
3555
|
} else {
|
|
2797
3556
|
let destExists = false;
|
|
2798
3557
|
try {
|
|
2799
|
-
await this.lstat(
|
|
3558
|
+
await this.lstat(destPath);
|
|
2800
3559
|
destExists = true;
|
|
2801
3560
|
} catch {
|
|
2802
3561
|
}
|
|
2803
3562
|
if (destExists) {
|
|
2804
|
-
if (errorOnExist) throw createError("EEXIST", "cp",
|
|
3563
|
+
if (errorOnExist) throw createError("EEXIST", "cp", destPath);
|
|
2805
3564
|
if (!force) return;
|
|
2806
3565
|
}
|
|
2807
|
-
await this.copyFile(
|
|
3566
|
+
await this.copyFile(srcPath, destPath, errorOnExist ? constants.COPYFILE_EXCL : 0);
|
|
2808
3567
|
}
|
|
2809
3568
|
if (preserveTimestamps) {
|
|
2810
|
-
const st = await this.stat(
|
|
2811
|
-
await this.utimes(
|
|
3569
|
+
const st = await this.stat(srcPath);
|
|
3570
|
+
await this.utimes(destPath, st.atime, st.mtime);
|
|
2812
3571
|
}
|
|
2813
3572
|
}
|
|
2814
3573
|
truncate(filePath, len) {
|
|
2815
|
-
return truncate(this._async, filePath, len);
|
|
3574
|
+
return truncate(this._async, toPathString(filePath), len);
|
|
2816
3575
|
}
|
|
2817
3576
|
realpath(filePath) {
|
|
2818
|
-
return realpath(this._async, filePath);
|
|
3577
|
+
return realpath(this._async, toPathString(filePath));
|
|
2819
3578
|
}
|
|
2820
3579
|
exists(filePath) {
|
|
2821
|
-
return exists(this._async, filePath);
|
|
3580
|
+
return exists(this._async, toPathString(filePath));
|
|
2822
3581
|
}
|
|
2823
3582
|
chmod(filePath, mode) {
|
|
3583
|
+
return chmod(this._async, toPathString(filePath), mode);
|
|
3584
|
+
}
|
|
3585
|
+
/** Like chmod but operates on the symlink itself. In this VFS, delegates to chmod. */
|
|
3586
|
+
lchmod(filePath, mode) {
|
|
2824
3587
|
return chmod(this._async, filePath, mode);
|
|
2825
3588
|
}
|
|
3589
|
+
/** chmod on an open file descriptor. No-op in this VFS (permissions are cosmetic). */
|
|
3590
|
+
async fchmod(_fd, _mode) {
|
|
3591
|
+
}
|
|
2826
3592
|
chown(filePath, uid, gid) {
|
|
3593
|
+
return chown(this._async, toPathString(filePath), uid, gid);
|
|
3594
|
+
}
|
|
3595
|
+
/** Like chown but operates on the symlink itself. In this VFS, delegates to chown. */
|
|
3596
|
+
lchown(filePath, uid, gid) {
|
|
2827
3597
|
return chown(this._async, filePath, uid, gid);
|
|
2828
3598
|
}
|
|
3599
|
+
/** chown on an open file descriptor. No-op in this VFS (permissions are cosmetic). */
|
|
3600
|
+
async fchown(_fd, _uid, _gid) {
|
|
3601
|
+
}
|
|
2829
3602
|
utimes(filePath, atime, mtime) {
|
|
3603
|
+
return utimes(this._async, toPathString(filePath), atime, mtime);
|
|
3604
|
+
}
|
|
3605
|
+
/** Like utimes but operates on the symlink itself. In this VFS, delegates to utimes. */
|
|
3606
|
+
lutimes(filePath, atime, mtime) {
|
|
2830
3607
|
return utimes(this._async, filePath, atime, mtime);
|
|
2831
3608
|
}
|
|
2832
3609
|
symlink(target, linkPath, type) {
|
|
2833
|
-
return symlink(this._async, target, linkPath);
|
|
3610
|
+
return symlink(this._async, toPathString(target), toPathString(linkPath));
|
|
2834
3611
|
}
|
|
2835
3612
|
readlink(filePath, options) {
|
|
2836
|
-
return readlink(this._async, filePath, options);
|
|
3613
|
+
return readlink(this._async, toPathString(filePath), options);
|
|
2837
3614
|
}
|
|
2838
3615
|
link(existingPath, newPath) {
|
|
2839
|
-
return link(this._async, existingPath, newPath);
|
|
3616
|
+
return link(this._async, toPathString(existingPath), toPathString(newPath));
|
|
2840
3617
|
}
|
|
2841
3618
|
open(filePath, flags, mode) {
|
|
2842
|
-
return open(this._async, filePath, flags);
|
|
3619
|
+
return open(this._async, toPathString(filePath), flags);
|
|
2843
3620
|
}
|
|
2844
3621
|
opendir(filePath) {
|
|
2845
|
-
return opendir(this._async, filePath);
|
|
3622
|
+
return opendir(this._async, toPathString(filePath));
|
|
2846
3623
|
}
|
|
2847
3624
|
mkdtemp(prefix) {
|
|
2848
3625
|
return mkdtemp(this._async, prefix);
|
|
2849
3626
|
}
|
|
3627
|
+
async openAsBlob(filePath, options) {
|
|
3628
|
+
const data = await this.readFile(filePath);
|
|
3629
|
+
const bytes = data instanceof Uint8Array ? data : new TextEncoder().encode(data);
|
|
3630
|
+
return new Blob([bytes], { type: options?.type ?? "" });
|
|
3631
|
+
}
|
|
2850
3632
|
async statfs(path) {
|
|
2851
3633
|
return {
|
|
2852
3634
|
type: 1447449377,
|
|
@@ -2866,6 +3648,12 @@ var VFSPromises = class {
|
|
|
2866
3648
|
async *watch(filePath, options) {
|
|
2867
3649
|
yield* watchAsync(this._ns, this._async, filePath, options);
|
|
2868
3650
|
}
|
|
3651
|
+
async fsync(_fd) {
|
|
3652
|
+
await this._async(OP.FSYNC, "");
|
|
3653
|
+
}
|
|
3654
|
+
async fdatasync(_fd) {
|
|
3655
|
+
await this._async(OP.FSYNC, "");
|
|
3656
|
+
}
|
|
2869
3657
|
async flush() {
|
|
2870
3658
|
await this._async(OP.FSYNC, "");
|
|
2871
3659
|
}
|
|
@@ -3699,8 +4487,7 @@ var VFSEngine = class {
|
|
|
3699
4487
|
const mode = DEFAULT_DIR_MODE & ~(this.umask & 511);
|
|
3700
4488
|
this.createInode(path, INODE_TYPE.DIRECTORY, mode, 0);
|
|
3701
4489
|
this.commitPending();
|
|
3702
|
-
|
|
3703
|
-
return { status: 0, data: pathBytes };
|
|
4490
|
+
return { status: 0, data: null };
|
|
3704
4491
|
}
|
|
3705
4492
|
mkdirRecursive(path) {
|
|
3706
4493
|
const parts = path.split("/").filter(Boolean);
|
|
@@ -4545,6 +5332,6 @@ function init() {
|
|
|
4545
5332
|
return getDefaultFS().init();
|
|
4546
5333
|
}
|
|
4547
5334
|
|
|
4548
|
-
export { FSError, VFSFileSystem, constants, createError, createFS, getDefaultFS, init, loadFromOPFS, path_exports as path, repairVFS, statusToError, unpackToOPFS };
|
|
5335
|
+
export { FSError, NodeReadable, NodeWritable, SimpleEventEmitter, VFSFileSystem, constants, createError, createFS, getDefaultFS, init, loadFromOPFS, path_exports as path, repairVFS, statusToError, unpackToOPFS };
|
|
4549
5336
|
//# sourceMappingURL=index.js.map
|
|
4550
5337
|
//# sourceMappingURL=index.js.map
|