@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.
- 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/promises.js
CHANGED
|
@@ -1,444 +1,471 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { getEncodingFromOptions, encodeUint8Array, decode } from "./encoding.js";
|
|
5
|
-
import { realpathSync, readdirSync as readdirSyncFn, renameSync, copyFileSync, accessSync, appendFileSync, readlinkSync, truncateSync, chmodSync, chownSync, linkSync } from "./sync.js";
|
|
6
|
-
import { cpAsync } from "./cp.js";
|
|
7
|
-
import { opendirAsync } from "./dir.js";
|
|
8
|
-
import { globAsync } from "./glob.js";
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { decode, encodeUint8Array, getEncodingFromOptions } from "./encoding.js";
|
|
3
|
+
import { normalizePath, tempDirPath } from "./utils.js";
|
|
9
4
|
import { watchAsync } from "./fs-watcher.js";
|
|
10
|
-
import { statfsAsync } from "./statfs.js";
|
|
11
|
-
import { utimesAsync, lutimesAsync, lchownAsync, lchmodAsync } from "./utimes.js";
|
|
12
|
-
import {
|
|
13
|
-
fstatAsync,
|
|
14
|
-
ftruncateAsync,
|
|
15
|
-
fdatasyncAsync,
|
|
16
|
-
fsyncAsync,
|
|
17
|
-
fchmodAsync,
|
|
18
|
-
fchownAsync,
|
|
19
|
-
futimesAsync,
|
|
20
|
-
readvAsync,
|
|
21
|
-
writevAsync,
|
|
22
|
-
openAsBlob
|
|
23
|
-
} from "./fd-ops.js";
|
|
24
|
-
import { FileHandle } from "./file-handle.js";
|
|
25
|
-
import { tempDirPath, normalizePath } from "./utils.js";
|
|
26
5
|
import { Dirent } from "./dirent.js";
|
|
27
|
-
import {
|
|
6
|
+
import { BigIntStats, STAT_ATTRIBUTES, Stats } from "./stats.js";
|
|
7
|
+
import { FileHandle } from "./file-handle.js";
|
|
28
8
|
import { createNodeError } from "./errors.js";
|
|
9
|
+
import { accessSync, appendFileSync, chmodSync, chownSync, copyFileSync, linkSync, readdirSync, readlinkSync, realpathSync, renameSync, truncateSync } from "./sync.js";
|
|
10
|
+
import { cpAsync as cpPromises } from "./cp.js";
|
|
11
|
+
import { opendirAsync } from "./dir.js";
|
|
12
|
+
import { globAsync } from "./glob.js";
|
|
13
|
+
import { statfsAsync } from "./statfs.js";
|
|
14
|
+
import { lchmodAsync, lchownAsync, lutimesAsync, utimesAsync } from "./utimes.js";
|
|
15
|
+
import { fchmodAsync, fchownAsync, fdatasyncAsync, fstatAsync, fsyncAsync, ftruncateAsync, futimesAsync, openAsBlob, readvAsync, writevAsync } from "./fd-ops.js";
|
|
16
|
+
import GLib from "@girs/glib-2.0";
|
|
17
|
+
import Gio from "@girs/gio-2.0";
|
|
18
|
+
import { dirname, join } from "node:path";
|
|
19
|
+
|
|
20
|
+
//#region src/promises.ts
|
|
21
|
+
var promises_exports = /* @__PURE__ */ __exportAll({
|
|
22
|
+
access: () => access,
|
|
23
|
+
appendFile: () => appendFile,
|
|
24
|
+
chmod: () => chmod,
|
|
25
|
+
chown: () => chown,
|
|
26
|
+
copyFile: () => copyFile,
|
|
27
|
+
cp: () => cpPromises,
|
|
28
|
+
default: () => promises_default,
|
|
29
|
+
fchmod: () => fchmodAsync,
|
|
30
|
+
fchown: () => fchownAsync,
|
|
31
|
+
fdatasync: () => fdatasyncAsync,
|
|
32
|
+
fstat: () => fstatAsync,
|
|
33
|
+
fsync: () => fsyncAsync,
|
|
34
|
+
ftruncate: () => ftruncateAsync,
|
|
35
|
+
futimes: () => futimesAsync,
|
|
36
|
+
glob: () => globAsync,
|
|
37
|
+
lchmod: () => lchmodAsync,
|
|
38
|
+
lchown: () => lchownAsync,
|
|
39
|
+
link: () => link,
|
|
40
|
+
lstat: () => lstat,
|
|
41
|
+
lutimes: () => lutimesAsync,
|
|
42
|
+
mkdir: () => mkdir,
|
|
43
|
+
mkdtemp: () => mkdtemp,
|
|
44
|
+
open: () => open,
|
|
45
|
+
openAsBlob: () => openAsBlob,
|
|
46
|
+
opendir: () => opendirAsync,
|
|
47
|
+
readFile: () => readFile,
|
|
48
|
+
readdir: () => readdir,
|
|
49
|
+
readlink: () => readlink,
|
|
50
|
+
readv: () => readvAsync,
|
|
51
|
+
realpath: () => realpath,
|
|
52
|
+
rename: () => rename,
|
|
53
|
+
rm: () => rm,
|
|
54
|
+
rmdir: () => rmdir,
|
|
55
|
+
stat: () => stat,
|
|
56
|
+
statfs: () => statfsAsync,
|
|
57
|
+
symlink: () => symlink,
|
|
58
|
+
truncate: () => truncate,
|
|
59
|
+
unlink: () => unlink,
|
|
60
|
+
utimes: () => utimesAsync,
|
|
61
|
+
watch: () => watchAsync,
|
|
62
|
+
write: () => write,
|
|
63
|
+
writeFile: () => writeFile,
|
|
64
|
+
writev: () => writevAsync
|
|
65
|
+
});
|
|
29
66
|
async function mkdir(path, options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
let recursive;
|
|
68
|
+
let _mode = 511;
|
|
69
|
+
if (typeof options === "object") {
|
|
70
|
+
if (options.recursive) recursive = options.recursive;
|
|
71
|
+
if (options.mode) _mode = options.mode;
|
|
72
|
+
} else {
|
|
73
|
+
_mode = options;
|
|
74
|
+
}
|
|
75
|
+
const pathStr = normalizePath(path);
|
|
76
|
+
if (recursive) {
|
|
77
|
+
return mkdirRecursiveAsync(pathStr);
|
|
78
|
+
}
|
|
79
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
file.make_directory_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
82
|
+
try {
|
|
83
|
+
file.make_directory_finish(res);
|
|
84
|
+
resolve(undefined);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
reject(createNodeError(err, "mkdir", pathStr));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
53
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Recursively creates directories, similar to `mkdir -p`.
|
|
93
|
+
* Returns the first directory path created, or undefined if all directories already existed.
|
|
94
|
+
*/
|
|
54
95
|
async function mkdirRecursiveAsync(pathStr) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
97
|
+
try {
|
|
98
|
+
await new Promise((resolve, reject) => {
|
|
99
|
+
file.make_directory_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
100
|
+
try {
|
|
101
|
+
file.make_directory_finish(res);
|
|
102
|
+
resolve();
|
|
103
|
+
} catch (err) {
|
|
104
|
+
reject(err);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
return pathStr;
|
|
109
|
+
} catch (err) {
|
|
110
|
+
const gErr = err;
|
|
111
|
+
if (gErr.code === Gio.IOErrorEnum.EXISTS) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (gErr.code === Gio.IOErrorEnum.NOT_FOUND) {
|
|
115
|
+
const parentPath = dirname(pathStr);
|
|
116
|
+
if (parentPath === pathStr) {
|
|
117
|
+
throw createNodeError(err, "mkdir", pathStr);
|
|
118
|
+
}
|
|
119
|
+
const firstCreated = await mkdirRecursiveAsync(parentPath);
|
|
120
|
+
const retryFile = Gio.File.new_for_path(pathStr);
|
|
121
|
+
await new Promise((resolve, reject) => {
|
|
122
|
+
retryFile.make_directory_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
123
|
+
try {
|
|
124
|
+
retryFile.make_directory_finish(res);
|
|
125
|
+
resolve();
|
|
126
|
+
} catch (retryErr) {
|
|
127
|
+
reject(createNodeError(retryErr, "mkdir", pathStr));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
return firstCreated ?? pathStr;
|
|
132
|
+
}
|
|
133
|
+
throw createNodeError(err, "mkdir", pathStr);
|
|
134
|
+
}
|
|
94
135
|
}
|
|
95
|
-
async function readFile(path, options = {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
136
|
+
async function readFile(path, options = {
|
|
137
|
+
encoding: null,
|
|
138
|
+
flag: "r"
|
|
139
|
+
}) {
|
|
140
|
+
const pathStr = normalizePath(path);
|
|
141
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
142
|
+
let ok;
|
|
143
|
+
let data;
|
|
144
|
+
try {
|
|
145
|
+
[ok, data] = await new Promise((resolve, reject) => {
|
|
146
|
+
file.load_contents_async(null, (self, res) => {
|
|
147
|
+
try {
|
|
148
|
+
resolve(file.load_contents_finish(res));
|
|
149
|
+
} catch (error) {
|
|
150
|
+
reject(error);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
} catch (error) {
|
|
155
|
+
throw createNodeError(error, "open", pathStr);
|
|
156
|
+
}
|
|
157
|
+
if (!ok) {
|
|
158
|
+
throw createNodeError(new Error("failed to read file"), "open", pathStr);
|
|
159
|
+
}
|
|
160
|
+
return encodeUint8Array(getEncodingFromOptions(options, "buffer"), data);
|
|
117
161
|
}
|
|
118
162
|
async function mkdtemp(prefix, options) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
163
|
+
const encoding = getEncodingFromOptions(options);
|
|
164
|
+
const path = tempDirPath(prefix);
|
|
165
|
+
await mkdir(path, {
|
|
166
|
+
recursive: false,
|
|
167
|
+
mode: 448
|
|
168
|
+
});
|
|
169
|
+
return decode(path, encoding);
|
|
126
170
|
}
|
|
127
171
|
async function writeFile(path, data) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
const pathStr = normalizePath(path);
|
|
173
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
174
|
+
let bytes;
|
|
175
|
+
if (typeof data === "string") {
|
|
176
|
+
bytes = new TextEncoder().encode(data);
|
|
177
|
+
} else if (data instanceof Uint8Array) {
|
|
178
|
+
bytes = data;
|
|
179
|
+
} else {
|
|
180
|
+
bytes = new TextEncoder().encode(String(data));
|
|
181
|
+
}
|
|
182
|
+
const outputStream = await new Promise((resolve, reject) => {
|
|
183
|
+
file.replace_async(null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
184
|
+
try {
|
|
185
|
+
resolve(file.replace_finish(res));
|
|
186
|
+
} catch (err) {
|
|
187
|
+
reject(createNodeError(err, "open", pathStr));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
if (bytes.length > 0) {
|
|
192
|
+
const glibBytes = new GLib.Bytes(bytes);
|
|
193
|
+
await new Promise((resolve, reject) => {
|
|
194
|
+
outputStream.write_bytes_async(glibBytes, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
195
|
+
try {
|
|
196
|
+
outputStream.write_bytes_finish(res);
|
|
197
|
+
resolve();
|
|
198
|
+
} catch (err) {
|
|
199
|
+
reject(createNodeError(err, "write", pathStr));
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
await new Promise((resolve, reject) => {
|
|
205
|
+
outputStream.close_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
206
|
+
try {
|
|
207
|
+
outputStream.close_finish(res);
|
|
208
|
+
resolve();
|
|
209
|
+
} catch (err) {
|
|
210
|
+
reject(createNodeError(err, "close", pathStr));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
170
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Removes the directory identified by `path`.
|
|
217
|
+
*
|
|
218
|
+
* Using `fsPromises.rmdir()` on a file (not a directory) results in the
|
|
219
|
+
* promise being rejected with an `ENOENT` error on Windows and an `ENOTDIR`error on POSIX.
|
|
220
|
+
*
|
|
221
|
+
* To get a behavior similar to the `rm -rf` Unix command, use `fsPromises.rm()` with options `{ recursive: true, force: true }`.
|
|
222
|
+
* @since v10.0.0
|
|
223
|
+
* @return Fulfills with `undefined` upon success.
|
|
224
|
+
*/
|
|
171
225
|
async function rmdir(path, _options) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
226
|
+
const pathStr = normalizePath(path);
|
|
227
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
228
|
+
const info = await new Promise((resolve, reject) => {
|
|
229
|
+
file.query_info_async("standard::type", Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
230
|
+
try {
|
|
231
|
+
resolve(file.query_info_finish(res));
|
|
232
|
+
} catch (err) {
|
|
233
|
+
reject(createNodeError(err, "rmdir", pathStr));
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
if (info.get_file_type() !== Gio.FileType.DIRECTORY) {
|
|
238
|
+
const err = Object.assign(new Error(), { code: 4 });
|
|
239
|
+
throw createNodeError(err, "rmdir", pathStr);
|
|
240
|
+
}
|
|
241
|
+
const children = await new Promise((resolve, reject) => {
|
|
242
|
+
file.enumerate_children_async("standard::name", Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
243
|
+
try {
|
|
244
|
+
resolve(file.enumerate_children_finish(res));
|
|
245
|
+
} catch (err) {
|
|
246
|
+
reject(createNodeError(err, "rmdir", pathStr));
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
const firstChild = children.next_file(null);
|
|
251
|
+
if (firstChild !== null) {
|
|
252
|
+
const err = Object.assign(new Error(), { code: 5 });
|
|
253
|
+
throw createNodeError(err, "rmdir", pathStr);
|
|
254
|
+
}
|
|
255
|
+
await new Promise((resolve, reject) => {
|
|
256
|
+
file.delete_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
257
|
+
try {
|
|
258
|
+
file.delete_finish(res);
|
|
259
|
+
resolve();
|
|
260
|
+
} catch (err) {
|
|
261
|
+
reject(createNodeError(err, "rmdir", pathStr));
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
});
|
|
211
265
|
}
|
|
212
266
|
async function unlink(path) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
267
|
+
const pathStr = normalizePath(path);
|
|
268
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
269
|
+
await new Promise((resolve, reject) => {
|
|
270
|
+
file.delete_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
271
|
+
try {
|
|
272
|
+
file.delete_finish(res);
|
|
273
|
+
resolve();
|
|
274
|
+
} catch (err) {
|
|
275
|
+
reject(createNodeError(err, "unlink", pathStr));
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
});
|
|
225
279
|
}
|
|
226
280
|
async function open(path, flags, mode) {
|
|
227
|
-
|
|
281
|
+
return new FileHandle({
|
|
282
|
+
path,
|
|
283
|
+
flags,
|
|
284
|
+
mode
|
|
285
|
+
});
|
|
228
286
|
}
|
|
229
287
|
async function write(fd, data, positionOrOffset, encodingOrLength, position) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
288
|
+
if (typeof data === "string") {
|
|
289
|
+
return _writeStr(fd, data, positionOrOffset, encodingOrLength);
|
|
290
|
+
}
|
|
291
|
+
return _writeBuf(fd, data, positionOrOffset, encodingOrLength, position);
|
|
234
292
|
}
|
|
235
293
|
async function _writeBuf(fd, buffer, offset, length, position) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
294
|
+
const fileHandle = FileHandle.getInstance(fd);
|
|
295
|
+
const result = await fileHandle.write(buffer, offset, length, position);
|
|
296
|
+
return {
|
|
297
|
+
bytesWritten: result.bytesWritten,
|
|
298
|
+
buffer
|
|
299
|
+
};
|
|
239
300
|
}
|
|
240
301
|
async function _writeStr(fd, data, position, encoding) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
302
|
+
const fileHandle = FileHandle.getInstance(fd);
|
|
303
|
+
const result = await fileHandle.write(data, position, encoding);
|
|
304
|
+
return {
|
|
305
|
+
bytesWritten: result.bytesWritten,
|
|
306
|
+
buffer: data
|
|
307
|
+
};
|
|
244
308
|
}
|
|
245
309
|
function queryInfoAsync(path, flags, syscall, options) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
310
|
+
const pathStr = normalizePath(path);
|
|
311
|
+
return new Promise((resolve, reject) => {
|
|
312
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
313
|
+
file.query_info_async(STAT_ATTRIBUTES, flags, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
314
|
+
try {
|
|
315
|
+
const info = file.query_info_finish(res);
|
|
316
|
+
resolve(options?.bigint ? new BigIntStats(info, pathStr) : new Stats(info, pathStr));
|
|
317
|
+
} catch (err) {
|
|
318
|
+
reject(createNodeError(err, syscall, pathStr));
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
});
|
|
258
322
|
}
|
|
259
323
|
async function stat(path, options) {
|
|
260
|
-
|
|
324
|
+
return queryInfoAsync(path, Gio.FileQueryInfoFlags.NONE, "stat", options);
|
|
261
325
|
}
|
|
262
326
|
async function lstat(path, options) {
|
|
263
|
-
|
|
327
|
+
return queryInfoAsync(path, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, "lstat", options);
|
|
264
328
|
}
|
|
265
329
|
async function readdir(path, options) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
330
|
+
try {
|
|
331
|
+
return readdirSync(path, options);
|
|
332
|
+
} catch (error) {
|
|
333
|
+
throw createNodeError(error, "scandir", path);
|
|
334
|
+
}
|
|
271
335
|
}
|
|
272
336
|
async function realpath(path) {
|
|
273
|
-
|
|
337
|
+
return realpathSync(path);
|
|
274
338
|
}
|
|
275
339
|
async function symlink(target, path, _type) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
340
|
+
const pathStr = normalizePath(path);
|
|
341
|
+
const targetStr = normalizePath(target);
|
|
342
|
+
return new Promise((resolve, reject) => {
|
|
343
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
344
|
+
file.make_symbolic_link_async(targetStr, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
345
|
+
try {
|
|
346
|
+
file.make_symbolic_link_finish(res);
|
|
347
|
+
resolve();
|
|
348
|
+
} catch (err) {
|
|
349
|
+
reject(createNodeError(err, "symlink", targetStr, pathStr));
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
});
|
|
289
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Removes files and directories (modeled on the standard POSIX `rm` utility).
|
|
356
|
+
* @since v14.14.0
|
|
357
|
+
* @return Fulfills with `undefined` upon success.
|
|
358
|
+
*/
|
|
290
359
|
async function rm(path, options) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
360
|
+
const pathStr = normalizePath(path);
|
|
361
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
362
|
+
const recursive = options?.recursive || false;
|
|
363
|
+
const force = options?.force || false;
|
|
364
|
+
let dirent;
|
|
365
|
+
try {
|
|
366
|
+
dirent = new Dirent(pathStr);
|
|
367
|
+
} catch (err) {
|
|
368
|
+
if (force) return;
|
|
369
|
+
throw createNodeError(err, "rm", path);
|
|
370
|
+
}
|
|
371
|
+
if (dirent.isDirectory()) {
|
|
372
|
+
const childFiles = await readdir(path, { withFileTypes: true });
|
|
373
|
+
if (!recursive && childFiles.length) {
|
|
374
|
+
const err = Object.assign(new Error(), { code: 5 });
|
|
375
|
+
throw createNodeError(err, "rm", path);
|
|
376
|
+
}
|
|
377
|
+
for (const childFile of childFiles) {
|
|
378
|
+
if (typeof childFile !== "string") {
|
|
379
|
+
await rm(join(pathStr, childFile.name), options);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
await new Promise((resolve, reject) => {
|
|
384
|
+
file.delete_async(GLib.PRIORITY_DEFAULT, null, (_self, res) => {
|
|
385
|
+
try {
|
|
386
|
+
file.delete_finish(res);
|
|
387
|
+
resolve();
|
|
388
|
+
} catch (err) {
|
|
389
|
+
if (force) {
|
|
390
|
+
resolve();
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
reject(createNodeError(err, "rm", path));
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
});
|
|
328
397
|
}
|
|
329
398
|
async function rename(oldPath, newPath) {
|
|
330
|
-
|
|
399
|
+
renameSync(oldPath, newPath);
|
|
331
400
|
}
|
|
332
401
|
async function copyFile(src, dest, mode) {
|
|
333
|
-
|
|
402
|
+
copyFileSync(src, dest, mode);
|
|
334
403
|
}
|
|
335
404
|
async function access(path, mode) {
|
|
336
|
-
|
|
405
|
+
accessSync(path, mode);
|
|
337
406
|
}
|
|
338
407
|
async function appendFile(path, data, options) {
|
|
339
|
-
|
|
408
|
+
appendFileSync(path, data, options);
|
|
340
409
|
}
|
|
341
410
|
async function readlink(path, options) {
|
|
342
|
-
|
|
411
|
+
return readlinkSync(path, options);
|
|
343
412
|
}
|
|
344
413
|
async function truncate(path, len) {
|
|
345
|
-
|
|
414
|
+
truncateSync(path, len);
|
|
346
415
|
}
|
|
347
416
|
async function chmod(path, mode) {
|
|
348
|
-
|
|
417
|
+
chmodSync(path, mode);
|
|
349
418
|
}
|
|
350
419
|
async function chown(path, uid, gid) {
|
|
351
|
-
|
|
420
|
+
chownSync(path, uid, gid);
|
|
352
421
|
}
|
|
353
422
|
async function link(existingPath, newPath) {
|
|
354
|
-
|
|
423
|
+
linkSync(existingPath, newPath);
|
|
355
424
|
}
|
|
356
425
|
var promises_default = {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
};
|
|
400
|
-
export {
|
|
401
|
-
access,
|
|
402
|
-
appendFile,
|
|
403
|
-
chmod,
|
|
404
|
-
chown,
|
|
405
|
-
copyFile,
|
|
406
|
-
cpAsync as cp,
|
|
407
|
-
promises_default as default,
|
|
408
|
-
fchmodAsync as fchmod,
|
|
409
|
-
fchownAsync as fchown,
|
|
410
|
-
fdatasyncAsync as fdatasync,
|
|
411
|
-
fstatAsync as fstat,
|
|
412
|
-
fsyncAsync as fsync,
|
|
413
|
-
ftruncateAsync as ftruncate,
|
|
414
|
-
futimesAsync as futimes,
|
|
415
|
-
globAsync as glob,
|
|
416
|
-
lchmodAsync as lchmod,
|
|
417
|
-
lchownAsync as lchown,
|
|
418
|
-
link,
|
|
419
|
-
lstat,
|
|
420
|
-
lutimesAsync as lutimes,
|
|
421
|
-
mkdir,
|
|
422
|
-
mkdtemp,
|
|
423
|
-
open,
|
|
424
|
-
openAsBlob,
|
|
425
|
-
opendirAsync as opendir,
|
|
426
|
-
readFile,
|
|
427
|
-
readdir,
|
|
428
|
-
readlink,
|
|
429
|
-
readvAsync as readv,
|
|
430
|
-
realpath,
|
|
431
|
-
rename,
|
|
432
|
-
rm,
|
|
433
|
-
rmdir,
|
|
434
|
-
stat,
|
|
435
|
-
statfsAsync as statfs,
|
|
436
|
-
symlink,
|
|
437
|
-
truncate,
|
|
438
|
-
unlink,
|
|
439
|
-
utimesAsync as utimes,
|
|
440
|
-
watchAsync as watch,
|
|
441
|
-
write,
|
|
442
|
-
writeFile,
|
|
443
|
-
writevAsync as writev
|
|
426
|
+
readFile,
|
|
427
|
+
mkdir,
|
|
428
|
+
mkdtemp,
|
|
429
|
+
realpath,
|
|
430
|
+
readdir,
|
|
431
|
+
writeFile,
|
|
432
|
+
rmdir,
|
|
433
|
+
unlink,
|
|
434
|
+
open,
|
|
435
|
+
write,
|
|
436
|
+
rm,
|
|
437
|
+
lstat,
|
|
438
|
+
symlink,
|
|
439
|
+
stat,
|
|
440
|
+
rename,
|
|
441
|
+
copyFile,
|
|
442
|
+
access,
|
|
443
|
+
appendFile,
|
|
444
|
+
readlink,
|
|
445
|
+
truncate,
|
|
446
|
+
chmod,
|
|
447
|
+
chown,
|
|
448
|
+
link,
|
|
449
|
+
cp: cpPromises,
|
|
450
|
+
opendir: opendirAsync,
|
|
451
|
+
glob: globAsync,
|
|
452
|
+
watch: watchAsync,
|
|
453
|
+
statfs: statfsAsync,
|
|
454
|
+
utimes: utimesAsync,
|
|
455
|
+
lutimes: lutimesAsync,
|
|
456
|
+
lchown: lchownAsync,
|
|
457
|
+
lchmod: lchmodAsync,
|
|
458
|
+
fstat: fstatAsync,
|
|
459
|
+
ftruncate: ftruncateAsync,
|
|
460
|
+
fdatasync: fdatasyncAsync,
|
|
461
|
+
fsync: fsyncAsync,
|
|
462
|
+
fchmod: fchmodAsync,
|
|
463
|
+
fchown: fchownAsync,
|
|
464
|
+
futimes: futimesAsync,
|
|
465
|
+
readv: readvAsync,
|
|
466
|
+
writev: writevAsync,
|
|
467
|
+
openAsBlob
|
|
444
468
|
};
|
|
469
|
+
|
|
470
|
+
//#endregion
|
|
471
|
+
export { access, appendFile, chmod, chown, copyFile, cpPromises as cp, promises_default as default, fchmodAsync as fchmod, fchownAsync as fchown, fdatasyncAsync as fdatasync, fstatAsync as fstat, fsyncAsync as fsync, ftruncateAsync as ftruncate, futimesAsync as futimes, globAsync as glob, lchmodAsync as lchmod, lchownAsync as lchown, link, lstat, lutimesAsync as lutimes, mkdir, mkdtemp, open, openAsBlob, opendirAsync as opendir, promises_exports, readFile, readdir, readlink, readvAsync as readv, realpath, rename, rm, rmdir, stat, statfsAsync as statfs, symlink, truncate, unlink, utimesAsync as utimes, watchAsync as watch, write, writeFile, writevAsync as writev };
|