@mikestools/usefilesystem 0.0.1 → 0.0.3
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/README.md +516 -114
- package/dist/index.d.ts +150 -191
- package/dist/usefilesystem.js +595 -425
- package/dist/usefilesystem.umd.cjs +1 -1
- package/package.json +4 -2
package/dist/usefilesystem.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { shallowRef as
|
|
2
|
-
function
|
|
3
|
-
const
|
|
1
|
+
import { shallowRef as se, computed as U } from "vue";
|
|
2
|
+
function ce() {
|
|
3
|
+
const h = {
|
|
4
4
|
name: "",
|
|
5
5
|
path: "/",
|
|
6
6
|
createdAt: Date.now(),
|
|
7
7
|
files: /* @__PURE__ */ new Map(),
|
|
8
8
|
directories: /* @__PURE__ */ new Map()
|
|
9
|
-
},
|
|
10
|
-
function
|
|
11
|
-
for (const
|
|
12
|
-
|
|
9
|
+
}, p = /* @__PURE__ */ new Set();
|
|
10
|
+
function b(e, t, r) {
|
|
11
|
+
for (const n of p)
|
|
12
|
+
n(e, t, r);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
const t = e.split(/[/\\]/).filter((
|
|
16
|
-
for (const
|
|
17
|
-
|
|
18
|
-
return "/" +
|
|
14
|
+
function u(e) {
|
|
15
|
+
const t = e.split(/[/\\]/).filter((n) => n.length > 0 && n !== "."), r = [];
|
|
16
|
+
for (const n of t)
|
|
17
|
+
n === ".." ? r.pop() : r.push(n);
|
|
18
|
+
return "/" + r.join("/");
|
|
19
19
|
}
|
|
20
20
|
function l(e) {
|
|
21
|
-
const t =
|
|
22
|
-
return { segments: t.split("/").filter((
|
|
21
|
+
const t = u(e);
|
|
22
|
+
return { segments: t.split("/").filter((n) => n.length > 0), normalized: t };
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function y(e) {
|
|
25
25
|
const { segments: t } = l(e);
|
|
26
26
|
if (t.length === 0)
|
|
27
27
|
return { parentPath: "/", name: "" };
|
|
28
|
-
const
|
|
29
|
-
return { parentPath: "/" + t.slice(0, -1).join("/"), name:
|
|
30
|
-
}
|
|
31
|
-
function
|
|
32
|
-
const { segments:
|
|
33
|
-
let
|
|
34
|
-
for (const
|
|
35
|
-
let
|
|
36
|
-
if (!
|
|
28
|
+
const r = t[t.length - 1] ?? "";
|
|
29
|
+
return { parentPath: "/" + t.slice(0, -1).join("/"), name: r };
|
|
30
|
+
}
|
|
31
|
+
function d(e, t = !1) {
|
|
32
|
+
const { segments: r } = l(e);
|
|
33
|
+
let n = h;
|
|
34
|
+
for (const o of r) {
|
|
35
|
+
let c = n.directories.get(o);
|
|
36
|
+
if (!c) {
|
|
37
37
|
if (!t)
|
|
38
38
|
return;
|
|
39
|
-
|
|
40
|
-
name:
|
|
41
|
-
path:
|
|
39
|
+
c = {
|
|
40
|
+
name: o,
|
|
41
|
+
path: n.path === "/" ? `/${o}` : `${n.path}/${o}`,
|
|
42
42
|
createdAt: Date.now(),
|
|
43
43
|
files: /* @__PURE__ */ new Map(),
|
|
44
44
|
directories: /* @__PURE__ */ new Map()
|
|
45
|
-
},
|
|
45
|
+
}, n.directories.set(o, c), b("create", c.path, "directory");
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
n = c;
|
|
48
48
|
}
|
|
49
|
-
return
|
|
49
|
+
return n;
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function f(e) {
|
|
52
52
|
return new TextEncoder().encode(e);
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function R(e) {
|
|
55
55
|
return new TextDecoder().decode(e);
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function C(e) {
|
|
58
58
|
const t = e.split(".").pop()?.toLowerCase() ?? "";
|
|
59
59
|
return {
|
|
60
60
|
txt: "text/plain",
|
|
@@ -92,482 +92,652 @@ function fe() {
|
|
|
92
92
|
webm: "video/webm"
|
|
93
93
|
}[t] ?? "application/octet-stream";
|
|
94
94
|
}
|
|
95
|
-
function
|
|
95
|
+
function k(e) {
|
|
96
96
|
return new Uint8Array(e);
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
const
|
|
100
|
-
|
|
98
|
+
function W(e) {
|
|
99
|
+
const t = e.lastIndexOf(".");
|
|
100
|
+
return t <= 0 || t === e.length - 1 ? "" : e.slice(t);
|
|
101
|
+
}
|
|
102
|
+
function L(e) {
|
|
103
|
+
return e.startsWith("text/") || e === "application/json" || e === "application/xml" || e === "application/javascript" || e === "application/typescript" || e.endsWith("+xml") || e.endsWith("+json");
|
|
104
|
+
}
|
|
105
|
+
function N(e) {
|
|
106
|
+
const { segments: t } = l(e);
|
|
107
|
+
return t.length;
|
|
108
|
+
}
|
|
109
|
+
function M(e) {
|
|
110
|
+
let t = 0;
|
|
111
|
+
for (const r of e.files.values())
|
|
112
|
+
t += r.size;
|
|
113
|
+
for (const r of e.directories.values())
|
|
114
|
+
t += M(r);
|
|
115
|
+
return t;
|
|
116
|
+
}
|
|
117
|
+
function x(e, t, r = {}) {
|
|
118
|
+
const { parentPath: n, name: o } = y(e), { normalized: c } = l(e);
|
|
119
|
+
if (!o)
|
|
101
120
|
return { success: !1, error: "Invalid file path: no filename specified" };
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
104
|
-
return { success: !1, error: `Failed to create parent directory: ${
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
return { success: !1, error: `File already exists: ${
|
|
108
|
-
const
|
|
109
|
-
name:
|
|
110
|
-
path:
|
|
111
|
-
content:
|
|
112
|
-
size:
|
|
113
|
-
mimeType:
|
|
114
|
-
createdAt:
|
|
115
|
-
modifiedAt:
|
|
121
|
+
const m = d(n, !0);
|
|
122
|
+
if (!m)
|
|
123
|
+
return { success: !1, error: `Failed to create parent directory: ${n}` };
|
|
124
|
+
const w = m.files.get(o);
|
|
125
|
+
if (w && r.overwrite === !1)
|
|
126
|
+
return { success: !1, error: `File already exists: ${c}` };
|
|
127
|
+
const S = typeof t == "string" ? f(t) : k(t), A = Date.now(), te = {
|
|
128
|
+
name: o,
|
|
129
|
+
path: c,
|
|
130
|
+
content: S,
|
|
131
|
+
size: S.length,
|
|
132
|
+
mimeType: r.mimeType ?? C(o),
|
|
133
|
+
createdAt: w?.createdAt ?? A,
|
|
134
|
+
modifiedAt: A
|
|
116
135
|
};
|
|
117
|
-
return
|
|
136
|
+
return m.files.set(o, te), b(w ? "modify" : "create", c, "file"), { success: !0 };
|
|
118
137
|
}
|
|
119
|
-
function
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
return
|
|
123
|
-
const
|
|
124
|
-
return
|
|
138
|
+
function q(e, t) {
|
|
139
|
+
const r = $(e, { encoding: "binary" }), n = typeof t == "string" ? f(t) : t;
|
|
140
|
+
if (r === void 0)
|
|
141
|
+
return x(e, n);
|
|
142
|
+
const o = r, c = new Uint8Array(o.length + n.length);
|
|
143
|
+
return c.set(o, 0), c.set(n, o.length), x(e, c);
|
|
125
144
|
}
|
|
126
|
-
function
|
|
127
|
-
const { parentPath:
|
|
128
|
-
return
|
|
145
|
+
function $(e, t = {}) {
|
|
146
|
+
const { parentPath: r, name: n } = y(e), c = d(r)?.files.get(n);
|
|
147
|
+
return c ? (t.encoding ?? "utf8") === "binary" ? k(c.content) : R(c.content) : void 0;
|
|
129
148
|
}
|
|
130
149
|
function T(e) {
|
|
131
|
-
const { parentPath: t, name:
|
|
132
|
-
if (
|
|
133
|
-
return
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
150
|
+
const { parentPath: t, name: r } = y(e), o = d(t)?.files.get(r);
|
|
151
|
+
if (!o)
|
|
152
|
+
return;
|
|
153
|
+
const c = W(o.name), m = L(o.mimeType);
|
|
154
|
+
return {
|
|
155
|
+
name: o.name,
|
|
156
|
+
path: o.path,
|
|
157
|
+
size: o.size,
|
|
158
|
+
mimeType: o.mimeType,
|
|
159
|
+
createdAt: o.createdAt,
|
|
160
|
+
modifiedAt: o.modifiedAt,
|
|
161
|
+
extension: c,
|
|
162
|
+
isText: m,
|
|
163
|
+
isBinary: !m,
|
|
164
|
+
parentPath: t,
|
|
165
|
+
depth: N(o.path)
|
|
166
|
+
};
|
|
141
167
|
}
|
|
142
|
-
function
|
|
143
|
-
return T(e) !== void 0 ||
|
|
168
|
+
function B(e) {
|
|
169
|
+
return T(e) !== void 0 || z(e);
|
|
144
170
|
}
|
|
145
|
-
function
|
|
171
|
+
function K(e) {
|
|
146
172
|
return T(e) !== void 0;
|
|
147
173
|
}
|
|
148
|
-
function
|
|
149
|
-
return
|
|
174
|
+
function z(e) {
|
|
175
|
+
return d(e) !== void 0;
|
|
150
176
|
}
|
|
151
|
-
function
|
|
152
|
-
const { parentPath: t, name:
|
|
153
|
-
return
|
|
177
|
+
function E(e) {
|
|
178
|
+
const { parentPath: t, name: r } = y(e), { normalized: n } = l(e), o = d(t);
|
|
179
|
+
return o ? o.files.has(r) ? (o.files.delete(r), b("delete", n, "file"), { success: !0 }) : { success: !1, error: `File not found: ${n}` } : { success: !1, error: `Parent directory not found: ${t}` };
|
|
154
180
|
}
|
|
155
|
-
function
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
181
|
+
function H(e, t, r = {}) {
|
|
182
|
+
const n = $(e, { encoding: "binary" });
|
|
183
|
+
if (n === void 0)
|
|
158
184
|
return { success: !1, error: `Source file not found: ${e}` };
|
|
159
|
-
const
|
|
160
|
-
return
|
|
161
|
-
mimeType:
|
|
162
|
-
overwrite:
|
|
185
|
+
const o = T(e);
|
|
186
|
+
return x(t, n, {
|
|
187
|
+
mimeType: o?.mimeType,
|
|
188
|
+
overwrite: r.overwrite
|
|
163
189
|
});
|
|
164
190
|
}
|
|
165
|
-
function
|
|
166
|
-
const
|
|
167
|
-
return
|
|
191
|
+
function J(e, t, r = {}) {
|
|
192
|
+
const n = H(e, t, { overwrite: r.overwrite });
|
|
193
|
+
return n.success ? E(e) : n;
|
|
168
194
|
}
|
|
169
|
-
function
|
|
170
|
-
return
|
|
195
|
+
function Q(e, t) {
|
|
196
|
+
return J(e, t, { overwrite: !1 });
|
|
171
197
|
}
|
|
172
|
-
function
|
|
173
|
-
return
|
|
198
|
+
function G(e) {
|
|
199
|
+
return d(e, !0) ? { success: !0 } : { success: !1, error: `Failed to create directory: ${e}` };
|
|
174
200
|
}
|
|
175
|
-
function
|
|
176
|
-
const { parentPath: t, name:
|
|
177
|
-
if (
|
|
201
|
+
function X(e) {
|
|
202
|
+
const { parentPath: t, name: r } = y(e), { normalized: n } = l(e);
|
|
203
|
+
if (n === "/")
|
|
178
204
|
return { success: !1, error: "Cannot remove root directory" };
|
|
179
|
-
const
|
|
180
|
-
if (!
|
|
205
|
+
const o = d(t);
|
|
206
|
+
if (!o)
|
|
181
207
|
return { success: !1, error: `Parent directory not found: ${t}` };
|
|
182
|
-
const
|
|
183
|
-
return
|
|
208
|
+
const c = o.directories.get(r);
|
|
209
|
+
return c ? c.files.size > 0 || c.directories.size > 0 ? { success: !1, error: `Directory not empty: ${n}` } : (o.directories.delete(r), b("delete", n, "directory"), { success: !0 }) : { success: !1, error: `Directory not found: ${n}` };
|
|
184
210
|
}
|
|
185
|
-
function
|
|
186
|
-
const { parentPath: t, name:
|
|
187
|
-
if (
|
|
211
|
+
function Z(e) {
|
|
212
|
+
const { parentPath: t, name: r } = y(e), { normalized: n } = l(e);
|
|
213
|
+
if (n === "/")
|
|
188
214
|
return { success: !1, error: "Cannot remove root directory" };
|
|
189
|
-
const
|
|
190
|
-
return
|
|
215
|
+
const o = d(t);
|
|
216
|
+
return o ? o.directories.get(r) ? (o.directories.delete(r), b("delete", n, "directory"), { success: !0 }) : { success: !1, error: `Directory not found: ${n}` } : { success: !1, error: `Parent directory not found: ${t}` };
|
|
191
217
|
}
|
|
192
|
-
function
|
|
193
|
-
const { recursive:
|
|
194
|
-
if (!
|
|
218
|
+
function j(e, t = {}) {
|
|
219
|
+
const { recursive: r = !1, filesOnly: n = !1, directoriesOnly: o = !1 } = t, c = e === "/" || e === "" ? h : d(e);
|
|
220
|
+
if (!c)
|
|
195
221
|
return [];
|
|
196
|
-
const
|
|
197
|
-
if (!
|
|
198
|
-
for (const
|
|
199
|
-
|
|
200
|
-
name:
|
|
201
|
-
path:
|
|
222
|
+
const m = [];
|
|
223
|
+
if (!o)
|
|
224
|
+
for (const w of c.files.values())
|
|
225
|
+
m.push({
|
|
226
|
+
name: w.name,
|
|
227
|
+
path: w.path,
|
|
202
228
|
type: "file",
|
|
203
|
-
size:
|
|
229
|
+
size: w.size
|
|
204
230
|
});
|
|
205
|
-
if (!
|
|
206
|
-
for (const
|
|
207
|
-
if (
|
|
208
|
-
name:
|
|
209
|
-
path:
|
|
231
|
+
if (!n) {
|
|
232
|
+
for (const w of c.directories.values())
|
|
233
|
+
if (m.push({
|
|
234
|
+
name: w.name,
|
|
235
|
+
path: w.path,
|
|
210
236
|
type: "directory"
|
|
211
|
-
}),
|
|
212
|
-
const
|
|
213
|
-
|
|
237
|
+
}), r) {
|
|
238
|
+
const S = j(w.path, t);
|
|
239
|
+
m.push(...S);
|
|
214
240
|
}
|
|
215
241
|
}
|
|
216
|
-
return
|
|
242
|
+
return m;
|
|
217
243
|
}
|
|
218
|
-
function
|
|
219
|
-
const t =
|
|
220
|
-
if (
|
|
221
|
-
return
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
244
|
+
function I(e) {
|
|
245
|
+
const { normalized: t } = l(e), r = t === "/" ? h : d(e);
|
|
246
|
+
if (!r)
|
|
247
|
+
return;
|
|
248
|
+
const { parentPath: n } = y(t);
|
|
249
|
+
return {
|
|
250
|
+
name: r.name || "/",
|
|
251
|
+
path: r.path,
|
|
252
|
+
createdAt: r.createdAt,
|
|
253
|
+
parentPath: t === "/" ? "/" : n,
|
|
254
|
+
depth: N(r.path),
|
|
255
|
+
fileCount: r.files.size,
|
|
256
|
+
directoryCount: r.directories.size,
|
|
257
|
+
totalSize: M(r)
|
|
258
|
+
};
|
|
226
259
|
}
|
|
227
|
-
function
|
|
260
|
+
function D() {
|
|
228
261
|
const e = [];
|
|
229
|
-
function t(
|
|
230
|
-
for (const
|
|
231
|
-
e.push(
|
|
232
|
-
for (const
|
|
233
|
-
t(
|
|
262
|
+
function t(r) {
|
|
263
|
+
for (const n of r.files.values())
|
|
264
|
+
e.push(n);
|
|
265
|
+
for (const n of r.directories.values())
|
|
266
|
+
t(n);
|
|
234
267
|
}
|
|
235
|
-
return t(
|
|
236
|
-
}
|
|
237
|
-
function
|
|
238
|
-
return
|
|
239
|
-
}
|
|
240
|
-
function
|
|
241
|
-
let e = 0, t = 0,
|
|
242
|
-
function
|
|
243
|
-
for (const
|
|
244
|
-
e++,
|
|
245
|
-
for (const
|
|
246
|
-
t++,
|
|
268
|
+
return t(h), e;
|
|
269
|
+
}
|
|
270
|
+
function P() {
|
|
271
|
+
return D().map((e) => e.path);
|
|
272
|
+
}
|
|
273
|
+
function V() {
|
|
274
|
+
let e = 0, t = 0, r = 0;
|
|
275
|
+
function n(o) {
|
|
276
|
+
for (const c of o.files.values())
|
|
277
|
+
e++, r += c.size;
|
|
278
|
+
for (const c of o.directories.values())
|
|
279
|
+
t++, n(c);
|
|
247
280
|
}
|
|
248
|
-
return
|
|
281
|
+
return n(h), { totalFiles: e, totalDirectories: t, totalSize: r };
|
|
249
282
|
}
|
|
250
|
-
function
|
|
251
|
-
|
|
283
|
+
function _() {
|
|
284
|
+
h.files.clear(), h.directories.clear(), b("delete", "/", "directory");
|
|
252
285
|
}
|
|
253
|
-
function
|
|
254
|
-
const t =
|
|
255
|
-
return t.filter((
|
|
286
|
+
function Y(e) {
|
|
287
|
+
const t = P(), r = e.replace(/\./g, "\\.").replace(/\*\*/g, "<<<GLOBSTAR>>>").replace(/\*/g, "[^/]*").replace(/<<<GLOBSTAR>>>/g, ".*"), n = new RegExp(`^${r}$`);
|
|
288
|
+
return t.filter((o) => n.test(o));
|
|
256
289
|
}
|
|
257
|
-
function
|
|
290
|
+
function ee(e) {
|
|
258
291
|
const t = e.startsWith(".") ? e : `.${e}`;
|
|
259
|
-
return
|
|
292
|
+
return P().filter((r) => r.endsWith(t));
|
|
260
293
|
}
|
|
261
|
-
function
|
|
262
|
-
|
|
263
|
-
|
|
294
|
+
function i(e, t) {
|
|
295
|
+
if (!t) {
|
|
296
|
+
const v = e;
|
|
297
|
+
return p.add(v), () => {
|
|
298
|
+
p.delete(v);
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
const {
|
|
302
|
+
pattern: r,
|
|
303
|
+
events: n,
|
|
304
|
+
type: o = "all",
|
|
305
|
+
debounce: c,
|
|
306
|
+
path: m,
|
|
307
|
+
recursive: w = !1
|
|
308
|
+
} = t;
|
|
309
|
+
let S, A = [];
|
|
310
|
+
function te(v, g) {
|
|
311
|
+
const O = g.replace(/\./g, "\\.").replace(/\*\*/g, "<<<GLOBSTAR>>>").replace(/\*/g, "[^/]*").replace(/<<<GLOBSTAR>>>/g, ".*");
|
|
312
|
+
return new RegExp(`^${O}$`).test(v);
|
|
313
|
+
}
|
|
314
|
+
function oe(v, g, O) {
|
|
315
|
+
if (n && !n.includes(v) || o !== "all" && o !== O || r && !te(g, r))
|
|
316
|
+
return !1;
|
|
317
|
+
if (m) {
|
|
318
|
+
const F = m.endsWith("/") ? m.slice(0, -1) : m;
|
|
319
|
+
if (w) {
|
|
320
|
+
if (!g.startsWith(F + "/") && g !== F)
|
|
321
|
+
return !1;
|
|
322
|
+
} else if ((g.substring(0, g.lastIndexOf("/")) || "/") !== F)
|
|
323
|
+
return !1;
|
|
324
|
+
}
|
|
325
|
+
return !0;
|
|
326
|
+
}
|
|
327
|
+
function ie() {
|
|
328
|
+
const v = e;
|
|
329
|
+
for (const g of A)
|
|
330
|
+
v(g);
|
|
331
|
+
A = [];
|
|
332
|
+
}
|
|
333
|
+
const ne = (v, g, O) => {
|
|
334
|
+
if (!oe(v, g, O))
|
|
335
|
+
return;
|
|
336
|
+
let F;
|
|
337
|
+
v !== "delete" && (O === "file" ? F = T(g) : F = I(g));
|
|
338
|
+
const re = {
|
|
339
|
+
event: v,
|
|
340
|
+
path: g,
|
|
341
|
+
type: O,
|
|
342
|
+
timestamp: Date.now(),
|
|
343
|
+
metadata: F
|
|
344
|
+
};
|
|
345
|
+
c !== void 0 && c > 0 ? (A.push(re), S && clearTimeout(S), S = setTimeout(ie, c)) : e(re);
|
|
346
|
+
};
|
|
347
|
+
return p.add(ne), () => {
|
|
348
|
+
p.delete(ne), S && clearTimeout(S), A = [];
|
|
264
349
|
};
|
|
265
350
|
}
|
|
266
|
-
function
|
|
351
|
+
function s() {
|
|
267
352
|
const e = {};
|
|
268
|
-
for (const t of
|
|
269
|
-
const
|
|
270
|
-
Array.from(t.content, (
|
|
353
|
+
for (const t of D()) {
|
|
354
|
+
const r = btoa(
|
|
355
|
+
Array.from(t.content, (n) => String.fromCharCode(n)).join("")
|
|
271
356
|
);
|
|
272
357
|
e[t.path] = {
|
|
273
|
-
content:
|
|
358
|
+
content: r,
|
|
274
359
|
mimeType: t.mimeType
|
|
275
360
|
};
|
|
276
361
|
}
|
|
277
362
|
return e;
|
|
278
363
|
}
|
|
279
|
-
function
|
|
280
|
-
|
|
281
|
-
for (const [t, { content:
|
|
282
|
-
const
|
|
283
|
-
|
|
364
|
+
function a(e) {
|
|
365
|
+
_();
|
|
366
|
+
for (const [t, { content: r, mimeType: n }] of Object.entries(e)) {
|
|
367
|
+
const o = atob(r), c = Uint8Array.from(o, (m) => m.charCodeAt(0));
|
|
368
|
+
x(t, c, { mimeType: n });
|
|
284
369
|
}
|
|
285
370
|
}
|
|
286
371
|
return {
|
|
287
372
|
// File operations
|
|
288
|
-
writeFile:
|
|
289
|
-
appendFile:
|
|
290
|
-
readFile:
|
|
373
|
+
writeFile: x,
|
|
374
|
+
appendFile: q,
|
|
375
|
+
readFile: $,
|
|
291
376
|
stat: T,
|
|
292
|
-
exists:
|
|
293
|
-
isFile:
|
|
294
|
-
isDirectory:
|
|
295
|
-
remove:
|
|
296
|
-
copy:
|
|
297
|
-
move:
|
|
298
|
-
rename:
|
|
377
|
+
exists: B,
|
|
378
|
+
isFile: K,
|
|
379
|
+
isDirectory: z,
|
|
380
|
+
remove: E,
|
|
381
|
+
copy: H,
|
|
382
|
+
move: J,
|
|
383
|
+
rename: Q,
|
|
299
384
|
// Directory operations
|
|
300
|
-
mkdir:
|
|
301
|
-
rmdir:
|
|
302
|
-
rmdirRecursive:
|
|
303
|
-
list:
|
|
304
|
-
statDirectory:
|
|
385
|
+
mkdir: G,
|
|
386
|
+
rmdir: X,
|
|
387
|
+
rmdirRecursive: Z,
|
|
388
|
+
list: j,
|
|
389
|
+
statDirectory: I,
|
|
305
390
|
// Bulk operations
|
|
306
|
-
getAllFiles:
|
|
307
|
-
getAllPaths:
|
|
308
|
-
getStats:
|
|
309
|
-
clear:
|
|
391
|
+
getAllFiles: D,
|
|
392
|
+
getAllPaths: P,
|
|
393
|
+
getStats: V,
|
|
394
|
+
clear: _,
|
|
310
395
|
// Search
|
|
311
|
-
find:
|
|
312
|
-
findByExtension:
|
|
396
|
+
find: Y,
|
|
397
|
+
findByExtension: ee,
|
|
313
398
|
// Watchers
|
|
314
|
-
watch:
|
|
399
|
+
watch: i,
|
|
315
400
|
// Serialization
|
|
316
|
-
toJSON:
|
|
317
|
-
fromJSON:
|
|
401
|
+
toJSON: s,
|
|
402
|
+
fromJSON: a
|
|
318
403
|
};
|
|
319
404
|
}
|
|
320
|
-
function
|
|
321
|
-
const {
|
|
322
|
-
|
|
323
|
-
|
|
405
|
+
function ue(h = {}) {
|
|
406
|
+
const {
|
|
407
|
+
adapter: p,
|
|
408
|
+
autoPersist: b = !1,
|
|
409
|
+
maxSize: u,
|
|
410
|
+
maxFiles: l,
|
|
411
|
+
maxFileSize: y,
|
|
412
|
+
warnAtPercentage: d = 90
|
|
413
|
+
} = h, f = ce(), R = se(0), C = /* @__PURE__ */ new Set();
|
|
414
|
+
function k() {
|
|
415
|
+
R.value++, b && p && $();
|
|
416
|
+
const i = W();
|
|
417
|
+
if (i.percentage >= d)
|
|
418
|
+
for (const s of C)
|
|
419
|
+
s(i);
|
|
420
|
+
}
|
|
421
|
+
function W() {
|
|
422
|
+
const s = f.getStats().totalSize, a = u ?? Number.MAX_SAFE_INTEGER, e = Math.max(0, a - s), t = u ? s / u * 100 : 0;
|
|
423
|
+
return {
|
|
424
|
+
quota: a,
|
|
425
|
+
usage: s,
|
|
426
|
+
available: e,
|
|
427
|
+
percentage: Math.min(100, t)
|
|
428
|
+
};
|
|
324
429
|
}
|
|
325
|
-
|
|
326
|
-
|
|
430
|
+
f.watch(() => {
|
|
431
|
+
k();
|
|
327
432
|
});
|
|
328
|
-
const
|
|
329
|
-
async function
|
|
330
|
-
if (!
|
|
433
|
+
const L = U(() => (R.value, f.getStats())), N = U(() => L.value.totalFiles), M = U(() => L.value.totalSize), x = U(() => (R.value, W())), q = U(() => x.value.percentage >= d);
|
|
434
|
+
async function $() {
|
|
435
|
+
if (!p)
|
|
331
436
|
throw new Error("No storage adapter configured");
|
|
332
|
-
const
|
|
333
|
-
await
|
|
437
|
+
const i = f.toJSON(), s = new TextEncoder().encode(JSON.stringify(i));
|
|
438
|
+
await p.save("filesystem", s);
|
|
334
439
|
}
|
|
335
|
-
async function
|
|
336
|
-
if (!
|
|
440
|
+
async function T() {
|
|
441
|
+
if (!p)
|
|
337
442
|
throw new Error("No storage adapter configured");
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
340
|
-
const
|
|
341
|
-
|
|
443
|
+
const i = await p.load("filesystem");
|
|
444
|
+
if (i) {
|
|
445
|
+
const s = JSON.parse(new TextDecoder().decode(i));
|
|
446
|
+
f.fromJSON(s), k();
|
|
342
447
|
}
|
|
343
448
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
let c = s;
|
|
357
|
-
for (let l = 0; l < 8; l++)
|
|
358
|
-
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
359
|
-
o[s] = c;
|
|
360
|
-
}
|
|
361
|
-
return o;
|
|
362
|
-
})();
|
|
363
|
-
function K(n) {
|
|
364
|
-
let o = 4294967295;
|
|
365
|
-
for (let s = 0; s < n.length; s++) {
|
|
366
|
-
const c = n[s] ?? 0, l = (o ^ c) & 255;
|
|
367
|
-
o = o >>> 8 ^ (de[l] ?? 0);
|
|
368
|
-
}
|
|
369
|
-
return ~o >>> 0;
|
|
370
|
-
}
|
|
371
|
-
function j(n) {
|
|
372
|
-
const o = new ArrayBuffer(n.byteLength);
|
|
373
|
-
return new Uint8Array(o).set(n), o;
|
|
374
|
-
}
|
|
375
|
-
function V(n) {
|
|
376
|
-
return new TextEncoder().encode(n);
|
|
377
|
-
}
|
|
378
|
-
function Q(n) {
|
|
379
|
-
return new TextDecoder().decode(n);
|
|
380
|
-
}
|
|
381
|
-
async function X(n) {
|
|
382
|
-
const s = new Blob([j(n)]).stream().pipeThrough(new CompressionStream("deflate-raw")), c = await new Response(s).blob();
|
|
383
|
-
return new Uint8Array(await c.arrayBuffer());
|
|
384
|
-
}
|
|
385
|
-
async function ee(n) {
|
|
386
|
-
const s = new Blob([j(n)]).stream().pipeThrough(new DecompressionStream("deflate-raw")), c = await new Response(s).blob();
|
|
387
|
-
return new Uint8Array(await c.arrayBuffer());
|
|
388
|
-
}
|
|
389
|
-
function me(n) {
|
|
390
|
-
const o = n.getHours(), s = n.getMinutes(), c = Math.floor(n.getSeconds() / 2), l = o << 11 | s << 5 | c, f = n.getFullYear() - 1980, u = n.getMonth() + 1, w = n.getDate(), A = f << 9 | u << 5 | w;
|
|
391
|
-
return { time: l, date: A };
|
|
392
|
-
}
|
|
393
|
-
function Z(n, o) {
|
|
394
|
-
const s = (n & 31) * 2, c = n >> 5 & 63, l = n >> 11 & 31, f = o & 31, u = (o >> 5 & 15) - 1, w = (o >> 9 & 127) + 1980;
|
|
395
|
-
return new Date(w, u, f, l, c, s);
|
|
396
|
-
}
|
|
397
|
-
async function J(n, o = {}) {
|
|
398
|
-
const { level: s = "default", comment: c = "" } = o, l = s !== "none", f = [], u = [];
|
|
399
|
-
let w = 0;
|
|
400
|
-
const h = me(/* @__PURE__ */ new Date());
|
|
401
|
-
for (const U of n) {
|
|
402
|
-
const v = V(U.path), b = typeof U.content == "string" ? V(U.content) : U.content, O = K(b), z = b.length, B = l ? await X(b) : b, C = B.length, R = l ? M : le, L = new ArrayBuffer(30), D = new DataView(L);
|
|
403
|
-
D.setUint32(0, Y, !0), D.setUint16(4, 20, !0), D.setUint16(6, 0, !0), D.setUint16(8, R, !0), D.setUint16(10, h.time, !0), D.setUint16(12, h.date, !0), D.setUint32(14, O, !0), D.setUint32(18, C, !0), D.setUint32(22, z, !0), D.setUint16(26, v.length, !0), D.setUint16(28, 0, !0), f.push(new Uint8Array(L), v, B);
|
|
404
|
-
const F = new ArrayBuffer(46), g = new DataView(F);
|
|
405
|
-
g.setUint32(0, G, !0), g.setUint16(4, 20, !0), g.setUint16(6, 20, !0), g.setUint16(8, 0, !0), g.setUint16(10, R, !0), g.setUint16(12, h.time, !0), g.setUint16(14, h.date, !0), g.setUint32(16, O, !0), g.setUint32(20, C, !0), g.setUint32(24, z, !0), g.setUint16(28, v.length, !0), g.setUint16(30, 0, !0), g.setUint16(32, 0, !0), g.setUint16(34, 0, !0), g.setUint16(36, 0, !0), g.setUint32(38, 0, !0), g.setUint32(42, w, !0);
|
|
406
|
-
const P = new Uint8Array(46 + v.length);
|
|
407
|
-
P.set(new Uint8Array(F), 0), P.set(v, 46), u.push(P), w += 30 + v.length + C;
|
|
408
|
-
}
|
|
409
|
-
const x = u.reduce((U, v) => U + v.length, 0), p = V(c), m = new ArrayBuffer(22), y = new DataView(m);
|
|
410
|
-
y.setUint32(0, q, !0), y.setUint16(4, 0, !0), y.setUint16(6, 0, !0), y.setUint16(8, n.length, !0), y.setUint16(10, n.length, !0), y.setUint32(12, x, !0), y.setUint32(16, w, !0), y.setUint16(20, p.length, !0);
|
|
411
|
-
const T = [
|
|
412
|
-
...f.map((U) => j(U)),
|
|
413
|
-
...u.map((U) => j(U)),
|
|
414
|
-
m,
|
|
415
|
-
j(p)
|
|
416
|
-
];
|
|
417
|
-
return new Blob(T, { type: "application/zip" });
|
|
418
|
-
}
|
|
419
|
-
async function pe(n) {
|
|
420
|
-
const o = n instanceof Blob ? new Uint8Array(await n.arrayBuffer()) : n, s = [], c = ge(o);
|
|
421
|
-
if (!c)
|
|
422
|
-
throw new Error("Invalid ZIP file: end of central directory not found");
|
|
423
|
-
const l = new DataView(o.buffer, o.byteOffset, o.byteLength);
|
|
424
|
-
let f = c.centralDirectoryOffset;
|
|
425
|
-
for (let u = 0; u < c.entryCount; u++) {
|
|
426
|
-
if (l.getUint32(f, !0) !== G)
|
|
427
|
-
throw new Error("Invalid ZIP file: invalid central directory entry");
|
|
428
|
-
const A = l.getUint16(f + 10, !0), h = l.getUint16(f + 12, !0), x = l.getUint16(f + 14, !0), p = l.getUint32(f + 20, !0), m = l.getUint32(f + 24, !0), y = l.getUint16(f + 28, !0), T = l.getUint16(f + 30, !0), U = l.getUint16(f + 32, !0), v = o.slice(f + 46, f + 46 + y), b = Q(v);
|
|
429
|
-
s.push({
|
|
430
|
-
path: b,
|
|
431
|
-
compressedSize: p,
|
|
432
|
-
uncompressedSize: m,
|
|
433
|
-
compressionMethod: A === M ? "deflate" : "store",
|
|
434
|
-
isDirectory: b.endsWith("/"),
|
|
435
|
-
modifiedAt: Z(h, x)
|
|
436
|
-
}), f += 46 + y + T + U;
|
|
437
|
-
}
|
|
438
|
-
return s;
|
|
439
|
-
}
|
|
440
|
-
async function te(n, o = {}) {
|
|
441
|
-
const { filter: s } = o, c = n instanceof Blob ? new Uint8Array(await n.arrayBuffer()) : n, l = [], f = new DataView(c.buffer, c.byteOffset, c.byteLength);
|
|
442
|
-
let u = 0;
|
|
443
|
-
for (; u < c.length - 4; ) {
|
|
444
|
-
const w = f.getUint32(u, !0);
|
|
445
|
-
if (w === Y) {
|
|
446
|
-
const A = f.getUint16(u + 8, !0), h = f.getUint16(u + 10, !0), x = f.getUint16(u + 12, !0), p = f.getUint32(u + 14, !0), m = f.getUint32(u + 18, !0), y = f.getUint32(u + 22, !0), T = f.getUint16(u + 26, !0), U = f.getUint16(u + 28, !0), v = c.slice(u + 30, u + 30 + T), b = Q(v), O = u + 30 + T + U, z = c.slice(O, O + m), B = b.endsWith("/"), C = A === M ? "deflate" : "store";
|
|
447
|
-
if (s) {
|
|
448
|
-
const L = {
|
|
449
|
-
path: b,
|
|
450
|
-
compressedSize: m,
|
|
451
|
-
uncompressedSize: y,
|
|
452
|
-
compressionMethod: C,
|
|
453
|
-
isDirectory: B,
|
|
454
|
-
modifiedAt: Z(h, x)
|
|
455
|
-
};
|
|
456
|
-
if (!s(L)) {
|
|
457
|
-
u = O + m;
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
let R;
|
|
462
|
-
B ? R = new Uint8Array(0) : A === M ? R = await ee(z) : R = new Uint8Array(z), l.push({
|
|
463
|
-
path: b,
|
|
464
|
-
content: R,
|
|
465
|
-
compressedSize: m,
|
|
466
|
-
uncompressedSize: y,
|
|
467
|
-
compressionMethod: C,
|
|
468
|
-
crc32: p,
|
|
469
|
-
modifiedAt: Z(h, x),
|
|
470
|
-
isDirectory: B
|
|
471
|
-
}), u = O + m;
|
|
472
|
-
} else {
|
|
473
|
-
if (w === G)
|
|
474
|
-
break;
|
|
475
|
-
u++;
|
|
449
|
+
async function B(i, s) {
|
|
450
|
+
const a = s ?? `/${i.name}`;
|
|
451
|
+
try {
|
|
452
|
+
const e = await i.arrayBuffer(), t = new Uint8Array(e);
|
|
453
|
+
return f.writeFile(a, t, {
|
|
454
|
+
mimeType: i.type || void 0
|
|
455
|
+
});
|
|
456
|
+
} catch (e) {
|
|
457
|
+
return {
|
|
458
|
+
success: !1,
|
|
459
|
+
error: e instanceof Error ? e.message : "Failed to import file"
|
|
460
|
+
};
|
|
476
461
|
}
|
|
477
462
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
463
|
+
async function K(i, s = "/") {
|
|
464
|
+
const e = (s.endsWith("/") ? s.slice(0, -1) : s) || "";
|
|
465
|
+
for (const t of Array.from(i)) {
|
|
466
|
+
const r = e === "" ? `/${t.name}` : `${e}/${t.name}`, n = await B(t, r);
|
|
467
|
+
if (!n.success)
|
|
468
|
+
return n;
|
|
469
|
+
}
|
|
470
|
+
return { success: !0 };
|
|
471
|
+
}
|
|
472
|
+
function z(i) {
|
|
473
|
+
return i.byteOffset === 0 && i.byteLength === i.buffer.byteLength ? i.buffer : i.buffer.slice(i.byteOffset, i.byteOffset + i.byteLength);
|
|
474
|
+
}
|
|
475
|
+
function E(i) {
|
|
476
|
+
const s = f.readFile(i, { encoding: "binary" });
|
|
477
|
+
if (s === void 0) return;
|
|
478
|
+
const a = f.stat(i);
|
|
479
|
+
return new Blob([z(s)], { type: a?.mimeType });
|
|
480
|
+
}
|
|
481
|
+
function H(i) {
|
|
482
|
+
const s = f.readFile(i, { encoding: "binary" });
|
|
483
|
+
if (s === void 0) return;
|
|
484
|
+
const a = f.stat(i);
|
|
485
|
+
if (a)
|
|
486
|
+
return new File([z(s)], a.name, {
|
|
487
|
+
type: a.mimeType,
|
|
488
|
+
lastModified: a.modifiedAt
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
function J(i) {
|
|
492
|
+
const s = E(i);
|
|
493
|
+
if (s)
|
|
494
|
+
return URL.createObjectURL(s);
|
|
495
|
+
}
|
|
496
|
+
function Q(i) {
|
|
497
|
+
URL.revokeObjectURL(i);
|
|
498
|
+
}
|
|
499
|
+
function G(i, s) {
|
|
500
|
+
const a = E(i);
|
|
501
|
+
if (!a) return !1;
|
|
502
|
+
const e = f.stat(i), t = s ?? e?.name ?? "download", r = URL.createObjectURL(a), n = document.createElement("a");
|
|
503
|
+
return n.href = r, n.download = t, n.style.display = "none", document.body.appendChild(n), n.click(), document.body.removeChild(n), setTimeout(() => URL.revokeObjectURL(r), 1e3), !0;
|
|
504
|
+
}
|
|
505
|
+
function X(i) {
|
|
506
|
+
i.forEach((s, a) => {
|
|
507
|
+
setTimeout(() => G(s), a * 100);
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
const Z = 64 * 1024, j = 3;
|
|
511
|
+
function I(i, s = {}) {
|
|
512
|
+
const a = f.readFile(i, { encoding: "binary" });
|
|
513
|
+
if (a === void 0) return;
|
|
514
|
+
const e = s.chunkSize ?? Z, t = s.highWaterMark ?? j;
|
|
515
|
+
let r = 0;
|
|
516
|
+
return new ReadableStream(
|
|
517
|
+
{
|
|
518
|
+
pull(n) {
|
|
519
|
+
if (r >= a.length) {
|
|
520
|
+
n.close();
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const o = a.slice(r, r + e);
|
|
524
|
+
n.enqueue(o), r += e;
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
new CountQueuingStrategy({ highWaterMark: t })
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
function D(i, s = {}) {
|
|
531
|
+
const a = [], e = s.highWaterMark ?? j;
|
|
532
|
+
return new WritableStream(
|
|
533
|
+
{
|
|
534
|
+
write(t) {
|
|
535
|
+
a.push(t);
|
|
536
|
+
},
|
|
537
|
+
close() {
|
|
538
|
+
const t = a.reduce((o, c) => o + c.length, 0), r = new Uint8Array(t);
|
|
539
|
+
let n = 0;
|
|
540
|
+
for (const o of a)
|
|
541
|
+
r.set(o, n), n += o.length;
|
|
542
|
+
f.writeFile(i, r, {
|
|
543
|
+
mimeType: s.mimeType,
|
|
544
|
+
overwrite: s.overwrite
|
|
545
|
+
});
|
|
546
|
+
},
|
|
547
|
+
abort() {
|
|
548
|
+
a.length = 0;
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
new CountQueuingStrategy({ highWaterMark: e })
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
async function P(i, s, a = {}) {
|
|
555
|
+
const e = [], t = new WritableStream({
|
|
556
|
+
write(r) {
|
|
557
|
+
e.push(r);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
try {
|
|
561
|
+
await s.pipeTo(t);
|
|
562
|
+
const r = e.reduce((c, m) => c + m.length, 0), n = new Uint8Array(r);
|
|
563
|
+
let o = 0;
|
|
564
|
+
for (const c of e)
|
|
565
|
+
n.set(c, o), o += c.length;
|
|
566
|
+
return f.writeFile(i, n, a);
|
|
567
|
+
} catch (r) {
|
|
490
568
|
return {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
centralDirectoryOffset: o.getUint32(s + 16, !0)
|
|
569
|
+
success: !1,
|
|
570
|
+
error: r instanceof Error ? r.message : "Stream read failed"
|
|
494
571
|
};
|
|
495
|
-
}
|
|
496
|
-
function k(n, o) {
|
|
497
|
-
const s = URL.createObjectURL(n), c = document.createElement("a");
|
|
498
|
-
c.href = s, c.download = o, document.body.appendChild(c), c.click(), document.body.removeChild(c), URL.revokeObjectURL(s);
|
|
499
|
-
}
|
|
500
|
-
async function Ue(n, o, s = {}) {
|
|
501
|
-
const c = await J(n, s);
|
|
502
|
-
k(c, o);
|
|
503
|
-
}
|
|
504
|
-
function ve() {
|
|
505
|
-
const n = _(!1), o = _(0), s = _(void 0), c = N(() => ({
|
|
506
|
-
isProcessing: n.value,
|
|
507
|
-
progress: o.value,
|
|
508
|
-
error: s.value
|
|
509
|
-
}));
|
|
510
|
-
async function l(p) {
|
|
511
|
-
n.value = !0, o.value = 0, s.value = void 0;
|
|
512
|
-
try {
|
|
513
|
-
const m = await p();
|
|
514
|
-
return o.value = 100, m;
|
|
515
|
-
} catch (m) {
|
|
516
|
-
const y = m instanceof Error ? m.message : "Unknown error";
|
|
517
|
-
throw s.value = y, m;
|
|
518
|
-
} finally {
|
|
519
|
-
n.value = !1;
|
|
520
572
|
}
|
|
521
573
|
}
|
|
522
|
-
|
|
523
|
-
|
|
574
|
+
function V(i, s = {}) {
|
|
575
|
+
const a = f.readFile(i, { encoding: "binary" });
|
|
576
|
+
if (a === void 0) return;
|
|
577
|
+
const e = f.stat(i), t = new Headers(s.headers);
|
|
578
|
+
return e?.mimeType && !t.has("Content-Type") && t.set("Content-Type", e.mimeType), t.set("Content-Length", String(a.length)), new Response(z(a), {
|
|
579
|
+
...s,
|
|
580
|
+
headers: t
|
|
581
|
+
});
|
|
524
582
|
}
|
|
525
|
-
async function
|
|
526
|
-
|
|
583
|
+
async function _(i) {
|
|
584
|
+
const s = f.readFile(i, { encoding: "binary" });
|
|
585
|
+
if (s === void 0) return;
|
|
586
|
+
const a = await crypto.subtle.digest("SHA-256", z(s));
|
|
587
|
+
return Array.from(new Uint8Array(a)).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
527
588
|
}
|
|
528
|
-
|
|
529
|
-
return
|
|
589
|
+
function Y(i) {
|
|
590
|
+
return C.add(i), () => {
|
|
591
|
+
C.delete(i);
|
|
592
|
+
};
|
|
530
593
|
}
|
|
531
|
-
|
|
532
|
-
|
|
594
|
+
function ee() {
|
|
595
|
+
const i = [];
|
|
596
|
+
let s = !1, a = !1;
|
|
597
|
+
const e = {
|
|
598
|
+
writeFile(t, r, n) {
|
|
599
|
+
return s || a || i.push({ type: "writeFile", path: t, content: r, options: n }), e;
|
|
600
|
+
},
|
|
601
|
+
remove(t) {
|
|
602
|
+
return s || a || i.push({ type: "remove", path: t }), e;
|
|
603
|
+
},
|
|
604
|
+
mkdir(t) {
|
|
605
|
+
return s || a || i.push({ type: "mkdir", path: t }), e;
|
|
606
|
+
},
|
|
607
|
+
copy(t, r) {
|
|
608
|
+
return s || a || i.push({ type: "copy", source: t, destination: r }), e;
|
|
609
|
+
},
|
|
610
|
+
move(t, r) {
|
|
611
|
+
return s || a || i.push({ type: "move", source: t, destination: r }), e;
|
|
612
|
+
},
|
|
613
|
+
commit() {
|
|
614
|
+
if (s)
|
|
615
|
+
return { success: !1, error: "Transaction already committed" };
|
|
616
|
+
if (a)
|
|
617
|
+
return { success: !1, error: "Transaction was rolled back" };
|
|
618
|
+
const t = f.toJSON();
|
|
619
|
+
for (const r of i) {
|
|
620
|
+
let n;
|
|
621
|
+
switch (r.type) {
|
|
622
|
+
case "writeFile":
|
|
623
|
+
if (y !== void 0) {
|
|
624
|
+
const o = typeof r.content == "string" ? new TextEncoder().encode(r.content).length : r.content.length;
|
|
625
|
+
if (o > y)
|
|
626
|
+
return f.fromJSON(t), { success: !1, error: `File size ${o} exceeds maximum ${y}` };
|
|
627
|
+
}
|
|
628
|
+
if (l !== void 0) {
|
|
629
|
+
const o = f.getStats().totalFiles;
|
|
630
|
+
if ((!f.exists(r.path) || !f.isFile(r.path)) && o >= l)
|
|
631
|
+
return f.fromJSON(t), { success: !1, error: `Maximum file count ${l} reached` };
|
|
632
|
+
}
|
|
633
|
+
n = f.writeFile(r.path, r.content, r.options);
|
|
634
|
+
break;
|
|
635
|
+
case "remove":
|
|
636
|
+
n = f.remove(r.path);
|
|
637
|
+
break;
|
|
638
|
+
case "mkdir":
|
|
639
|
+
n = f.mkdir(r.path);
|
|
640
|
+
break;
|
|
641
|
+
case "copy":
|
|
642
|
+
n = f.copy(r.source, r.destination);
|
|
643
|
+
break;
|
|
644
|
+
case "move":
|
|
645
|
+
n = f.move(r.source, r.destination);
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
if (!n.success)
|
|
649
|
+
return f.fromJSON(t), { success: !1, error: `Transaction failed at ${r.type}: ${n.error}` };
|
|
650
|
+
if (u !== void 0) {
|
|
651
|
+
const o = f.getStats().totalSize;
|
|
652
|
+
if (o > u)
|
|
653
|
+
return f.fromJSON(t), { success: !1, error: `Total size ${o} exceeds maximum ${u}` };
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return s = !0, k(), { success: !0 };
|
|
657
|
+
},
|
|
658
|
+
rollback() {
|
|
659
|
+
!s && !a && (a = !0, i.length = 0);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
return e;
|
|
533
663
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
664
|
+
return {
|
|
665
|
+
...f,
|
|
666
|
+
stats: L,
|
|
667
|
+
fileCount: N,
|
|
668
|
+
totalSize: M,
|
|
669
|
+
persist: $,
|
|
670
|
+
restore: T,
|
|
671
|
+
// Upload methods
|
|
672
|
+
upload: B,
|
|
673
|
+
uploads: K,
|
|
674
|
+
// Export/conversion methods
|
|
675
|
+
toBlob: E,
|
|
676
|
+
toFile: H,
|
|
677
|
+
createObjectURL: J,
|
|
678
|
+
revokeObjectURL: Q,
|
|
679
|
+
// Download methods
|
|
680
|
+
download: G,
|
|
681
|
+
downloads: X,
|
|
682
|
+
// Web Streams API methods
|
|
683
|
+
createReadStream: I,
|
|
684
|
+
createWriteStream: D,
|
|
685
|
+
writeFromStream: P,
|
|
686
|
+
toResponse: V,
|
|
687
|
+
// Utility methods
|
|
688
|
+
computeChecksum: _,
|
|
689
|
+
// Storage quota management
|
|
690
|
+
storageEstimate: x,
|
|
691
|
+
isNearCapacity: q,
|
|
692
|
+
onStorageWarning: Y,
|
|
693
|
+
// Transactions
|
|
694
|
+
beginTransaction: ee
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function le() {
|
|
698
|
+
let h;
|
|
699
|
+
async function p() {
|
|
700
|
+
return h || (h = await navigator.storage.getDirectory()), h;
|
|
539
701
|
}
|
|
540
|
-
function
|
|
541
|
-
|
|
702
|
+
function b(u) {
|
|
703
|
+
return u.byteOffset === 0 && u.byteLength === u.buffer.byteLength ? u.buffer : u.buffer.slice(u.byteOffset, u.byteOffset + u.byteLength);
|
|
542
704
|
}
|
|
543
705
|
return {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
706
|
+
async save(u, l) {
|
|
707
|
+
const f = await (await (await p()).getFileHandle(u, { create: !0 })).createWritable();
|
|
708
|
+
await f.write(b(l)), await f.close();
|
|
709
|
+
},
|
|
710
|
+
async load(u) {
|
|
711
|
+
try {
|
|
712
|
+
const f = await (await (await (await p()).getFileHandle(u)).getFile()).arrayBuffer();
|
|
713
|
+
return new Uint8Array(f);
|
|
714
|
+
} catch {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
},
|
|
718
|
+
async remove(u) {
|
|
719
|
+
try {
|
|
720
|
+
await (await p()).removeEntry(u);
|
|
721
|
+
} catch {
|
|
722
|
+
}
|
|
723
|
+
},
|
|
724
|
+
async list() {
|
|
725
|
+
const u = await p(), l = [], y = u;
|
|
726
|
+
for await (const [d] of y)
|
|
727
|
+
l.push(d);
|
|
728
|
+
return l;
|
|
729
|
+
},
|
|
730
|
+
async clear() {
|
|
731
|
+
const u = await p(), l = [], y = u;
|
|
732
|
+
for await (const [d] of y)
|
|
733
|
+
l.push(d);
|
|
734
|
+
for (const d of l)
|
|
735
|
+
await u.removeEntry(d, { recursive: !0 });
|
|
736
|
+
}
|
|
558
737
|
};
|
|
559
738
|
}
|
|
560
739
|
export {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
J as createZip,
|
|
565
|
-
ee as decompress,
|
|
566
|
-
Ue as downloadAsZip,
|
|
567
|
-
k as downloadBlob,
|
|
568
|
-
ye as extractFile,
|
|
569
|
-
te as extractZip,
|
|
570
|
-
pe as listZip,
|
|
571
|
-
he as useFileSystem,
|
|
572
|
-
ve as useZip
|
|
740
|
+
ce as createFileSystem,
|
|
741
|
+
le as createOPFSAdapter,
|
|
742
|
+
ue as useFileSystem
|
|
573
743
|
};
|