@gjsify/fs 0.0.4 → 0.1.1
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/README.md +31 -2
- package/lib/esm/callback.js +251 -15
- package/lib/esm/dirent.js +47 -6
- package/lib/esm/encoding.js +2 -3
- package/lib/esm/errors.js +13 -0
- package/lib/esm/file-handle.js +108 -66
- package/lib/esm/fs-watcher.js +44 -7
- package/lib/esm/index.js +140 -5
- package/lib/esm/promises.js +290 -69
- package/lib/esm/read-stream.js +82 -57
- package/lib/esm/stats.js +138 -18
- package/lib/esm/sync.js +293 -44
- package/lib/esm/write-stream.js +4 -4
- package/lib/types/callback.d.ts +233 -0
- package/lib/types/dirent.d.ts +77 -0
- package/lib/types/encoding.d.ts +6 -0
- package/lib/types/errors.d.ts +7 -0
- package/lib/types/file-handle.d.ts +367 -0
- package/lib/types/fs-watcher.d.ts +17 -0
- package/lib/types/index.d.ts +149 -0
- package/lib/types/promises.d.ts +158 -0
- package/lib/types/read-stream.d.ts +21 -0
- package/lib/types/stats.d.ts +67 -0
- package/lib/types/sync.d.ts +109 -0
- package/lib/types/types/encoding-option.d.ts +2 -0
- package/lib/types/types/file-read-options.d.ts +15 -0
- package/lib/types/types/file-read-result.d.ts +4 -0
- package/lib/types/types/flag-and-open-mode.d.ts +5 -0
- package/lib/types/types/index.d.ts +6 -0
- package/lib/types/types/open-flags.d.ts +1 -0
- package/lib/types/types/read-options.d.ts +5 -0
- package/lib/types/utils.d.ts +2 -0
- package/lib/types/write-stream.d.ts +45 -0
- package/package.json +22 -35
- package/src/callback.spec.ts +284 -30
- package/src/callback.ts +352 -39
- package/src/dirent.ts +56 -8
- package/src/encoding.ts +7 -2
- package/src/errors.spec.ts +389 -0
- package/src/errors.ts +19 -0
- package/src/extended.spec.ts +706 -0
- package/src/file-handle.spec.ts +104 -23
- package/src/file-handle.ts +147 -79
- package/src/fs-watcher.ts +55 -8
- package/src/index.ts +146 -2
- package/src/new-apis.spec.ts +505 -0
- package/src/promises.spec.ts +651 -11
- package/src/promises.ts +353 -81
- package/src/read-stream.ts +98 -74
- package/src/stat.spec.ts +22 -14
- package/src/stats.ts +176 -75
- package/src/streams.spec.ts +455 -0
- package/src/symlink.spec.ts +176 -26
- package/src/sync.spec.ts +204 -32
- package/src/sync.ts +363 -58
- package/src/test.mts +7 -2
- package/src/types/encoding-option.ts +1 -1
- package/src/types/flag-and-open-mode.ts +1 -1
- package/src/types/read-options.ts +2 -2
- package/src/utils.ts +2 -0
- package/src/write-stream.ts +9 -7
- package/tsconfig.json +23 -10
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/callback.js +0 -112
- package/lib/cjs/dirent.js +0 -98
- package/lib/cjs/encoding.js +0 -34
- package/lib/cjs/file-handle.js +0 -444
- package/lib/cjs/fs-watcher.js +0 -50
- package/lib/cjs/index.js +0 -95
- package/lib/cjs/promises.js +0 -160
- package/lib/cjs/read-stream.js +0 -78
- package/lib/cjs/stats.js +0 -45
- package/lib/cjs/sync.js +0 -126
- package/lib/cjs/types/encoding-option.js +0 -0
- package/lib/cjs/types/file-read-options.js +0 -0
- package/lib/cjs/types/file-read-result.js +0 -0
- package/lib/cjs/types/flag-and-open-mode.js +0 -0
- package/lib/cjs/types/index.js +0 -6
- package/lib/cjs/types/open-flags.js +0 -0
- package/lib/cjs/types/read-options.js +0 -0
- package/lib/cjs/utils.js +0 -18
- package/lib/cjs/write-stream.js +0 -116
- package/test/watch.js +0 -1
- package/test.gjs.js +0 -35359
- package/test.gjs.js.map +0 -7
- package/test.gjs.mjs +0 -40534
- package/test.gjs.mjs.meta.json +0 -1
- package/test.node.js +0 -1479
- package/test.node.js.map +0 -7
- package/test.node.mjs +0 -710
- package/tsconfig.types.json +0 -8
package/lib/esm/file-handle.js
CHANGED
|
@@ -4,14 +4,52 @@ import { WriteStream } from "./write-stream.js";
|
|
|
4
4
|
import { Stats } from "./stats.js";
|
|
5
5
|
import { getEncodingFromOptions, encodeUint8Array } from "./encoding.js";
|
|
6
6
|
import GLib from "@girs/glib-2.0";
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
7
|
+
import Gio from "@girs/gio-2.0";
|
|
8
|
+
import { ReadableStream } from "node:stream/web";
|
|
9
|
+
import { Buffer } from "node:buffer";
|
|
10
|
+
const GLIB_FILE_ERROR_TO_NODE = {
|
|
11
|
+
0: "EEXIST",
|
|
12
|
+
1: "EISDIR",
|
|
13
|
+
2: "EACCES",
|
|
14
|
+
3: "ENAMETOOLONG",
|
|
15
|
+
4: "ENOENT",
|
|
16
|
+
5: "ENOTDIR",
|
|
17
|
+
6: "ENXIO",
|
|
18
|
+
7: "ENODEV",
|
|
19
|
+
8: "EROFS",
|
|
20
|
+
11: "ELOOP",
|
|
21
|
+
12: "ENOSPC",
|
|
22
|
+
13: "ENOMEM",
|
|
23
|
+
14: "EMFILE",
|
|
24
|
+
15: "ENFILE",
|
|
25
|
+
16: "EBADF",
|
|
26
|
+
17: "EINVAL",
|
|
27
|
+
18: "EPIPE",
|
|
28
|
+
21: "EIO",
|
|
29
|
+
22: "EPERM",
|
|
30
|
+
24: "EIO"
|
|
31
|
+
};
|
|
32
|
+
function mapOpenError(err, path) {
|
|
33
|
+
const gErr = err;
|
|
34
|
+
const msg = gErr?.message ?? "";
|
|
35
|
+
const code = GLIB_FILE_ERROR_TO_NODE[gErr?.code ?? -1] ?? "EIO";
|
|
36
|
+
const error = new Error(`${code}: ${msg || "unknown error"}, open '${path}'`);
|
|
37
|
+
error.code = code;
|
|
38
|
+
error.syscall = "open";
|
|
39
|
+
error.path = path;
|
|
40
|
+
return error;
|
|
41
|
+
}
|
|
9
42
|
class FileHandle {
|
|
10
43
|
constructor(options) {
|
|
11
44
|
this.options = options;
|
|
12
45
|
this.options.flags ||= "r";
|
|
13
46
|
this.options.mode ||= 438;
|
|
14
|
-
|
|
47
|
+
try {
|
|
48
|
+
this._file = GLib.IOChannel.new_file(options.path.toString(), this.options.flags);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
throw mapOpenError(err, options.path.toString());
|
|
51
|
+
}
|
|
52
|
+
this._file.set_encoding(null);
|
|
15
53
|
this.fd = this._file.unix_get_fd();
|
|
16
54
|
FileHandle.instances[this.fd] = this;
|
|
17
55
|
return FileHandle.getInstance(this.fd);
|
|
@@ -46,8 +84,7 @@ class FileHandle {
|
|
|
46
84
|
if (typeof data === "string") {
|
|
47
85
|
data = Buffer.from(data);
|
|
48
86
|
}
|
|
49
|
-
if (encoding)
|
|
50
|
-
this._file.set_encoding(encoding);
|
|
87
|
+
if (encoding) this._file.set_encoding(encoding);
|
|
51
88
|
const [status, written] = this._file.write_chars(data, data.length);
|
|
52
89
|
if (status === GLib.IOStatus.ERROR) {
|
|
53
90
|
throw new Error("Error on append to file!");
|
|
@@ -92,7 +129,7 @@ class FileHandle {
|
|
|
92
129
|
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
|
93
130
|
*
|
|
94
131
|
* ```js
|
|
95
|
-
* import { open } from 'fs/promises';
|
|
132
|
+
* import { open } from 'node:fs/promises';
|
|
96
133
|
*
|
|
97
134
|
* const fd = await open('/dev/input/event0');
|
|
98
135
|
* // Create a stream from some character device.
|
|
@@ -118,7 +155,7 @@ class FileHandle {
|
|
|
118
155
|
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
|
119
156
|
*
|
|
120
157
|
* ```js
|
|
121
|
-
* import { open } from 'fs/promises';
|
|
158
|
+
* import { open } from 'node:fs/promises';
|
|
122
159
|
*
|
|
123
160
|
* const fd = await open('sample.txt');
|
|
124
161
|
* fd.createReadStream({ start: 90, end: 99 });
|
|
@@ -168,12 +205,12 @@ class FileHandle {
|
|
|
168
205
|
async sync() {
|
|
169
206
|
warnNotImplemented("fs.FileHandle.sync");
|
|
170
207
|
}
|
|
171
|
-
async read(args) {
|
|
208
|
+
async read(...args) {
|
|
172
209
|
let buffer;
|
|
173
210
|
let offset;
|
|
174
211
|
let length;
|
|
175
212
|
let position;
|
|
176
|
-
if (typeof args[0] === "object") {
|
|
213
|
+
if (typeof args[0] === "object" && !(args[0] instanceof Uint8Array) && !(args[0] instanceof Buffer)) {
|
|
177
214
|
const options = args[0];
|
|
178
215
|
buffer = options.buffer;
|
|
179
216
|
offset = options.offset;
|
|
@@ -185,25 +222,18 @@ class FileHandle {
|
|
|
185
222
|
length = args[2];
|
|
186
223
|
position = args[3];
|
|
187
224
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
throw new Error("Error on set position!");
|
|
200
|
-
}
|
|
225
|
+
const bufView = buffer;
|
|
226
|
+
const bufOffset = offset ?? 0;
|
|
227
|
+
const readLength = length ?? bufView?.byteLength ?? 65536;
|
|
228
|
+
const gFile = Gio.File.new_for_path(this.options.path.toString());
|
|
229
|
+
const [, fileContents] = gFile.load_contents(null);
|
|
230
|
+
const fileData = fileContents;
|
|
231
|
+
const startPos = position ?? 0;
|
|
232
|
+
const readData = fileData.slice(startPos, startPos + readLength);
|
|
233
|
+
const bytesRead = readData.length;
|
|
234
|
+
if (bufView && bytesRead > 0) {
|
|
235
|
+
bufView.set(readData, bufOffset);
|
|
201
236
|
}
|
|
202
|
-
const [status, buf, bytesRead] = this._file.read_chars();
|
|
203
|
-
if (status === GLib.IOStatus.ERROR) {
|
|
204
|
-
throw new Error("Error on read!");
|
|
205
|
-
}
|
|
206
|
-
buffer = buf;
|
|
207
237
|
return {
|
|
208
238
|
bytesRead,
|
|
209
239
|
buffer
|
|
@@ -216,7 +246,7 @@ class FileHandle {
|
|
|
216
246
|
* or closing.
|
|
217
247
|
*
|
|
218
248
|
* ```js
|
|
219
|
-
* import { open } from 'fs/promises';
|
|
249
|
+
* import { open } from 'node:fs/promises';
|
|
220
250
|
*
|
|
221
251
|
* const file = await open('./some/file/to/read');
|
|
222
252
|
*
|
|
@@ -242,8 +272,7 @@ class FileHandle {
|
|
|
242
272
|
*/
|
|
243
273
|
async readFile(options) {
|
|
244
274
|
const encoding = getEncodingFromOptions(options, "buffer");
|
|
245
|
-
if (encoding)
|
|
246
|
-
this._file.set_encoding(encoding);
|
|
275
|
+
if (encoding) this._file.set_encoding(encoding);
|
|
247
276
|
const [status, buf] = this._file.read_to_end();
|
|
248
277
|
if (status === GLib.IOStatus.ERROR) {
|
|
249
278
|
throw new Error("Error on read from file!");
|
|
@@ -283,7 +312,7 @@ class FileHandle {
|
|
|
283
312
|
* The following example retains only the first four bytes of the file:
|
|
284
313
|
*
|
|
285
314
|
* ```js
|
|
286
|
-
* import { open } from 'fs/promises';
|
|
315
|
+
* import { open } from 'node:fs/promises';
|
|
287
316
|
*
|
|
288
317
|
* let filehandle = null;
|
|
289
318
|
* try {
|
|
@@ -302,8 +331,14 @@ class FileHandle {
|
|
|
302
331
|
* @param [len=0]
|
|
303
332
|
* @return Fulfills with `undefined` upon success.
|
|
304
333
|
*/
|
|
305
|
-
async truncate(len) {
|
|
306
|
-
|
|
334
|
+
async truncate(len = 0) {
|
|
335
|
+
const effectiveLen = Math.max(0, len);
|
|
336
|
+
this._file.flush();
|
|
337
|
+
const gFile = Gio.File.new_for_path(this.options.path.toString());
|
|
338
|
+
const [, currentContent] = gFile.load_contents(null);
|
|
339
|
+
const newContent = new Uint8Array(effectiveLen);
|
|
340
|
+
newContent.set(currentContent.slice(0, Math.min(effectiveLen, currentContent.length)));
|
|
341
|
+
gFile.replace_contents(newContent, null, false, Gio.FileCreateFlags.NONE, null);
|
|
307
342
|
}
|
|
308
343
|
/**
|
|
309
344
|
* Change the file system timestamps of the object referenced by the `FileHandle` then resolves the promise with no arguments upon success.
|
|
@@ -331,7 +366,19 @@ class FileHandle {
|
|
|
331
366
|
* @since v10.0.0
|
|
332
367
|
*/
|
|
333
368
|
async writeFile(data, options) {
|
|
334
|
-
|
|
369
|
+
const encoding = getEncodingFromOptions(options);
|
|
370
|
+
let buf;
|
|
371
|
+
if (typeof data === "string") {
|
|
372
|
+
buf = Buffer.from(data, encoding || "utf8");
|
|
373
|
+
} else {
|
|
374
|
+
buf = data;
|
|
375
|
+
}
|
|
376
|
+
this._file.seek_position(0, GLib.SeekType.SET);
|
|
377
|
+
const [status] = this._file.write_chars(buf, buf.length);
|
|
378
|
+
if (status === GLib.IOStatus.ERROR) {
|
|
379
|
+
throw new Error("Error writing to file!");
|
|
380
|
+
}
|
|
381
|
+
this._file.flush();
|
|
335
382
|
}
|
|
336
383
|
async write(data, ...args) {
|
|
337
384
|
let position = null;
|
|
@@ -347,39 +394,31 @@ class FileHandle {
|
|
|
347
394
|
position = args[2];
|
|
348
395
|
}
|
|
349
396
|
encoding = getEncodingFromOptions(encoding, typeof data === "string" ? "utf8" : null);
|
|
350
|
-
|
|
351
|
-
console.log("set_encoding", encoding, this._file.get_encoding(), typeof data);
|
|
352
|
-
this._file.set_encoding(encoding === "buffer" ? null : encoding);
|
|
353
|
-
}
|
|
354
|
-
if (offset) {
|
|
355
|
-
const status2 = this._file.seek_position(offset, GLib.SeekType.CUR);
|
|
356
|
-
if (status2 === GLib.IOStatus.ERROR) {
|
|
357
|
-
throw new Error("Error on set offset!");
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (length)
|
|
361
|
-
this._file.set_buffer_size(length);
|
|
362
|
-
if (position) {
|
|
363
|
-
const status2 = this._file.seek_position(position, GLib.SeekType.SET);
|
|
364
|
-
if (status2 === GLib.IOStatus.ERROR) {
|
|
365
|
-
throw new Error("Error on set position!");
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
let bytesWritten = 0;
|
|
369
|
-
let status;
|
|
397
|
+
let writeBuf;
|
|
370
398
|
if (typeof data === "string") {
|
|
371
|
-
|
|
372
|
-
bytesWritten = data.length;
|
|
399
|
+
writeBuf = new TextEncoder().encode(data);
|
|
373
400
|
} else {
|
|
374
|
-
|
|
375
|
-
bytesWritten = _bytesWritten;
|
|
376
|
-
status = _status;
|
|
401
|
+
writeBuf = data;
|
|
377
402
|
}
|
|
378
|
-
|
|
379
|
-
|
|
403
|
+
const bufOffset = offset ?? 0;
|
|
404
|
+
const writeLength = length ?? writeBuf.byteLength - bufOffset;
|
|
405
|
+
const writeSlice = writeBuf.slice(bufOffset, bufOffset + writeLength);
|
|
406
|
+
const writePos = position ?? 0;
|
|
407
|
+
const gFile = Gio.File.new_for_path(this.options.path.toString());
|
|
408
|
+
let existingData;
|
|
409
|
+
try {
|
|
410
|
+
const [, existing] = gFile.load_contents(null);
|
|
411
|
+
existingData = existing;
|
|
412
|
+
} catch {
|
|
413
|
+
existingData = new Uint8Array(0);
|
|
380
414
|
}
|
|
415
|
+
const newSize = Math.max(existingData.length, writePos + writeSlice.length);
|
|
416
|
+
const newContent = new Uint8Array(newSize);
|
|
417
|
+
newContent.set(existingData);
|
|
418
|
+
newContent.set(writeSlice, writePos);
|
|
419
|
+
gFile.replace_contents(newContent, null, false, Gio.FileCreateFlags.NONE, null);
|
|
381
420
|
return {
|
|
382
|
-
bytesWritten,
|
|
421
|
+
bytesWritten: writeSlice.length,
|
|
383
422
|
buffer: data
|
|
384
423
|
};
|
|
385
424
|
}
|
|
@@ -402,7 +441,7 @@ class FileHandle {
|
|
|
402
441
|
warnNotImplemented("fs.FileHandle.writev");
|
|
403
442
|
return {
|
|
404
443
|
bytesWritten: 0,
|
|
405
|
-
buffers
|
|
444
|
+
buffers
|
|
406
445
|
};
|
|
407
446
|
}
|
|
408
447
|
/**
|
|
@@ -415,7 +454,7 @@ class FileHandle {
|
|
|
415
454
|
warnNotImplemented("fs.FileHandle.readv");
|
|
416
455
|
return {
|
|
417
456
|
bytesRead: 0,
|
|
418
|
-
buffers
|
|
457
|
+
buffers
|
|
419
458
|
};
|
|
420
459
|
}
|
|
421
460
|
/**
|
|
@@ -423,7 +462,7 @@ class FileHandle {
|
|
|
423
462
|
* complete.
|
|
424
463
|
*
|
|
425
464
|
* ```js
|
|
426
|
-
* import { open } from 'fs/promises';
|
|
465
|
+
* import { open } from 'node:fs/promises';
|
|
427
466
|
*
|
|
428
467
|
* let filehandle;
|
|
429
468
|
* try {
|
|
@@ -436,7 +475,10 @@ class FileHandle {
|
|
|
436
475
|
* @return Fulfills with `undefined` upon success.
|
|
437
476
|
*/
|
|
438
477
|
async close() {
|
|
439
|
-
this._file.
|
|
478
|
+
this._file.shutdown(true);
|
|
479
|
+
}
|
|
480
|
+
async [Symbol.asyncDispose]() {
|
|
481
|
+
await this.close();
|
|
440
482
|
}
|
|
441
483
|
}
|
|
442
484
|
export {
|
package/lib/esm/fs-watcher.js
CHANGED
|
@@ -1,31 +1,68 @@
|
|
|
1
|
+
import GLib from "@girs/glib-2.0";
|
|
1
2
|
import Gio from "@girs/gio-2.0";
|
|
2
|
-
import { EventEmitter } from "events";
|
|
3
|
+
import { EventEmitter } from "node:events";
|
|
3
4
|
const privates = /* @__PURE__ */ new WeakMap();
|
|
4
5
|
class FSWatcher extends EventEmitter {
|
|
5
6
|
constructor(filename, options, listener) {
|
|
6
7
|
super();
|
|
7
8
|
if (!options || typeof options !== "object")
|
|
8
9
|
options = { persistent: true };
|
|
10
|
+
const persistent = options.persistent !== false;
|
|
9
11
|
const cancellable = Gio.Cancellable.new();
|
|
10
12
|
const file = Gio.File.new_for_path(filename);
|
|
11
13
|
const watcher = file.monitor(Gio.FileMonitorFlags.NONE, cancellable);
|
|
12
14
|
watcher.connect("changed", changed.bind(this));
|
|
15
|
+
let sourceId = null;
|
|
16
|
+
if (persistent) {
|
|
17
|
+
sourceId = GLib.timeout_add(GLib.PRIORITY_LOW, 2147483647, () => GLib.SOURCE_CONTINUE);
|
|
18
|
+
}
|
|
13
19
|
privates.set(this, {
|
|
14
|
-
persistent
|
|
20
|
+
persistent,
|
|
15
21
|
cancellable,
|
|
22
|
+
sourceId,
|
|
16
23
|
// even if never used later on, the monitor needs to be
|
|
17
24
|
// attached to this instance or GJS reference counter
|
|
18
25
|
// will ignore it and no watch will ever happen
|
|
19
26
|
watcher
|
|
20
27
|
});
|
|
21
|
-
if (listener)
|
|
22
|
-
this.on("change", listener);
|
|
28
|
+
if (listener) this.on("change", listener);
|
|
23
29
|
}
|
|
24
30
|
close() {
|
|
25
|
-
const
|
|
26
|
-
if (!cancellable.is_cancelled()) {
|
|
27
|
-
cancellable.cancel();
|
|
31
|
+
const priv = privates.get(this);
|
|
32
|
+
if (!priv.cancellable.is_cancelled()) {
|
|
33
|
+
priv.cancellable.cancel();
|
|
34
|
+
if (priv.sourceId !== null) {
|
|
35
|
+
GLib.source_remove(priv.sourceId);
|
|
36
|
+
priv.sourceId = null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* When called, requests that the Node.js event loop not exit so long as the
|
|
42
|
+
* FSWatcher is active. Calling ref() multiple times has no effect.
|
|
43
|
+
*/
|
|
44
|
+
ref() {
|
|
45
|
+
const priv = privates.get(this);
|
|
46
|
+
if (!priv.persistent && !priv.cancellable.is_cancelled()) {
|
|
47
|
+
priv.persistent = true;
|
|
48
|
+
priv.sourceId = GLib.timeout_add(GLib.PRIORITY_LOW, 2147483647, () => GLib.SOURCE_CONTINUE);
|
|
49
|
+
}
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* When called, the active FSWatcher will not require the Node.js event loop
|
|
54
|
+
* to remain active. Calling unref() multiple times has no effect.
|
|
55
|
+
*/
|
|
56
|
+
unref() {
|
|
57
|
+
const priv = privates.get(this);
|
|
58
|
+
if (priv.persistent) {
|
|
59
|
+
priv.persistent = false;
|
|
60
|
+
if (priv.sourceId !== null) {
|
|
61
|
+
GLib.source_remove(priv.sourceId);
|
|
62
|
+
priv.sourceId = null;
|
|
63
|
+
}
|
|
28
64
|
}
|
|
65
|
+
return this;
|
|
29
66
|
}
|
|
30
67
|
}
|
|
31
68
|
;
|
package/lib/esm/index.js
CHANGED
|
@@ -13,7 +13,16 @@ import {
|
|
|
13
13
|
openSync,
|
|
14
14
|
realpathSync,
|
|
15
15
|
symlinkSync,
|
|
16
|
-
lstatSync
|
|
16
|
+
lstatSync,
|
|
17
|
+
renameSync,
|
|
18
|
+
copyFileSync,
|
|
19
|
+
accessSync,
|
|
20
|
+
appendFileSync,
|
|
21
|
+
readlinkSync,
|
|
22
|
+
linkSync,
|
|
23
|
+
truncateSync,
|
|
24
|
+
chmodSync,
|
|
25
|
+
chownSync
|
|
17
26
|
} from "./sync.js";
|
|
18
27
|
import {
|
|
19
28
|
open,
|
|
@@ -24,16 +33,86 @@ import {
|
|
|
24
33
|
realpath,
|
|
25
34
|
readdir,
|
|
26
35
|
symlink,
|
|
27
|
-
lstat
|
|
36
|
+
lstat,
|
|
37
|
+
stat,
|
|
38
|
+
rename,
|
|
39
|
+
copyFile,
|
|
40
|
+
access,
|
|
41
|
+
appendFile,
|
|
42
|
+
readlink,
|
|
43
|
+
truncate,
|
|
44
|
+
chmod,
|
|
45
|
+
chown,
|
|
46
|
+
mkdir,
|
|
47
|
+
rmdir,
|
|
48
|
+
readFile,
|
|
49
|
+
writeFile,
|
|
50
|
+
unlink,
|
|
51
|
+
link
|
|
28
52
|
} from "./callback.js";
|
|
29
53
|
import FSWatcher from "./fs-watcher.js";
|
|
30
54
|
import {
|
|
31
55
|
createReadStream,
|
|
32
56
|
ReadStream
|
|
33
57
|
} from "./read-stream.js";
|
|
58
|
+
import {
|
|
59
|
+
createWriteStream,
|
|
60
|
+
WriteStream
|
|
61
|
+
} from "./write-stream.js";
|
|
34
62
|
import * as promises from "./promises.js";
|
|
35
|
-
|
|
63
|
+
import { Stats, BigIntStats } from "./stats.js";
|
|
64
|
+
import { Dirent } from "./dirent.js";
|
|
65
|
+
const constants = {
|
|
66
|
+
// File access constants
|
|
67
|
+
F_OK: 0,
|
|
68
|
+
R_OK: 4,
|
|
69
|
+
W_OK: 2,
|
|
70
|
+
X_OK: 1,
|
|
71
|
+
// File copy constants
|
|
72
|
+
COPYFILE_EXCL: 1,
|
|
73
|
+
COPYFILE_FICLONE: 2,
|
|
74
|
+
COPYFILE_FICLONE_FORCE: 4,
|
|
75
|
+
// File open constants
|
|
76
|
+
O_RDONLY: 0,
|
|
77
|
+
O_WRONLY: 1,
|
|
78
|
+
O_RDWR: 2,
|
|
79
|
+
O_CREAT: 64,
|
|
80
|
+
O_EXCL: 128,
|
|
81
|
+
O_TRUNC: 512,
|
|
82
|
+
O_APPEND: 1024,
|
|
83
|
+
O_SYNC: 1052672,
|
|
84
|
+
O_NONBLOCK: 2048,
|
|
85
|
+
O_DIRECTORY: 65536,
|
|
86
|
+
O_NOFOLLOW: 131072,
|
|
87
|
+
// File type constants
|
|
88
|
+
S_IFMT: 61440,
|
|
89
|
+
S_IFREG: 32768,
|
|
90
|
+
S_IFDIR: 16384,
|
|
91
|
+
S_IFCHR: 8192,
|
|
92
|
+
S_IFBLK: 24576,
|
|
93
|
+
S_IFIFO: 4096,
|
|
94
|
+
S_IFLNK: 40960,
|
|
95
|
+
S_IFSOCK: 49152,
|
|
96
|
+
// File mode constants
|
|
97
|
+
S_IRWXU: 448,
|
|
98
|
+
S_IRUSR: 256,
|
|
99
|
+
S_IWUSR: 128,
|
|
100
|
+
S_IXUSR: 64,
|
|
101
|
+
S_IRWXG: 56,
|
|
102
|
+
S_IRGRP: 32,
|
|
103
|
+
S_IWGRP: 16,
|
|
104
|
+
S_IXGRP: 8,
|
|
105
|
+
S_IRWXO: 7,
|
|
106
|
+
S_IROTH: 4,
|
|
107
|
+
S_IWOTH: 2,
|
|
108
|
+
S_IXOTH: 1
|
|
109
|
+
};
|
|
110
|
+
var index_default = {
|
|
36
111
|
FSWatcher,
|
|
112
|
+
Stats,
|
|
113
|
+
BigIntStats,
|
|
114
|
+
Dirent,
|
|
115
|
+
constants,
|
|
37
116
|
existsSync,
|
|
38
117
|
readdirSync,
|
|
39
118
|
readFileSync,
|
|
@@ -48,9 +127,20 @@ var src_default = {
|
|
|
48
127
|
realpathSync,
|
|
49
128
|
symlinkSync,
|
|
50
129
|
lstatSync,
|
|
130
|
+
renameSync,
|
|
131
|
+
copyFileSync,
|
|
132
|
+
accessSync,
|
|
133
|
+
appendFileSync,
|
|
134
|
+
readlinkSync,
|
|
135
|
+
linkSync,
|
|
136
|
+
truncateSync,
|
|
137
|
+
chmodSync,
|
|
138
|
+
chownSync,
|
|
51
139
|
watch,
|
|
52
140
|
createReadStream,
|
|
53
141
|
ReadStream,
|
|
142
|
+
createWriteStream,
|
|
143
|
+
WriteStream,
|
|
54
144
|
promises,
|
|
55
145
|
open,
|
|
56
146
|
close,
|
|
@@ -60,36 +150,81 @@ var src_default = {
|
|
|
60
150
|
realpath,
|
|
61
151
|
readdir,
|
|
62
152
|
symlink,
|
|
63
|
-
lstat
|
|
153
|
+
lstat,
|
|
154
|
+
stat,
|
|
155
|
+
rename,
|
|
156
|
+
copyFile,
|
|
157
|
+
access,
|
|
158
|
+
appendFile,
|
|
159
|
+
readlink,
|
|
160
|
+
truncate,
|
|
161
|
+
chmod,
|
|
162
|
+
chown,
|
|
163
|
+
mkdir,
|
|
164
|
+
rmdir,
|
|
165
|
+
readFile,
|
|
166
|
+
writeFile,
|
|
167
|
+
unlink,
|
|
168
|
+
link
|
|
64
169
|
};
|
|
65
170
|
export {
|
|
171
|
+
BigIntStats,
|
|
172
|
+
Dirent,
|
|
66
173
|
FSWatcher,
|
|
67
174
|
ReadStream,
|
|
175
|
+
Stats,
|
|
176
|
+
WriteStream,
|
|
177
|
+
access,
|
|
178
|
+
accessSync,
|
|
179
|
+
appendFile,
|
|
180
|
+
appendFileSync,
|
|
181
|
+
chmod,
|
|
182
|
+
chmodSync,
|
|
183
|
+
chown,
|
|
184
|
+
chownSync,
|
|
68
185
|
close,
|
|
186
|
+
constants,
|
|
187
|
+
copyFile,
|
|
188
|
+
copyFileSync,
|
|
69
189
|
createReadStream,
|
|
70
|
-
|
|
190
|
+
createWriteStream,
|
|
191
|
+
index_default as default,
|
|
71
192
|
existsSync,
|
|
193
|
+
link,
|
|
194
|
+
linkSync,
|
|
72
195
|
lstat,
|
|
73
196
|
lstatSync,
|
|
197
|
+
mkdir,
|
|
74
198
|
mkdirSync,
|
|
75
199
|
mkdtempSync,
|
|
76
200
|
open,
|
|
77
201
|
openSync,
|
|
78
202
|
promises,
|
|
79
203
|
read,
|
|
204
|
+
readFile,
|
|
80
205
|
readFileSync,
|
|
81
206
|
readdir,
|
|
82
207
|
readdirSync,
|
|
208
|
+
readlink,
|
|
209
|
+
readlinkSync,
|
|
83
210
|
realpath,
|
|
84
211
|
realpathSync,
|
|
212
|
+
rename,
|
|
213
|
+
renameSync,
|
|
85
214
|
rm,
|
|
86
215
|
rmSync,
|
|
216
|
+
rmdir,
|
|
87
217
|
rmdirSync,
|
|
218
|
+
stat,
|
|
88
219
|
statSync,
|
|
89
220
|
symlink,
|
|
90
221
|
symlinkSync,
|
|
222
|
+
truncate,
|
|
223
|
+
truncateSync,
|
|
224
|
+
unlink,
|
|
91
225
|
unlinkSync,
|
|
92
226
|
watch,
|
|
93
227
|
write,
|
|
228
|
+
writeFile,
|
|
94
229
|
writeFileSync
|
|
95
230
|
};
|