@gjsify/fs 0.3.13 → 0.3.15

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/stats.js CHANGED
@@ -1,165 +1,172 @@
1
- import Gio from "@girs/gio-2.0";
2
1
  import { Dirent } from "./dirent.js";
2
+ import Gio from "@girs/gio-2.0";
3
3
  import { basename } from "node:path";
4
+
5
+ //#region src/stats.ts
4
6
  const STAT_ATTRIBUTES = "standard::*,time::*,unix::*";
5
7
  function populateFromInfo(info) {
6
- const atimeSec = info.get_attribute_uint64("time::access");
7
- const atimeUsec = info.get_attribute_uint32("time::access-usec") || 0;
8
- const mtimeSec = info.get_attribute_uint64("time::modified");
9
- const mtimeUsec = info.get_attribute_uint32("time::modified-usec") || 0;
10
- const ctimeSec = info.get_attribute_uint64("time::changed");
11
- const ctimeUsec = info.get_attribute_uint32("time::changed-usec") || 0;
12
- const createdSec = info.get_attribute_uint64("time::created");
13
- const createdUsec = info.get_attribute_uint32("time::created-usec") || 0;
14
- const atimeMs = atimeSec * 1e3 + atimeUsec / 1e3;
15
- const mtimeMs = mtimeSec * 1e3 + mtimeUsec / 1e3;
16
- const ctimeMs = ctimeSec ? ctimeSec * 1e3 + ctimeUsec / 1e3 : mtimeMs;
17
- const birthtimeMs = createdSec ? createdSec * 1e3 + createdUsec / 1e3 : ctimeMs;
18
- return {
19
- dev: info.get_attribute_uint32("unix::device") || 0,
20
- ino: Number(info.get_attribute_uint64("unix::inode") || 0),
21
- mode: info.get_attribute_uint32("unix::mode") || 0,
22
- nlink: info.get_attribute_uint32("unix::nlink") || 0,
23
- uid: info.get_attribute_uint32("unix::uid") || 0,
24
- gid: info.get_attribute_uint32("unix::gid") || 0,
25
- rdev: info.get_attribute_uint32("unix::rdev") || 0,
26
- size: Number(info.get_size() || 0),
27
- blksize: info.get_attribute_uint32("unix::block-size") || 4096,
28
- blocks: Number(info.get_attribute_uint64("unix::blocks") || 0),
29
- atimeMs,
30
- mtimeMs,
31
- ctimeMs,
32
- birthtimeMs,
33
- atime: new Date(atimeMs),
34
- mtime: new Date(mtimeMs),
35
- ctime: new Date(ctimeMs),
36
- birthtime: new Date(birthtimeMs)
37
- };
38
- }
39
- class Stats extends Dirent {
40
- dev;
41
- ino;
42
- mode;
43
- nlink;
44
- uid;
45
- gid;
46
- rdev;
47
- size;
48
- blksize;
49
- blocks;
50
- atimeMs;
51
- mtimeMs;
52
- ctimeMs;
53
- birthtimeMs;
54
- atime;
55
- mtime;
56
- ctime;
57
- birthtime;
58
- _info;
59
- constructor(infoOrPath, pathOrFilename, filename) {
60
- let info;
61
- let pathStr;
62
- if (infoOrPath instanceof Gio.FileInfo) {
63
- info = infoOrPath;
64
- pathStr = pathOrFilename.toString();
65
- if (!filename) filename = basename(pathStr);
66
- } else {
67
- pathStr = infoOrPath.toString();
68
- if (typeof pathOrFilename === "string") filename = pathOrFilename;
69
- if (!filename) filename = basename(pathStr);
70
- const file = Gio.File.new_for_path(pathStr);
71
- info = file.query_info(STAT_ATTRIBUTES, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
72
- }
73
- super(pathStr, filename, info.get_file_type());
74
- this._info = info;
75
- const data = populateFromInfo(info);
76
- this.dev = data.dev;
77
- this.ino = data.ino;
78
- this.mode = data.mode;
79
- this.nlink = data.nlink;
80
- this.uid = data.uid;
81
- this.gid = data.gid;
82
- this.rdev = data.rdev;
83
- this.size = data.size;
84
- this.blksize = data.blksize;
85
- this.blocks = data.blocks;
86
- this.atimeMs = data.atimeMs;
87
- this.mtimeMs = data.mtimeMs;
88
- this.ctimeMs = data.ctimeMs;
89
- this.birthtimeMs = data.birthtimeMs;
90
- this.atime = data.atime;
91
- this.mtime = data.mtime;
92
- this.ctime = data.ctime;
93
- this.birthtime = data.birthtime;
94
- }
8
+ const atimeSec = info.get_attribute_uint64("time::access");
9
+ const atimeUsec = info.get_attribute_uint32("time::access-usec") || 0;
10
+ const mtimeSec = info.get_attribute_uint64("time::modified");
11
+ const mtimeUsec = info.get_attribute_uint32("time::modified-usec") || 0;
12
+ const ctimeSec = info.get_attribute_uint64("time::changed");
13
+ const ctimeUsec = info.get_attribute_uint32("time::changed-usec") || 0;
14
+ const createdSec = info.get_attribute_uint64("time::created");
15
+ const createdUsec = info.get_attribute_uint32("time::created-usec") || 0;
16
+ const atimeMs = atimeSec * 1e3 + atimeUsec / 1e3;
17
+ const mtimeMs = mtimeSec * 1e3 + mtimeUsec / 1e3;
18
+ const ctimeMs = ctimeSec ? ctimeSec * 1e3 + ctimeUsec / 1e3 : mtimeMs;
19
+ const birthtimeMs = createdSec ? createdSec * 1e3 + createdUsec / 1e3 : ctimeMs;
20
+ return {
21
+ dev: info.get_attribute_uint32("unix::device") || 0,
22
+ ino: Number(info.get_attribute_uint64("unix::inode") || 0),
23
+ mode: info.get_attribute_uint32("unix::mode") || 0,
24
+ nlink: info.get_attribute_uint32("unix::nlink") || 0,
25
+ uid: info.get_attribute_uint32("unix::uid") || 0,
26
+ gid: info.get_attribute_uint32("unix::gid") || 0,
27
+ rdev: info.get_attribute_uint32("unix::rdev") || 0,
28
+ size: Number(info.get_size() || 0),
29
+ blksize: info.get_attribute_uint32("unix::block-size") || 4096,
30
+ blocks: Number(info.get_attribute_uint64("unix::blocks") || 0),
31
+ atimeMs,
32
+ mtimeMs,
33
+ ctimeMs,
34
+ birthtimeMs,
35
+ atime: new Date(atimeMs),
36
+ mtime: new Date(mtimeMs),
37
+ ctime: new Date(ctimeMs),
38
+ birthtime: new Date(birthtimeMs)
39
+ };
95
40
  }
96
- class BigIntStats extends Dirent {
97
- dev;
98
- ino;
99
- mode;
100
- nlink;
101
- uid;
102
- gid;
103
- rdev;
104
- size;
105
- blksize;
106
- blocks;
107
- atimeMs;
108
- mtimeMs;
109
- ctimeMs;
110
- birthtimeMs;
111
- atimeNs;
112
- mtimeNs;
113
- ctimeNs;
114
- birthtimeNs;
115
- atime;
116
- mtime;
117
- ctime;
118
- birthtime;
119
- _info;
120
- constructor(infoOrPath, pathOrFilename, filename) {
121
- let info;
122
- let pathStr;
123
- if (infoOrPath instanceof Gio.FileInfo) {
124
- info = infoOrPath;
125
- pathStr = pathOrFilename.toString();
126
- if (!filename) filename = basename(pathStr);
127
- } else {
128
- pathStr = infoOrPath.toString();
129
- if (typeof pathOrFilename === "string") filename = pathOrFilename;
130
- if (!filename) filename = basename(pathStr);
131
- const file = Gio.File.new_for_path(pathStr);
132
- info = file.query_info(STAT_ATTRIBUTES, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
133
- }
134
- super(pathStr, filename, info.get_file_type());
135
- this._info = info;
136
- const data = populateFromInfo(info);
137
- this.dev = BigInt(data.dev);
138
- this.ino = BigInt(data.ino);
139
- this.mode = BigInt(data.mode);
140
- this.nlink = BigInt(data.nlink);
141
- this.uid = BigInt(data.uid);
142
- this.gid = BigInt(data.gid);
143
- this.rdev = BigInt(data.rdev);
144
- this.size = BigInt(data.size);
145
- this.blksize = BigInt(data.blksize);
146
- this.blocks = BigInt(data.blocks);
147
- this.atimeMs = BigInt(Math.trunc(data.atimeMs));
148
- this.mtimeMs = BigInt(Math.trunc(data.mtimeMs));
149
- this.ctimeMs = BigInt(Math.trunc(data.ctimeMs));
150
- this.birthtimeMs = BigInt(Math.trunc(data.birthtimeMs));
151
- this.atimeNs = this.atimeMs * 1000000n;
152
- this.mtimeNs = this.mtimeMs * 1000000n;
153
- this.ctimeNs = this.ctimeMs * 1000000n;
154
- this.birthtimeNs = this.birthtimeMs * 1000000n;
155
- this.atime = data.atime;
156
- this.mtime = data.mtime;
157
- this.ctime = data.ctime;
158
- this.birthtime = data.birthtime;
159
- }
160
- }
161
- export {
162
- BigIntStats,
163
- STAT_ATTRIBUTES,
164
- Stats
41
+ /**
42
+ * A `fs.Stats` object provides information about a file.
43
+ * @since v0.1.21
44
+ */
45
+ var Stats = class extends Dirent {
46
+ dev;
47
+ ino;
48
+ mode;
49
+ nlink;
50
+ uid;
51
+ gid;
52
+ rdev;
53
+ size;
54
+ blksize;
55
+ blocks;
56
+ atimeMs;
57
+ mtimeMs;
58
+ ctimeMs;
59
+ birthtimeMs;
60
+ atime;
61
+ mtime;
62
+ ctime;
63
+ birthtime;
64
+ _info;
65
+ constructor(infoOrPath, pathOrFilename, filename) {
66
+ let info;
67
+ let pathStr;
68
+ if (infoOrPath instanceof Gio.FileInfo) {
69
+ info = infoOrPath;
70
+ pathStr = pathOrFilename.toString();
71
+ if (!filename) filename = basename(pathStr);
72
+ } else {
73
+ pathStr = infoOrPath.toString();
74
+ if (typeof pathOrFilename === "string") filename = pathOrFilename;
75
+ if (!filename) filename = basename(pathStr);
76
+ const file = Gio.File.new_for_path(pathStr);
77
+ info = file.query_info(STAT_ATTRIBUTES, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
78
+ }
79
+ super(pathStr, filename, info.get_file_type());
80
+ this._info = info;
81
+ const data = populateFromInfo(info);
82
+ this.dev = data.dev;
83
+ this.ino = data.ino;
84
+ this.mode = data.mode;
85
+ this.nlink = data.nlink;
86
+ this.uid = data.uid;
87
+ this.gid = data.gid;
88
+ this.rdev = data.rdev;
89
+ this.size = data.size;
90
+ this.blksize = data.blksize;
91
+ this.blocks = data.blocks;
92
+ this.atimeMs = data.atimeMs;
93
+ this.mtimeMs = data.mtimeMs;
94
+ this.ctimeMs = data.ctimeMs;
95
+ this.birthtimeMs = data.birthtimeMs;
96
+ this.atime = data.atime;
97
+ this.mtime = data.mtime;
98
+ this.ctime = data.ctime;
99
+ this.birthtime = data.birthtime;
100
+ }
101
+ };
102
+ /**
103
+ * BigIntStats — same as Stats but with bigint fields and nanosecond precision.
104
+ */
105
+ var BigIntStats = class extends Dirent {
106
+ dev;
107
+ ino;
108
+ mode;
109
+ nlink;
110
+ uid;
111
+ gid;
112
+ rdev;
113
+ size;
114
+ blksize;
115
+ blocks;
116
+ atimeMs;
117
+ mtimeMs;
118
+ ctimeMs;
119
+ birthtimeMs;
120
+ atimeNs;
121
+ mtimeNs;
122
+ ctimeNs;
123
+ birthtimeNs;
124
+ atime;
125
+ mtime;
126
+ ctime;
127
+ birthtime;
128
+ _info;
129
+ constructor(infoOrPath, pathOrFilename, filename) {
130
+ let info;
131
+ let pathStr;
132
+ if (infoOrPath instanceof Gio.FileInfo) {
133
+ info = infoOrPath;
134
+ pathStr = pathOrFilename.toString();
135
+ if (!filename) filename = basename(pathStr);
136
+ } else {
137
+ pathStr = infoOrPath.toString();
138
+ if (typeof pathOrFilename === "string") filename = pathOrFilename;
139
+ if (!filename) filename = basename(pathStr);
140
+ const file = Gio.File.new_for_path(pathStr);
141
+ info = file.query_info(STAT_ATTRIBUTES, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
142
+ }
143
+ super(pathStr, filename, info.get_file_type());
144
+ this._info = info;
145
+ const data = populateFromInfo(info);
146
+ this.dev = BigInt(data.dev);
147
+ this.ino = BigInt(data.ino);
148
+ this.mode = BigInt(data.mode);
149
+ this.nlink = BigInt(data.nlink);
150
+ this.uid = BigInt(data.uid);
151
+ this.gid = BigInt(data.gid);
152
+ this.rdev = BigInt(data.rdev);
153
+ this.size = BigInt(data.size);
154
+ this.blksize = BigInt(data.blksize);
155
+ this.blocks = BigInt(data.blocks);
156
+ this.atimeMs = BigInt(Math.trunc(data.atimeMs));
157
+ this.mtimeMs = BigInt(Math.trunc(data.mtimeMs));
158
+ this.ctimeMs = BigInt(Math.trunc(data.ctimeMs));
159
+ this.birthtimeMs = BigInt(Math.trunc(data.birthtimeMs));
160
+ this.atimeNs = this.atimeMs * 1000000n;
161
+ this.mtimeNs = this.mtimeMs * 1000000n;
162
+ this.ctimeNs = this.ctimeMs * 1000000n;
163
+ this.birthtimeNs = this.birthtimeMs * 1000000n;
164
+ this.atime = data.atime;
165
+ this.mtime = data.mtime;
166
+ this.ctime = data.ctime;
167
+ this.birthtime = data.birthtime;
168
+ }
165
169
  };
170
+
171
+ //#endregion
172
+ export { BigIntStats, STAT_ATTRIBUTES, Stats };