@gjsify/fs 0.3.12 → 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.
@@ -1,6 +1,6 @@
1
- export * from "./encoding-option.js";
2
- export * from "./file-read-options.js";
3
- export * from "./file-read-result.js";
4
- export * from "./flag-and-open-mode.js";
5
- export * from "./open-flags.js";
6
- export * from "./read-options.js";
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 { fileURLToPath, URL as NodeURL } from "node:url";
2
+ import { URL as URL$1, fileURLToPath } from "node:url";
3
+
4
+ //#region src/utils.ts
3
5
  function normalizePath(path) {
4
- if (path instanceof URL || path instanceof NodeURL) return fileURLToPath(path);
5
- if (typeof path === "string") return path;
6
- return path.toString();
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
- return [...Array(6)].map(
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
- let path;
16
- do {
17
- path = prefix + randomName();
18
- } while (existsSync(path));
19
- return path;
15
+ let path;
16
+ do {
17
+ path = prefix + randomName();
18
+ } while (existsSync(path));
19
+ return path;
20
20
  }
21
- export {
22
- normalizePath,
23
- randomName,
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
- import { normalizePath } from "./utils.js";
4
+
5
+ //#region src/utimes.ts
4
6
  function toGLibDateTime(t) {
5
- const ms = t instanceof Date ? t.getTime() : typeof t === "bigint" ? Number(t) : typeof t === "string" ? Date.parse(t) : t * 1e3;
6
- return GLib.DateTime.new_from_unix_utc(Math.floor(ms / 1e3));
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
- const file = Gio.File.new_for_path(path);
10
- const info = new Gio.FileInfo();
11
- info.set_modification_date_time(toGLibDateTime(mtime));
12
- info.set_access_date_time(toGLibDateTime(atime));
13
- file.set_attributes_from_info(info, flags, null);
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
- setTimestamps(normalizePath(path), atime, mtime, Gio.FileQueryInfoFlags.NONE);
18
+ setTimestamps(normalizePath(path), atime, mtime, Gio.FileQueryInfoFlags.NONE);
17
19
  }
18
20
  function utimes(path, atime, mtime, callback) {
19
- Promise.resolve().then(() => utimesSync(path, atime, mtime)).then(() => callback(null), callback);
21
+ Promise.resolve().then(() => utimesSync(path, atime, mtime)).then(() => callback(null), callback);
20
22
  }
21
23
  async function utimesAsync(path, atime, mtime) {
22
- utimesSync(path, atime, mtime);
24
+ utimesSync(path, atime, mtime);
23
25
  }
24
26
  function lutimesSync(path, atime, mtime) {
25
- setTimestamps(normalizePath(path), atime, mtime, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
27
+ setTimestamps(normalizePath(path), atime, mtime, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
26
28
  }
27
29
  function lutimes(path, atime, mtime, callback) {
28
- Promise.resolve().then(() => lutimesSync(path, atime, mtime)).then(() => callback(null), callback);
30
+ Promise.resolve().then(() => lutimesSync(path, atime, mtime)).then(() => callback(null), callback);
29
31
  }
30
32
  async function lutimesAsync(path, atime, mtime) {
31
- lutimesSync(path, atime, mtime);
33
+ lutimesSync(path, atime, mtime);
32
34
  }
33
35
  function lchownSync(path, uid, gid) {
34
- GLib.spawn_command_line_sync(`chown -h ${uid}:${gid} ${normalizePath(path)}`);
36
+ GLib.spawn_command_line_sync(`chown -h ${uid}:${gid} ${normalizePath(path)}`);
35
37
  }
36
38
  function lchown(path, uid, gid, callback) {
37
- Promise.resolve().then(() => lchownSync(path, uid, gid)).then(() => callback(null), callback);
39
+ Promise.resolve().then(() => lchownSync(path, uid, gid)).then(() => callback(null), callback);
38
40
  }
39
41
  async function lchownAsync(path, uid, gid) {
40
- lchownSync(path, uid, gid);
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
- callback(null);
46
- }
47
- async function lchmodAsync(_path, _mode) {
48
- }
49
- export {
50
- lchmod,
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 };
@@ -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
- const kIsPerformingIO = /* @__PURE__ */ Symbol("kIsPerformingIO");
5
- const kIoDone = /* @__PURE__ */ Symbol("kIoDone");
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
- return normalizePath(fileURLOrPath);
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
- return new WriteStream(path, opts);
97
+ return new WriteStream(path, opts);
108
98
  }
109
- export {
110
- WriteStream,
111
- createWriteStream,
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.12",
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.12",
38
- "@gjsify/unit": "^0.3.12",
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": "^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.12",
46
- "@gjsify/events": "^0.3.12",
47
- "@gjsify/stream": "^0.3.12",
48
- "@gjsify/url": "^0.3.12",
49
- "@gjsify/utils": "^0.3.12"
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
  }