@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/errors.js CHANGED
@@ -1,13 +1,17 @@
1
- import { createNodeError as createNodeErrorGeneric, isNotFoundError } from "@gjsify/utils";
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
- const pathStr = path.toString();
4
- const error = createNodeErrorGeneric(err, syscall, {
5
- path: pathStr,
6
- dest: dest?.toString()
7
- });
8
- return error;
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
- export {
11
- createNodeError,
12
- isNotFoundError
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 { statSync, truncateSync, chmodSync, chownSync, readFileSync } from "./sync.js";
3
+ import { chmodSync, chownSync, readFileSync, statSync, truncateSync } from "./sync.js";
3
4
  import { utimesSync } from "./utimes.js";
4
- import { normalizePath } from "./utils.js";
5
+
6
+ //#region src/fd-ops.ts
5
7
  function getFH(fd) {
6
- if (fd instanceof FileHandle) return FileHandle.getInstance(fd.fd);
7
- return FileHandle.getInstance(fd);
8
+ if (fd instanceof FileHandle) return FileHandle.getInstance(fd.fd);
9
+ return FileHandle.getInstance(fd);
8
10
  }
9
11
  function fstatSync(fd, options) {
10
- return statSync(normalizePath(getFH(fd).options.path), options);
12
+ return statSync(normalizePath(getFH(fd).options.path), options);
11
13
  }
12
14
  function fstat(fd, optionsOrCb, callback) {
13
- if (typeof optionsOrCb === "function") {
14
- callback = optionsOrCb;
15
- optionsOrCb = {};
16
- }
17
- Promise.resolve().then(() => fstatSync(fd, optionsOrCb)).then((s) => callback(null, s), callback);
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
- return fstatSync(fd, options);
22
+ return fstatSync(fd, options);
21
23
  }
22
24
  function ftruncateSync(fd, len = 0) {
23
- truncateSync(normalizePath(getFH(fd).options.path), len);
25
+ truncateSync(normalizePath(getFH(fd).options.path), len);
24
26
  }
25
27
  function ftruncate(fd, lenOrCb, callback) {
26
- if (typeof lenOrCb === "function") {
27
- callback = lenOrCb;
28
- lenOrCb = 0;
29
- }
30
- Promise.resolve().then(() => ftruncateSync(fd, lenOrCb)).then(() => callback(null), callback);
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
- ftruncateSync(fd, len);
35
+ ftruncateSync(fd, len);
34
36
  }
35
37
  function fdatasyncSync(fd) {
36
- getFH(fd)._flushSync();
38
+ getFH(fd)._flushSync();
37
39
  }
38
40
  function fdatasync(fd, callback) {
39
- Promise.resolve().then(() => fdatasyncSync(fd)).then(() => callback(null), callback);
41
+ Promise.resolve().then(() => fdatasyncSync(fd)).then(() => callback(null), callback);
40
42
  }
41
43
  async function fdatasyncAsync(fd) {
42
- fdatasyncSync(fd);
44
+ fdatasyncSync(fd);
43
45
  }
44
46
  function fsyncSync(fd) {
45
- getFH(fd)._flushSync();
47
+ getFH(fd)._flushSync();
46
48
  }
47
49
  function fsync(fd, callback) {
48
- Promise.resolve().then(() => fsyncSync(fd)).then(() => callback(null), callback);
50
+ Promise.resolve().then(() => fsyncSync(fd)).then(() => callback(null), callback);
49
51
  }
50
52
  async function fsyncAsync(fd) {
51
- fsyncSync(fd);
53
+ fsyncSync(fd);
52
54
  }
53
55
  function fchmodSync(fd, mode) {
54
- chmodSync(normalizePath(getFH(fd).options.path), mode);
56
+ chmodSync(normalizePath(getFH(fd).options.path), mode);
55
57
  }
56
58
  function fchmod(fd, mode, callback) {
57
- Promise.resolve().then(() => fchmodSync(fd, mode)).then(() => callback(null), callback);
59
+ Promise.resolve().then(() => fchmodSync(fd, mode)).then(() => callback(null), callback);
58
60
  }
59
61
  async function fchmodAsync(fd, mode) {
60
- fchmodSync(fd, mode);
62
+ fchmodSync(fd, mode);
61
63
  }
62
64
  function fchownSync(fd, uid, gid) {
63
- chownSync(normalizePath(getFH(fd).options.path), uid, gid);
65
+ chownSync(normalizePath(getFH(fd).options.path), uid, gid);
64
66
  }
65
67
  function fchown(fd, uid, gid, callback) {
66
- Promise.resolve().then(() => fchownSync(fd, uid, gid)).then(() => callback(null), callback);
68
+ Promise.resolve().then(() => fchownSync(fd, uid, gid)).then(() => callback(null), callback);
67
69
  }
68
70
  async function fchownAsync(fd, uid, gid) {
69
- fchownSync(fd, uid, gid);
71
+ fchownSync(fd, uid, gid);
70
72
  }
71
73
  function futimesSync(fd, atime, mtime) {
72
- utimesSync(normalizePath(getFH(fd).options.path), atime, mtime);
74
+ utimesSync(normalizePath(getFH(fd).options.path), atime, mtime);
73
75
  }
74
76
  function futimes(fd, atime, mtime, callback) {
75
- Promise.resolve().then(() => futimesSync(fd, atime, mtime)).then(() => callback(null), callback);
77
+ Promise.resolve().then(() => futimesSync(fd, atime, mtime)).then(() => callback(null), callback);
76
78
  }
77
79
  async function futimesAsync(fd, atime, mtime) {
78
- futimesSync(fd, atime, mtime);
80
+ futimesSync(fd, atime, mtime);
79
81
  }
80
82
  function closeSync(fd) {
81
- getFH(fd)._closeSync();
83
+ getFH(fd)._closeSync();
82
84
  }
83
85
  function readSync(fd, buffer, offsetOrOptions, length, position) {
84
- let offset = 0;
85
- if (offsetOrOptions !== null && typeof offsetOrOptions === "object") {
86
- offset = offsetOrOptions.offset ?? 0;
87
- length = offsetOrOptions.length ?? buffer.byteLength;
88
- position = offsetOrOptions.position ?? null;
89
- } else {
90
- offset = offsetOrOptions ?? 0;
91
- length = length ?? buffer.byteLength - offset;
92
- }
93
- return getFH(fd)._readSync(buffer, offset, length, position ?? null);
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
- let data;
97
- if (typeof bufferOrString === "string") {
98
- data = new TextEncoder().encode(bufferOrString);
99
- if (typeof offsetOrPosition === "number") position = offsetOrPosition;
100
- } else {
101
- const offset = typeof offsetOrPosition === "number" ? offsetOrPosition : 0;
102
- const len = typeof lengthOrEncoding === "number" ? lengthOrEncoding : bufferOrString.byteLength - offset;
103
- data = new Uint8Array(bufferOrString.buffer, bufferOrString.byteOffset + offset, len);
104
- }
105
- return getFH(fd)._writeSync(data, position ?? null);
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
- let bytesRead = 0;
109
- for (const buf of buffers) {
110
- const n = readSync(fd, buf, 0, buf.byteLength, position != null ? position + bytesRead : null);
111
- bytesRead += n;
112
- if (n < buf.byteLength) break;
113
- }
114
- return bytesRead;
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
- if (typeof positionOrCb === "function") {
118
- callback = positionOrCb;
119
- positionOrCb = null;
120
- }
121
- Promise.resolve().then(() => ({ bytesRead: readvSync(fd, buffers, positionOrCb), buffers })).then((r) => callback(null, r.bytesRead, r.buffers), callback);
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
- return { bytesRead: readvSync(fd, buffers, position), buffers };
129
+ return {
130
+ bytesRead: readvSync(fd, buffers, position),
131
+ buffers
132
+ };
125
133
  }
126
134
  function writevSync(fd, buffers, position) {
127
- let bytesWritten = 0;
128
- for (const buf of buffers) {
129
- const n = writeSync(fd, buf, 0, buf.byteLength, position != null ? position + bytesWritten : null);
130
- bytesWritten += n;
131
- }
132
- return bytesWritten;
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
- if (typeof positionOrCb === "function") {
136
- callback = positionOrCb;
137
- positionOrCb = null;
138
- }
139
- Promise.resolve().then(() => ({ bytesWritten: writevSync(fd, buffers, positionOrCb), buffers })).then((r) => callback(null, r.bytesWritten, r.buffers), callback);
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
- return { bytesWritten: writevSync(fd, buffers, position), buffers };
153
+ return {
154
+ bytesWritten: writevSync(fd, buffers, position),
155
+ buffers
156
+ };
143
157
  }
144
158
  function exists(path, callback) {
145
- try {
146
- statSync(normalizePath(path));
147
- callback(true);
148
- } catch {
149
- callback(false);
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
- const data = readFileSync(normalizePath(path));
154
- return new Blob([data], { type: options?.type ?? "" });
155
- }
156
- export {
157
- closeSync,
158
- exists,
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 };