@gjsify/fs 0.3.13 → 0.3.14
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/lib/esm/_virtual/_rolldown/runtime.js +18 -0
- package/lib/esm/callback.js +301 -302
- package/lib/esm/cp.js +207 -227
- package/lib/esm/dir.js +140 -148
- package/lib/esm/dirent.js +137 -128
- package/lib/esm/encoding.js +30 -27
- package/lib/esm/errors.js +15 -11
- package/lib/esm/fd-ops.js +105 -122
- package/lib/esm/file-handle.js +648 -653
- package/lib/esm/fs-watcher.js +153 -161
- package/lib/esm/glob.js +148 -149
- package/lib/esm/index.js +158 -351
- package/lib/esm/promises.js +413 -386
- package/lib/esm/read-stream.js +104 -108
- package/lib/esm/stat-watcher.js +113 -114
- package/lib/esm/statfs.js +56 -43
- package/lib/esm/stats.js +166 -159
- package/lib/esm/sync.js +366 -341
- package/lib/esm/types/index.js +6 -6
- package/lib/esm/utils.js +15 -17
- package/lib/esm/utimes.js +26 -37
- package/lib/esm/write-stream.js +96 -108
- package/package.json +10 -10
package/lib/esm/types/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import "./encoding-option.js";
|
|
2
|
+
import "./file-read-options.js";
|
|
3
|
+
import "./file-read-result.js";
|
|
4
|
+
import "./flag-and-open-mode.js";
|
|
5
|
+
import "./open-flags.js";
|
|
6
|
+
import "./read-options.js";
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import { existsSync } from "./sync.js";
|
|
2
|
-
import {
|
|
2
|
+
import { URL as URL$1, fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
//#region src/utils.ts
|
|
3
5
|
function normalizePath(path) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
if (path instanceof URL || path instanceof URL$1) return fileURLToPath(path);
|
|
7
|
+
if (typeof path === "string") return path;
|
|
8
|
+
return path.toString();
|
|
7
9
|
}
|
|
8
10
|
const CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
9
11
|
function randomName() {
|
|
10
|
-
|
|
11
|
-
() => CHARS[Math.floor(Math.random() * CHARS.length)]
|
|
12
|
-
).join("");
|
|
12
|
+
return [...Array(6)].map(() => CHARS[Math.floor(Math.random() * CHARS.length)]).join("");
|
|
13
13
|
}
|
|
14
14
|
function tempDirPath(prefix) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
let path;
|
|
16
|
+
do {
|
|
17
|
+
path = prefix + randomName();
|
|
18
|
+
} while (existsSync(path));
|
|
19
|
+
return path;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
tempDirPath
|
|
25
|
-
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { normalizePath, randomName, tempDirPath };
|
package/lib/esm/utimes.js
CHANGED
|
@@ -1,62 +1,51 @@
|
|
|
1
|
+
import { normalizePath } from "./utils.js";
|
|
1
2
|
import GLib from "@girs/glib-2.0";
|
|
2
3
|
import Gio from "@girs/gio-2.0";
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
//#region src/utimes.ts
|
|
4
6
|
function toGLibDateTime(t) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
const ms = t instanceof Date ? t.getTime() : typeof t === "bigint" ? Number(t) : typeof t === "string" ? Date.parse(t) : t * 1e3;
|
|
8
|
+
return GLib.DateTime.new_from_unix_utc(Math.floor(ms / 1e3));
|
|
7
9
|
}
|
|
8
10
|
function setTimestamps(path, atime, mtime, flags) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const file = Gio.File.new_for_path(path);
|
|
12
|
+
const info = new Gio.FileInfo();
|
|
13
|
+
info.set_modification_date_time(toGLibDateTime(mtime));
|
|
14
|
+
info.set_access_date_time(toGLibDateTime(atime));
|
|
15
|
+
file.set_attributes_from_info(info, flags, null);
|
|
14
16
|
}
|
|
15
17
|
function utimesSync(path, atime, mtime) {
|
|
16
|
-
|
|
18
|
+
setTimestamps(normalizePath(path), atime, mtime, Gio.FileQueryInfoFlags.NONE);
|
|
17
19
|
}
|
|
18
20
|
function utimes(path, atime, mtime, callback) {
|
|
19
|
-
|
|
21
|
+
Promise.resolve().then(() => utimesSync(path, atime, mtime)).then(() => callback(null), callback);
|
|
20
22
|
}
|
|
21
23
|
async function utimesAsync(path, atime, mtime) {
|
|
22
|
-
|
|
24
|
+
utimesSync(path, atime, mtime);
|
|
23
25
|
}
|
|
24
26
|
function lutimesSync(path, atime, mtime) {
|
|
25
|
-
|
|
27
|
+
setTimestamps(normalizePath(path), atime, mtime, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
|
|
26
28
|
}
|
|
27
29
|
function lutimes(path, atime, mtime, callback) {
|
|
28
|
-
|
|
30
|
+
Promise.resolve().then(() => lutimesSync(path, atime, mtime)).then(() => callback(null), callback);
|
|
29
31
|
}
|
|
30
32
|
async function lutimesAsync(path, atime, mtime) {
|
|
31
|
-
|
|
33
|
+
lutimesSync(path, atime, mtime);
|
|
32
34
|
}
|
|
33
35
|
function lchownSync(path, uid, gid) {
|
|
34
|
-
|
|
36
|
+
GLib.spawn_command_line_sync(`chown -h ${uid}:${gid} ${normalizePath(path)}`);
|
|
35
37
|
}
|
|
36
38
|
function lchown(path, uid, gid, callback) {
|
|
37
|
-
|
|
39
|
+
Promise.resolve().then(() => lchownSync(path, uid, gid)).then(() => callback(null), callback);
|
|
38
40
|
}
|
|
39
41
|
async function lchownAsync(path, uid, gid) {
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
function lchmodSync(_path, _mode) {
|
|
42
|
+
lchownSync(path, uid, gid);
|
|
43
43
|
}
|
|
44
|
+
function lchmodSync(_path, _mode) {}
|
|
44
45
|
function lchmod(_path, _mode, callback) {
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
async function lchmodAsync(_path, _mode) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
lchmodAsync,
|
|
52
|
-
lchmodSync,
|
|
53
|
-
lchown,
|
|
54
|
-
lchownAsync,
|
|
55
|
-
lchownSync,
|
|
56
|
-
lutimes,
|
|
57
|
-
lutimesAsync,
|
|
58
|
-
lutimesSync,
|
|
59
|
-
utimes,
|
|
60
|
-
utimesAsync,
|
|
61
|
-
utimesSync
|
|
62
|
-
};
|
|
46
|
+
callback(null);
|
|
47
|
+
}
|
|
48
|
+
async function lchmodAsync(_path, _mode) {}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { lchmod, lchmodAsync, lchmodSync, lchown, lchownAsync, lchownSync, lutimes, lutimesAsync, lutimesSync, utimes, utimesAsync, utimesSync };
|
package/lib/esm/write-stream.js
CHANGED
|
@@ -1,113 +1,101 @@
|
|
|
1
|
-
import { Writable } from "node:stream";
|
|
2
|
-
import { open, write, close } from "./callback.js";
|
|
3
1
|
import { normalizePath } from "./utils.js";
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { close, open, write } from "./callback.js";
|
|
3
|
+
import { Writable } from "node:stream";
|
|
4
|
+
|
|
5
|
+
//#region src/write-stream.ts
|
|
6
|
+
const kIsPerformingIO = Symbol("kIsPerformingIO");
|
|
7
|
+
const kIoDone = Symbol("kIoDone");
|
|
6
8
|
function toPathIfFileURL(fileURLOrPath) {
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
class WriteStream extends Writable {
|
|
10
|
-
/**
|
|
11
|
-
* Closes `writeStream`. Optionally accepts a
|
|
12
|
-
* callback that will be executed once the `writeStream`is closed.
|
|
13
|
-
* @since v0.9.4
|
|
14
|
-
*/
|
|
15
|
-
close(callback, err = null) {
|
|
16
|
-
if (!this.fd) {
|
|
17
|
-
callback(err);
|
|
18
|
-
} else {
|
|
19
|
-
close(this.fd, (er) => {
|
|
20
|
-
callback(er || err);
|
|
21
|
-
});
|
|
22
|
-
this.fd = null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The number of bytes written so far. Does not include data that is still queued
|
|
27
|
-
* for writing.
|
|
28
|
-
* @since v0.4.7
|
|
29
|
-
*/
|
|
30
|
-
bytesWritten = 0;
|
|
31
|
-
/**
|
|
32
|
-
* The path to the file the stream is writing to as specified in the first
|
|
33
|
-
* argument to {@link createWriteStream}. If `path` is passed as a string, then`writeStream.path` will be a string. If `path` is passed as a `Buffer`, then`writeStream.path` will be a
|
|
34
|
-
* `Buffer`.
|
|
35
|
-
* @since v0.1.93
|
|
36
|
-
*/
|
|
37
|
-
path;
|
|
38
|
-
/**
|
|
39
|
-
* This property is `true` if the underlying file has not been opened yet,
|
|
40
|
-
* i.e. before the `'ready'` event is emitted.
|
|
41
|
-
* @since v11.2.0
|
|
42
|
-
*/
|
|
43
|
-
pending;
|
|
44
|
-
fd = null;
|
|
45
|
-
flags = "w";
|
|
46
|
-
mode = 438;
|
|
47
|
-
pos = 0;
|
|
48
|
-
[kIsPerformingIO] = false;
|
|
49
|
-
constructor(path, opts = {}) {
|
|
50
|
-
super(opts);
|
|
51
|
-
this.path = toPathIfFileURL(path);
|
|
52
|
-
if (opts.encoding) {
|
|
53
|
-
this.setDefaultEncoding(opts.encoding);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
_construct(callback) {
|
|
57
|
-
open(
|
|
58
|
-
this.path.toString(),
|
|
59
|
-
this.flags,
|
|
60
|
-
this.mode,
|
|
61
|
-
(err, fd) => {
|
|
62
|
-
if (err) {
|
|
63
|
-
callback(err);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
this.fd = fd;
|
|
67
|
-
callback();
|
|
68
|
-
this.emit("open", this.fd);
|
|
69
|
-
this.emit("ready");
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
_write(data, _encoding, cb) {
|
|
74
|
-
this[kIsPerformingIO] = true;
|
|
75
|
-
write(
|
|
76
|
-
this.fd,
|
|
77
|
-
data,
|
|
78
|
-
0,
|
|
79
|
-
data.length,
|
|
80
|
-
this.pos,
|
|
81
|
-
(er, bytes) => {
|
|
82
|
-
this[kIsPerformingIO] = false;
|
|
83
|
-
if (this.destroyed) {
|
|
84
|
-
cb(er);
|
|
85
|
-
return this.emit(kIoDone, er);
|
|
86
|
-
}
|
|
87
|
-
if (er) {
|
|
88
|
-
return cb(er);
|
|
89
|
-
}
|
|
90
|
-
this.bytesWritten += bytes;
|
|
91
|
-
cb();
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
if (this.pos !== void 0) {
|
|
95
|
-
this.pos += data.length;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
_destroy(err, cb) {
|
|
99
|
-
if (this[kIsPerformingIO]) {
|
|
100
|
-
this.once(kIoDone, (er) => this.close(cb, err || er));
|
|
101
|
-
} else {
|
|
102
|
-
this.close(cb, err);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
9
|
+
return normalizePath(fileURLOrPath);
|
|
105
10
|
}
|
|
11
|
+
var WriteStream = class extends Writable {
|
|
12
|
+
/**
|
|
13
|
+
* Closes `writeStream`. Optionally accepts a
|
|
14
|
+
* callback that will be executed once the `writeStream`is closed.
|
|
15
|
+
* @since v0.9.4
|
|
16
|
+
*/
|
|
17
|
+
close(callback, err = null) {
|
|
18
|
+
if (!this.fd) {
|
|
19
|
+
callback(err);
|
|
20
|
+
} else {
|
|
21
|
+
close(this.fd, (er) => {
|
|
22
|
+
callback(er || err);
|
|
23
|
+
});
|
|
24
|
+
this.fd = null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The number of bytes written so far. Does not include data that is still queued
|
|
29
|
+
* for writing.
|
|
30
|
+
* @since v0.4.7
|
|
31
|
+
*/
|
|
32
|
+
bytesWritten = 0;
|
|
33
|
+
/**
|
|
34
|
+
* The path to the file the stream is writing to as specified in the first
|
|
35
|
+
* argument to {@link createWriteStream}. If `path` is passed as a string, then`writeStream.path` will be a string. If `path` is passed as a `Buffer`, then`writeStream.path` will be a
|
|
36
|
+
* `Buffer`.
|
|
37
|
+
* @since v0.1.93
|
|
38
|
+
*/
|
|
39
|
+
path;
|
|
40
|
+
/**
|
|
41
|
+
* This property is `true` if the underlying file has not been opened yet,
|
|
42
|
+
* i.e. before the `'ready'` event is emitted.
|
|
43
|
+
* @since v11.2.0
|
|
44
|
+
*/
|
|
45
|
+
pending;
|
|
46
|
+
fd = null;
|
|
47
|
+
flags = "w";
|
|
48
|
+
mode = 438;
|
|
49
|
+
pos = 0;
|
|
50
|
+
[kIsPerformingIO] = false;
|
|
51
|
+
constructor(path, opts = {}) {
|
|
52
|
+
super(opts);
|
|
53
|
+
this.path = toPathIfFileURL(path);
|
|
54
|
+
if (opts.encoding) {
|
|
55
|
+
this.setDefaultEncoding(opts.encoding);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
_construct(callback) {
|
|
59
|
+
open(this.path.toString(), this.flags, this.mode, (err, fd) => {
|
|
60
|
+
if (err) {
|
|
61
|
+
callback(err);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.fd = fd;
|
|
65
|
+
callback();
|
|
66
|
+
this.emit("open", this.fd);
|
|
67
|
+
this.emit("ready");
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
_write(data, _encoding, cb) {
|
|
71
|
+
this[kIsPerformingIO] = true;
|
|
72
|
+
write(this.fd, data, 0, data.length, this.pos, (er, bytes) => {
|
|
73
|
+
this[kIsPerformingIO] = false;
|
|
74
|
+
if (this.destroyed) {
|
|
75
|
+
cb(er);
|
|
76
|
+
return this.emit(kIoDone, er);
|
|
77
|
+
}
|
|
78
|
+
if (er) {
|
|
79
|
+
return cb(er);
|
|
80
|
+
}
|
|
81
|
+
this.bytesWritten += bytes;
|
|
82
|
+
cb();
|
|
83
|
+
});
|
|
84
|
+
if (this.pos !== undefined) {
|
|
85
|
+
this.pos += data.length;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
_destroy(err, cb) {
|
|
89
|
+
if (this[kIsPerformingIO]) {
|
|
90
|
+
this.once(kIoDone, (er) => this.close(cb, err || er));
|
|
91
|
+
} else {
|
|
92
|
+
this.close(cb, err);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
106
96
|
function createWriteStream(path, opts) {
|
|
107
|
-
|
|
97
|
+
return new WriteStream(path, opts);
|
|
108
98
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
toPathIfFileURL
|
|
113
|
-
};
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { WriteStream, createWriteStream, toPathIfFileURL };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/fs",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "Node.js fs module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
"fs"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@gjsify/cli": "^0.3.
|
|
38
|
-
"@gjsify/unit": "^0.3.
|
|
37
|
+
"@gjsify/cli": "^0.3.14",
|
|
38
|
+
"@gjsify/unit": "^0.3.14",
|
|
39
39
|
"@types/node": "^25.6.0",
|
|
40
40
|
"typescript": "^6.0.3"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@girs/gio-2.0": "
|
|
44
|
-
"@girs/glib-2.0": "
|
|
45
|
-
"@gjsify/buffer": "^0.3.
|
|
46
|
-
"@gjsify/events": "^0.3.
|
|
47
|
-
"@gjsify/stream": "^0.3.
|
|
48
|
-
"@gjsify/url": "^0.3.
|
|
49
|
-
"@gjsify/utils": "^0.3.
|
|
43
|
+
"@girs/gio-2.0": "2.88.0-4.0.0-rc.9",
|
|
44
|
+
"@girs/glib-2.0": "2.88.0-4.0.0-rc.9",
|
|
45
|
+
"@gjsify/buffer": "^0.3.14",
|
|
46
|
+
"@gjsify/events": "^0.3.14",
|
|
47
|
+
"@gjsify/stream": "^0.3.14",
|
|
48
|
+
"@gjsify/url": "^0.3.14",
|
|
49
|
+
"@gjsify/utils": "^0.3.14"
|
|
50
50
|
}
|
|
51
51
|
}
|