@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/errors.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { createNodeError as
|
|
1
|
+
import { createNodeError as createNodeError$1, isNotFoundError } from "@gjsify/utils";
|
|
2
|
+
|
|
3
|
+
//#region src/errors.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create a Node.js-style ErrnoException from a Gio error, with fs-specific path/dest fields.
|
|
6
|
+
*/
|
|
2
7
|
function createNodeError(err, syscall, path, dest) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const pathStr = path.toString();
|
|
9
|
+
const error = createNodeError$1(err, syscall, {
|
|
10
|
+
path: pathStr,
|
|
11
|
+
dest: dest?.toString()
|
|
12
|
+
});
|
|
13
|
+
return error;
|
|
9
14
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createNodeError, isNotFoundError };
|
package/lib/esm/fd-ops.js
CHANGED
|
@@ -1,189 +1,172 @@
|
|
|
1
|
+
import { normalizePath } from "./utils.js";
|
|
1
2
|
import { FileHandle } from "./file-handle.js";
|
|
2
|
-
import {
|
|
3
|
+
import { chmodSync, chownSync, readFileSync, statSync, truncateSync } from "./sync.js";
|
|
3
4
|
import { utimesSync } from "./utimes.js";
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
//#region src/fd-ops.ts
|
|
5
7
|
function getFH(fd) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
if (fd instanceof FileHandle) return FileHandle.getInstance(fd.fd);
|
|
9
|
+
return FileHandle.getInstance(fd);
|
|
8
10
|
}
|
|
9
11
|
function fstatSync(fd, options) {
|
|
10
|
-
|
|
12
|
+
return statSync(normalizePath(getFH(fd).options.path), options);
|
|
11
13
|
}
|
|
12
14
|
function fstat(fd, optionsOrCb, callback) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (typeof optionsOrCb === "function") {
|
|
16
|
+
callback = optionsOrCb;
|
|
17
|
+
optionsOrCb = {};
|
|
18
|
+
}
|
|
19
|
+
Promise.resolve().then(() => fstatSync(fd, optionsOrCb)).then((s) => callback(null, s), callback);
|
|
18
20
|
}
|
|
19
21
|
async function fstatAsync(fd, options) {
|
|
20
|
-
|
|
22
|
+
return fstatSync(fd, options);
|
|
21
23
|
}
|
|
22
24
|
function ftruncateSync(fd, len = 0) {
|
|
23
|
-
|
|
25
|
+
truncateSync(normalizePath(getFH(fd).options.path), len);
|
|
24
26
|
}
|
|
25
27
|
function ftruncate(fd, lenOrCb, callback) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if (typeof lenOrCb === "function") {
|
|
29
|
+
callback = lenOrCb;
|
|
30
|
+
lenOrCb = 0;
|
|
31
|
+
}
|
|
32
|
+
Promise.resolve().then(() => ftruncateSync(fd, lenOrCb)).then(() => callback(null), callback);
|
|
31
33
|
}
|
|
32
34
|
async function ftruncateAsync(fd, len = 0) {
|
|
33
|
-
|
|
35
|
+
ftruncateSync(fd, len);
|
|
34
36
|
}
|
|
35
37
|
function fdatasyncSync(fd) {
|
|
36
|
-
|
|
38
|
+
getFH(fd)._flushSync();
|
|
37
39
|
}
|
|
38
40
|
function fdatasync(fd, callback) {
|
|
39
|
-
|
|
41
|
+
Promise.resolve().then(() => fdatasyncSync(fd)).then(() => callback(null), callback);
|
|
40
42
|
}
|
|
41
43
|
async function fdatasyncAsync(fd) {
|
|
42
|
-
|
|
44
|
+
fdatasyncSync(fd);
|
|
43
45
|
}
|
|
44
46
|
function fsyncSync(fd) {
|
|
45
|
-
|
|
47
|
+
getFH(fd)._flushSync();
|
|
46
48
|
}
|
|
47
49
|
function fsync(fd, callback) {
|
|
48
|
-
|
|
50
|
+
Promise.resolve().then(() => fsyncSync(fd)).then(() => callback(null), callback);
|
|
49
51
|
}
|
|
50
52
|
async function fsyncAsync(fd) {
|
|
51
|
-
|
|
53
|
+
fsyncSync(fd);
|
|
52
54
|
}
|
|
53
55
|
function fchmodSync(fd, mode) {
|
|
54
|
-
|
|
56
|
+
chmodSync(normalizePath(getFH(fd).options.path), mode);
|
|
55
57
|
}
|
|
56
58
|
function fchmod(fd, mode, callback) {
|
|
57
|
-
|
|
59
|
+
Promise.resolve().then(() => fchmodSync(fd, mode)).then(() => callback(null), callback);
|
|
58
60
|
}
|
|
59
61
|
async function fchmodAsync(fd, mode) {
|
|
60
|
-
|
|
62
|
+
fchmodSync(fd, mode);
|
|
61
63
|
}
|
|
62
64
|
function fchownSync(fd, uid, gid) {
|
|
63
|
-
|
|
65
|
+
chownSync(normalizePath(getFH(fd).options.path), uid, gid);
|
|
64
66
|
}
|
|
65
67
|
function fchown(fd, uid, gid, callback) {
|
|
66
|
-
|
|
68
|
+
Promise.resolve().then(() => fchownSync(fd, uid, gid)).then(() => callback(null), callback);
|
|
67
69
|
}
|
|
68
70
|
async function fchownAsync(fd, uid, gid) {
|
|
69
|
-
|
|
71
|
+
fchownSync(fd, uid, gid);
|
|
70
72
|
}
|
|
71
73
|
function futimesSync(fd, atime, mtime) {
|
|
72
|
-
|
|
74
|
+
utimesSync(normalizePath(getFH(fd).options.path), atime, mtime);
|
|
73
75
|
}
|
|
74
76
|
function futimes(fd, atime, mtime, callback) {
|
|
75
|
-
|
|
77
|
+
Promise.resolve().then(() => futimesSync(fd, atime, mtime)).then(() => callback(null), callback);
|
|
76
78
|
}
|
|
77
79
|
async function futimesAsync(fd, atime, mtime) {
|
|
78
|
-
|
|
80
|
+
futimesSync(fd, atime, mtime);
|
|
79
81
|
}
|
|
80
82
|
function closeSync(fd) {
|
|
81
|
-
|
|
83
|
+
getFH(fd)._closeSync();
|
|
82
84
|
}
|
|
83
85
|
function readSync(fd, buffer, offsetOrOptions, length, position) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
let offset = 0;
|
|
87
|
+
if (offsetOrOptions !== null && typeof offsetOrOptions === "object") {
|
|
88
|
+
offset = offsetOrOptions.offset ?? 0;
|
|
89
|
+
length = offsetOrOptions.length ?? buffer.byteLength;
|
|
90
|
+
position = offsetOrOptions.position ?? null;
|
|
91
|
+
} else {
|
|
92
|
+
offset = offsetOrOptions ?? 0;
|
|
93
|
+
length = length ?? buffer.byteLength - offset;
|
|
94
|
+
}
|
|
95
|
+
return getFH(fd)._readSync(buffer, offset, length, position ?? null);
|
|
94
96
|
}
|
|
95
97
|
function writeSync(fd, bufferOrString, offsetOrPosition, lengthOrEncoding, position) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
let data;
|
|
99
|
+
if (typeof bufferOrString === "string") {
|
|
100
|
+
data = new TextEncoder().encode(bufferOrString);
|
|
101
|
+
if (typeof offsetOrPosition === "number") position = offsetOrPosition;
|
|
102
|
+
} else {
|
|
103
|
+
const offset = typeof offsetOrPosition === "number" ? offsetOrPosition : 0;
|
|
104
|
+
const len = typeof lengthOrEncoding === "number" ? lengthOrEncoding : bufferOrString.byteLength - offset;
|
|
105
|
+
data = new Uint8Array(bufferOrString.buffer, bufferOrString.byteOffset + offset, len);
|
|
106
|
+
}
|
|
107
|
+
return getFH(fd)._writeSync(data, position ?? null);
|
|
106
108
|
}
|
|
107
109
|
function readvSync(fd, buffers, position) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
let bytesRead = 0;
|
|
111
|
+
for (const buf of buffers) {
|
|
112
|
+
const n = readSync(fd, buf, 0, buf.byteLength, position != null ? position + bytesRead : null);
|
|
113
|
+
bytesRead += n;
|
|
114
|
+
if (n < buf.byteLength) break;
|
|
115
|
+
}
|
|
116
|
+
return bytesRead;
|
|
115
117
|
}
|
|
116
118
|
function readv(fd, buffers, positionOrCb, callback) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
if (typeof positionOrCb === "function") {
|
|
120
|
+
callback = positionOrCb;
|
|
121
|
+
positionOrCb = null;
|
|
122
|
+
}
|
|
123
|
+
Promise.resolve().then(() => ({
|
|
124
|
+
bytesRead: readvSync(fd, buffers, positionOrCb),
|
|
125
|
+
buffers
|
|
126
|
+
})).then((r) => callback(null, r.bytesRead, r.buffers), callback);
|
|
122
127
|
}
|
|
123
128
|
async function readvAsync(fd, buffers, position) {
|
|
124
|
-
|
|
129
|
+
return {
|
|
130
|
+
bytesRead: readvSync(fd, buffers, position),
|
|
131
|
+
buffers
|
|
132
|
+
};
|
|
125
133
|
}
|
|
126
134
|
function writevSync(fd, buffers, position) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
let bytesWritten = 0;
|
|
136
|
+
for (const buf of buffers) {
|
|
137
|
+
const n = writeSync(fd, buf, 0, buf.byteLength, position != null ? position + bytesWritten : null);
|
|
138
|
+
bytesWritten += n;
|
|
139
|
+
}
|
|
140
|
+
return bytesWritten;
|
|
133
141
|
}
|
|
134
142
|
function writev(fd, buffers, positionOrCb, callback) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
if (typeof positionOrCb === "function") {
|
|
144
|
+
callback = positionOrCb;
|
|
145
|
+
positionOrCb = null;
|
|
146
|
+
}
|
|
147
|
+
Promise.resolve().then(() => ({
|
|
148
|
+
bytesWritten: writevSync(fd, buffers, positionOrCb),
|
|
149
|
+
buffers
|
|
150
|
+
})).then((r) => callback(null, r.bytesWritten, r.buffers), callback);
|
|
140
151
|
}
|
|
141
152
|
async function writevAsync(fd, buffers, position) {
|
|
142
|
-
|
|
153
|
+
return {
|
|
154
|
+
bytesWritten: writevSync(fd, buffers, position),
|
|
155
|
+
buffers
|
|
156
|
+
};
|
|
143
157
|
}
|
|
144
158
|
function exists(path, callback) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
try {
|
|
160
|
+
statSync(normalizePath(path));
|
|
161
|
+
callback(true);
|
|
162
|
+
} catch {
|
|
163
|
+
callback(false);
|
|
164
|
+
}
|
|
151
165
|
}
|
|
152
166
|
async function openAsBlob(path, options) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
fchmod,
|
|
160
|
-
fchmodAsync,
|
|
161
|
-
fchmodSync,
|
|
162
|
-
fchown,
|
|
163
|
-
fchownAsync,
|
|
164
|
-
fchownSync,
|
|
165
|
-
fdatasync,
|
|
166
|
-
fdatasyncAsync,
|
|
167
|
-
fdatasyncSync,
|
|
168
|
-
fstat,
|
|
169
|
-
fstatAsync,
|
|
170
|
-
fstatSync,
|
|
171
|
-
fsync,
|
|
172
|
-
fsyncAsync,
|
|
173
|
-
fsyncSync,
|
|
174
|
-
ftruncate,
|
|
175
|
-
ftruncateAsync,
|
|
176
|
-
ftruncateSync,
|
|
177
|
-
futimes,
|
|
178
|
-
futimesAsync,
|
|
179
|
-
futimesSync,
|
|
180
|
-
openAsBlob,
|
|
181
|
-
readSync,
|
|
182
|
-
readv,
|
|
183
|
-
readvAsync,
|
|
184
|
-
readvSync,
|
|
185
|
-
writeSync,
|
|
186
|
-
writev,
|
|
187
|
-
writevAsync,
|
|
188
|
-
writevSync
|
|
189
|
-
};
|
|
167
|
+
const data = readFileSync(normalizePath(path));
|
|
168
|
+
return new Blob([data], { type: options?.type ?? "" });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
export { closeSync, exists, fchmod, fchmodAsync, fchmodSync, fchown, fchownAsync, fchownSync, fdatasync, fdatasyncAsync, fdatasyncSync, fstat, fstatAsync, fstatSync, fsync, fsyncAsync, fsyncSync, ftruncate, ftruncateAsync, ftruncateSync, futimes, futimesAsync, futimesSync, openAsBlob, readSync, readv, readvAsync, readvSync, writeSync, writev, writevAsync, writevSync };
|