@mikestools/usefilesystem 0.0.1 → 0.0.2
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 +349 -118
- package/dist/index.d.ts +0 -200
- package/dist/usefilesystem.js +199 -416
- package/dist/usefilesystem.umd.cjs +1 -1
- package/package.json +2 -1
package/dist/usefilesystem.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { shallowRef as
|
|
2
|
-
function
|
|
3
|
-
const
|
|
1
|
+
import { shallowRef as Q, computed as b } from "vue";
|
|
2
|
+
function V() {
|
|
3
|
+
const m = {
|
|
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 r of
|
|
12
|
-
r(e, t,
|
|
9
|
+
}, l = /* @__PURE__ */ new Set();
|
|
10
|
+
function p(e, t, n) {
|
|
11
|
+
for (const r of l)
|
|
12
|
+
r(e, t, n);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
const t = e.split(/[/\\]/).filter((r) => r.length > 0 && r !== "."),
|
|
14
|
+
function y(e) {
|
|
15
|
+
const t = e.split(/[/\\]/).filter((r) => r.length > 0 && r !== "."), n = [];
|
|
16
16
|
for (const r of t)
|
|
17
|
-
r === ".." ?
|
|
18
|
-
return "/" +
|
|
17
|
+
r === ".." ? n.pop() : n.push(r);
|
|
18
|
+
return "/" + n.join("/");
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
const t =
|
|
20
|
+
function u(e) {
|
|
21
|
+
const t = y(e);
|
|
22
22
|
return { segments: t.split("/").filter((r) => r.length > 0), normalized: t };
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
const { segments: t } =
|
|
24
|
+
function d(e) {
|
|
25
|
+
const { segments: t } = u(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 r =
|
|
34
|
-
for (const
|
|
35
|
-
let
|
|
36
|
-
if (!
|
|
28
|
+
const n = t[t.length - 1] ?? "";
|
|
29
|
+
return { parentPath: "/" + t.slice(0, -1).join("/"), name: n };
|
|
30
|
+
}
|
|
31
|
+
function s(e, t = !1) {
|
|
32
|
+
const { segments: n } = u(e);
|
|
33
|
+
let r = m;
|
|
34
|
+
for (const o of n) {
|
|
35
|
+
let i = r.directories.get(o);
|
|
36
|
+
if (!i) {
|
|
37
37
|
if (!t)
|
|
38
38
|
return;
|
|
39
|
-
|
|
40
|
-
name:
|
|
41
|
-
path: r.path === "/" ? `/${
|
|
39
|
+
i = {
|
|
40
|
+
name: o,
|
|
41
|
+
path: r.path === "/" ? `/${o}` : `${r.path}/${o}`,
|
|
42
42
|
createdAt: Date.now(),
|
|
43
43
|
files: /* @__PURE__ */ new Map(),
|
|
44
44
|
directories: /* @__PURE__ */ new Map()
|
|
45
|
-
}, r.directories.set(
|
|
45
|
+
}, r.directories.set(o, i), p("create", i.path, "directory");
|
|
46
46
|
}
|
|
47
|
-
r =
|
|
47
|
+
r = i;
|
|
48
48
|
}
|
|
49
49
|
return r;
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function h(e) {
|
|
52
52
|
return new TextEncoder().encode(e);
|
|
53
53
|
}
|
|
54
54
|
function A(e) {
|
|
55
55
|
return new TextDecoder().decode(e);
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function v(e) {
|
|
58
58
|
const t = e.split(".").pop()?.toLowerCase() ?? "";
|
|
59
59
|
return {
|
|
60
60
|
txt: "text/plain",
|
|
@@ -92,131 +92,131 @@ function fe() {
|
|
|
92
92
|
webm: "video/webm"
|
|
93
93
|
}[t] ?? "application/octet-stream";
|
|
94
94
|
}
|
|
95
|
-
function
|
|
95
|
+
function w(e) {
|
|
96
96
|
return new Uint8Array(e);
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
const { parentPath: r, name:
|
|
100
|
-
if (!
|
|
98
|
+
function f(e, t, n = {}) {
|
|
99
|
+
const { parentPath: r, name: o } = d(e), { normalized: i } = u(e);
|
|
100
|
+
if (!o)
|
|
101
101
|
return { success: !1, error: "Invalid file path: no filename specified" };
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
102
|
+
const c = s(r, !0);
|
|
103
|
+
if (!c)
|
|
104
104
|
return { success: !1, error: `Failed to create parent directory: ${r}` };
|
|
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:
|
|
105
|
+
const a = c.files.get(o);
|
|
106
|
+
if (a && n.overwrite === !1)
|
|
107
|
+
return { success: !1, error: `File already exists: ${i}` };
|
|
108
|
+
const z = typeof t == "string" ? h(t) : w(t), E = Date.now(), K = {
|
|
109
|
+
name: o,
|
|
110
|
+
path: i,
|
|
111
|
+
content: z,
|
|
112
|
+
size: z.length,
|
|
113
|
+
mimeType: n.mimeType ?? v(o),
|
|
114
|
+
createdAt: a?.createdAt ?? E,
|
|
115
|
+
modifiedAt: E
|
|
116
116
|
};
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
function
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
return
|
|
123
|
-
const
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
function
|
|
127
|
-
const { parentPath:
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
function
|
|
131
|
-
const { parentPath: t, name:
|
|
132
|
-
if (
|
|
117
|
+
return c.files.set(o, K), p(a ? "modify" : "create", i, "file"), { success: !0 };
|
|
118
|
+
}
|
|
119
|
+
function g(e, t) {
|
|
120
|
+
const n = T(e, { encoding: "binary" }), r = typeof t == "string" ? h(t) : t;
|
|
121
|
+
if (n === void 0)
|
|
122
|
+
return f(e, r);
|
|
123
|
+
const o = n, i = new Uint8Array(o.length + r.length);
|
|
124
|
+
return i.set(o, 0), i.set(r, o.length), f(e, i);
|
|
125
|
+
}
|
|
126
|
+
function T(e, t = {}) {
|
|
127
|
+
const { parentPath: n, name: r } = d(e), i = s(n)?.files.get(r);
|
|
128
|
+
return i ? (t.encoding ?? "utf8") === "binary" ? w(i.content) : A(i.content) : void 0;
|
|
129
|
+
}
|
|
130
|
+
function x(e) {
|
|
131
|
+
const { parentPath: t, name: n } = d(e), o = s(t)?.files.get(n);
|
|
132
|
+
if (o)
|
|
133
133
|
return {
|
|
134
|
-
name:
|
|
135
|
-
path:
|
|
136
|
-
size:
|
|
137
|
-
mimeType:
|
|
138
|
-
createdAt:
|
|
139
|
-
modifiedAt:
|
|
134
|
+
name: o.name,
|
|
135
|
+
path: o.path,
|
|
136
|
+
size: o.size,
|
|
137
|
+
mimeType: o.mimeType,
|
|
138
|
+
createdAt: o.createdAt,
|
|
139
|
+
modifiedAt: o.modifiedAt
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
|
-
function
|
|
143
|
-
return
|
|
142
|
+
function N(e) {
|
|
143
|
+
return x(e) !== void 0 || $(e);
|
|
144
144
|
}
|
|
145
|
-
function
|
|
146
|
-
return
|
|
145
|
+
function B(e) {
|
|
146
|
+
return x(e) !== void 0;
|
|
147
147
|
}
|
|
148
|
-
function
|
|
149
|
-
return
|
|
148
|
+
function $(e) {
|
|
149
|
+
return s(e) !== void 0;
|
|
150
150
|
}
|
|
151
|
-
function
|
|
152
|
-
const { parentPath: t, name:
|
|
153
|
-
return
|
|
151
|
+
function D(e) {
|
|
152
|
+
const { parentPath: t, name: n } = d(e), { normalized: r } = u(e), o = s(t);
|
|
153
|
+
return o ? o.files.has(n) ? (o.files.delete(n), p("delete", r, "file"), { success: !0 }) : { success: !1, error: `File not found: ${r}` } : { success: !1, error: `Parent directory not found: ${t}` };
|
|
154
154
|
}
|
|
155
|
-
function
|
|
156
|
-
const r =
|
|
155
|
+
function j(e, t, n = {}) {
|
|
156
|
+
const r = T(e, { encoding: "binary" });
|
|
157
157
|
if (r === void 0)
|
|
158
158
|
return { success: !1, error: `Source file not found: ${e}` };
|
|
159
|
-
const
|
|
160
|
-
return
|
|
161
|
-
mimeType:
|
|
162
|
-
overwrite:
|
|
159
|
+
const o = x(e);
|
|
160
|
+
return f(t, r, {
|
|
161
|
+
mimeType: o?.mimeType,
|
|
162
|
+
overwrite: n.overwrite
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
-
function
|
|
166
|
-
const r =
|
|
167
|
-
return r.success ?
|
|
165
|
+
function F(e, t, n = {}) {
|
|
166
|
+
const r = j(e, t, { overwrite: n.overwrite });
|
|
167
|
+
return r.success ? D(e) : r;
|
|
168
168
|
}
|
|
169
|
-
function
|
|
170
|
-
return
|
|
169
|
+
function J(e, t) {
|
|
170
|
+
return F(e, t, { overwrite: !1 });
|
|
171
171
|
}
|
|
172
172
|
function R(e) {
|
|
173
|
-
return
|
|
173
|
+
return s(e, !0) ? { success: !0 } : { success: !1, error: `Failed to create directory: ${e}` };
|
|
174
174
|
}
|
|
175
|
-
function
|
|
176
|
-
const { parentPath: t, name:
|
|
175
|
+
function M(e) {
|
|
176
|
+
const { parentPath: t, name: n } = d(e), { normalized: r } = u(e);
|
|
177
177
|
if (r === "/")
|
|
178
178
|
return { success: !1, error: "Cannot remove root directory" };
|
|
179
|
-
const
|
|
180
|
-
if (!
|
|
179
|
+
const o = s(t);
|
|
180
|
+
if (!o)
|
|
181
181
|
return { success: !1, error: `Parent directory not found: ${t}` };
|
|
182
|
-
const
|
|
183
|
-
return
|
|
182
|
+
const i = o.directories.get(n);
|
|
183
|
+
return i ? i.files.size > 0 || i.directories.size > 0 ? { success: !1, error: `Directory not empty: ${r}` } : (o.directories.delete(n), p("delete", r, "directory"), { success: !0 }) : { success: !1, error: `Directory not found: ${r}` };
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
const { parentPath: t, name:
|
|
185
|
+
function U(e) {
|
|
186
|
+
const { parentPath: t, name: n } = d(e), { normalized: r } = u(e);
|
|
187
187
|
if (r === "/")
|
|
188
188
|
return { success: !1, error: "Cannot remove root directory" };
|
|
189
|
-
const
|
|
190
|
-
return
|
|
189
|
+
const o = s(t);
|
|
190
|
+
return o ? o.directories.get(n) ? (o.directories.delete(n), p("delete", r, "directory"), { success: !0 }) : { success: !1, error: `Directory not found: ${r}` } : { success: !1, error: `Parent directory not found: ${t}` };
|
|
191
191
|
}
|
|
192
|
-
function
|
|
193
|
-
const { recursive:
|
|
194
|
-
if (!
|
|
192
|
+
function O(e, t = {}) {
|
|
193
|
+
const { recursive: n = !1, filesOnly: r = !1, directoriesOnly: o = !1 } = t, i = e === "/" || e === "" ? m : s(e);
|
|
194
|
+
if (!i)
|
|
195
195
|
return [];
|
|
196
|
-
const
|
|
197
|
-
if (!
|
|
198
|
-
for (const
|
|
199
|
-
|
|
200
|
-
name:
|
|
201
|
-
path:
|
|
196
|
+
const c = [];
|
|
197
|
+
if (!o)
|
|
198
|
+
for (const a of i.files.values())
|
|
199
|
+
c.push({
|
|
200
|
+
name: a.name,
|
|
201
|
+
path: a.path,
|
|
202
202
|
type: "file",
|
|
203
|
-
size:
|
|
203
|
+
size: a.size
|
|
204
204
|
});
|
|
205
205
|
if (!r) {
|
|
206
|
-
for (const
|
|
207
|
-
if (
|
|
208
|
-
name:
|
|
209
|
-
path:
|
|
206
|
+
for (const a of i.directories.values())
|
|
207
|
+
if (c.push({
|
|
208
|
+
name: a.name,
|
|
209
|
+
path: a.path,
|
|
210
210
|
type: "directory"
|
|
211
|
-
}),
|
|
212
|
-
const
|
|
213
|
-
|
|
211
|
+
}), n) {
|
|
212
|
+
const z = O(a.path, t);
|
|
213
|
+
c.push(...z);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
|
-
return
|
|
216
|
+
return c;
|
|
217
217
|
}
|
|
218
|
-
function
|
|
219
|
-
const t =
|
|
218
|
+
function L(e) {
|
|
219
|
+
const t = s(e);
|
|
220
220
|
if (t)
|
|
221
221
|
return {
|
|
222
222
|
name: t.name,
|
|
@@ -226,348 +226,131 @@ function fe() {
|
|
|
226
226
|
}
|
|
227
227
|
function P() {
|
|
228
228
|
const e = [];
|
|
229
|
-
function t(
|
|
230
|
-
for (const r of
|
|
229
|
+
function t(n) {
|
|
230
|
+
for (const r of n.files.values())
|
|
231
231
|
e.push(r);
|
|
232
|
-
for (const r of
|
|
232
|
+
for (const r of n.directories.values())
|
|
233
233
|
t(r);
|
|
234
234
|
}
|
|
235
|
-
return t(
|
|
235
|
+
return t(m), e;
|
|
236
236
|
}
|
|
237
|
-
function
|
|
237
|
+
function S() {
|
|
238
238
|
return P().map((e) => e.path);
|
|
239
239
|
}
|
|
240
|
-
function
|
|
241
|
-
let e = 0, t = 0,
|
|
242
|
-
function r(
|
|
243
|
-
for (const
|
|
244
|
-
e++,
|
|
245
|
-
for (const
|
|
246
|
-
t++, r(
|
|
240
|
+
function G() {
|
|
241
|
+
let e = 0, t = 0, n = 0;
|
|
242
|
+
function r(o) {
|
|
243
|
+
for (const i of o.files.values())
|
|
244
|
+
e++, n += i.size;
|
|
245
|
+
for (const i of o.directories.values())
|
|
246
|
+
t++, r(i);
|
|
247
247
|
}
|
|
248
|
-
return r(
|
|
248
|
+
return r(m), { totalFiles: e, totalDirectories: t, totalSize: n };
|
|
249
249
|
}
|
|
250
|
-
function
|
|
251
|
-
|
|
250
|
+
function C() {
|
|
251
|
+
m.files.clear(), m.directories.clear(), p("delete", "/", "directory");
|
|
252
252
|
}
|
|
253
|
-
function
|
|
254
|
-
const t =
|
|
255
|
-
return t.filter((
|
|
253
|
+
function W(e) {
|
|
254
|
+
const t = S(), n = e.replace(/\./g, "\\.").replace(/\*\*/g, "<<<GLOBSTAR>>>").replace(/\*/g, "[^/]*").replace(/<<<GLOBSTAR>>>/g, ".*"), r = new RegExp(`^${n}$`);
|
|
255
|
+
return t.filter((o) => r.test(o));
|
|
256
256
|
}
|
|
257
|
-
function
|
|
257
|
+
function k(e) {
|
|
258
258
|
const t = e.startsWith(".") ? e : `.${e}`;
|
|
259
|
-
return
|
|
259
|
+
return S().filter((n) => n.endsWith(t));
|
|
260
260
|
}
|
|
261
|
-
function
|
|
262
|
-
return
|
|
263
|
-
|
|
261
|
+
function I(e) {
|
|
262
|
+
return l.add(e), () => {
|
|
263
|
+
l.delete(e);
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function q() {
|
|
267
267
|
const e = {};
|
|
268
268
|
for (const t of P()) {
|
|
269
|
-
const
|
|
269
|
+
const n = btoa(
|
|
270
270
|
Array.from(t.content, (r) => String.fromCharCode(r)).join("")
|
|
271
271
|
);
|
|
272
272
|
e[t.path] = {
|
|
273
|
-
content:
|
|
273
|
+
content: n,
|
|
274
274
|
mimeType: t.mimeType
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
277
|
return e;
|
|
278
278
|
}
|
|
279
|
-
function
|
|
280
|
-
|
|
281
|
-
for (const [t, { content:
|
|
282
|
-
const
|
|
283
|
-
|
|
279
|
+
function H(e) {
|
|
280
|
+
C();
|
|
281
|
+
for (const [t, { content: n, mimeType: r }] of Object.entries(e)) {
|
|
282
|
+
const o = atob(n), i = Uint8Array.from(o, (c) => c.charCodeAt(0));
|
|
283
|
+
f(t, i, { mimeType: r });
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
return {
|
|
287
287
|
// File operations
|
|
288
|
-
writeFile:
|
|
289
|
-
appendFile:
|
|
290
|
-
readFile:
|
|
291
|
-
stat:
|
|
292
|
-
exists:
|
|
293
|
-
isFile:
|
|
294
|
-
isDirectory:
|
|
295
|
-
remove:
|
|
296
|
-
copy:
|
|
297
|
-
move:
|
|
298
|
-
rename:
|
|
288
|
+
writeFile: f,
|
|
289
|
+
appendFile: g,
|
|
290
|
+
readFile: T,
|
|
291
|
+
stat: x,
|
|
292
|
+
exists: N,
|
|
293
|
+
isFile: B,
|
|
294
|
+
isDirectory: $,
|
|
295
|
+
remove: D,
|
|
296
|
+
copy: j,
|
|
297
|
+
move: F,
|
|
298
|
+
rename: J,
|
|
299
299
|
// Directory operations
|
|
300
300
|
mkdir: R,
|
|
301
|
-
rmdir:
|
|
302
|
-
rmdirRecursive:
|
|
303
|
-
list:
|
|
304
|
-
statDirectory:
|
|
301
|
+
rmdir: M,
|
|
302
|
+
rmdirRecursive: U,
|
|
303
|
+
list: O,
|
|
304
|
+
statDirectory: L,
|
|
305
305
|
// Bulk operations
|
|
306
306
|
getAllFiles: P,
|
|
307
|
-
getAllPaths:
|
|
308
|
-
getStats:
|
|
309
|
-
clear:
|
|
307
|
+
getAllPaths: S,
|
|
308
|
+
getStats: G,
|
|
309
|
+
clear: C,
|
|
310
310
|
// Search
|
|
311
|
-
find:
|
|
312
|
-
findByExtension:
|
|
311
|
+
find: W,
|
|
312
|
+
findByExtension: k,
|
|
313
313
|
// Watchers
|
|
314
|
-
watch:
|
|
314
|
+
watch: I,
|
|
315
315
|
// Serialization
|
|
316
|
-
toJSON:
|
|
317
|
-
fromJSON:
|
|
316
|
+
toJSON: q,
|
|
317
|
+
fromJSON: H
|
|
318
318
|
};
|
|
319
319
|
}
|
|
320
|
-
function
|
|
321
|
-
const { adapter:
|
|
322
|
-
function
|
|
323
|
-
|
|
320
|
+
function Y(m = {}) {
|
|
321
|
+
const { adapter: l, autoPersist: p = !1 } = m, y = V(), u = Q(0);
|
|
322
|
+
function d() {
|
|
323
|
+
u.value++, p && l && v();
|
|
324
324
|
}
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
y.watch(() => {
|
|
326
|
+
d();
|
|
327
327
|
});
|
|
328
|
-
const
|
|
329
|
-
async function
|
|
330
|
-
if (!
|
|
328
|
+
const s = b(() => (u.value, y.getStats())), h = b(() => s.value.totalFiles), A = b(() => s.value.totalSize);
|
|
329
|
+
async function v() {
|
|
330
|
+
if (!l)
|
|
331
331
|
throw new Error("No storage adapter configured");
|
|
332
|
-
const
|
|
333
|
-
await
|
|
332
|
+
const f = y.toJSON(), g = new TextEncoder().encode(JSON.stringify(f));
|
|
333
|
+
await l.save("filesystem", g);
|
|
334
334
|
}
|
|
335
|
-
async function
|
|
336
|
-
if (!
|
|
335
|
+
async function w() {
|
|
336
|
+
if (!l)
|
|
337
337
|
throw new Error("No storage adapter configured");
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
340
|
-
const
|
|
341
|
-
|
|
338
|
+
const f = await l.load("filesystem");
|
|
339
|
+
if (f) {
|
|
340
|
+
const g = JSON.parse(new TextDecoder().decode(f));
|
|
341
|
+
y.fromJSON(g), d();
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
return {
|
|
345
|
-
...
|
|
346
|
-
stats:
|
|
347
|
-
fileCount:
|
|
345
|
+
...y,
|
|
346
|
+
stats: s,
|
|
347
|
+
fileCount: h,
|
|
348
348
|
totalSize: A,
|
|
349
|
-
persist:
|
|
350
|
-
restore:
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
const Y = 67324752, G = 33639248, q = 101010256, le = 0, M = 8, de = (function() {
|
|
354
|
-
const o = new Uint32Array(256);
|
|
355
|
-
for (let s = 0; s < 256; s++) {
|
|
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++;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
return l;
|
|
479
|
-
}
|
|
480
|
-
async function ye(n, o) {
|
|
481
|
-
const s = await te(n, {
|
|
482
|
-
filter: (c) => c.path === o
|
|
483
|
-
});
|
|
484
|
-
return s.length > 0 ? s[0]?.content : void 0;
|
|
485
|
-
}
|
|
486
|
-
function ge(n) {
|
|
487
|
-
const o = new DataView(n.buffer, n.byteOffset, n.byteLength);
|
|
488
|
-
for (let s = n.length - 22; s >= 0; s--)
|
|
489
|
-
if (o.getUint32(s, !0) === q)
|
|
490
|
-
return {
|
|
491
|
-
entryCount: o.getUint16(s + 10, !0),
|
|
492
|
-
centralDirectorySize: o.getUint32(s + 12, !0),
|
|
493
|
-
centralDirectoryOffset: o.getUint32(s + 16, !0)
|
|
494
|
-
};
|
|
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
|
-
}
|
|
521
|
-
}
|
|
522
|
-
async function f(p, m = {}) {
|
|
523
|
-
return l(() => J(p, m));
|
|
524
|
-
}
|
|
525
|
-
async function u(p, m = {}) {
|
|
526
|
-
return l(() => te(p, m));
|
|
527
|
-
}
|
|
528
|
-
async function w(p, m) {
|
|
529
|
-
return l(() => ye(p, m));
|
|
530
|
-
}
|
|
531
|
-
async function A(p) {
|
|
532
|
-
return l(() => pe(p));
|
|
533
|
-
}
|
|
534
|
-
async function h(p, m, y = {}) {
|
|
535
|
-
return l(async () => {
|
|
536
|
-
const T = await J(p, y);
|
|
537
|
-
k(T, m);
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
function x() {
|
|
541
|
-
s.value = void 0;
|
|
542
|
-
}
|
|
543
|
-
return {
|
|
544
|
-
state: c,
|
|
545
|
-
isProcessing: n,
|
|
546
|
-
progress: o,
|
|
547
|
-
error: s,
|
|
548
|
-
create: f,
|
|
549
|
-
extract: u,
|
|
550
|
-
extractSingle: w,
|
|
551
|
-
list: A,
|
|
552
|
-
download: h,
|
|
553
|
-
downloadBlob: k,
|
|
554
|
-
compress: X,
|
|
555
|
-
decompress: ee,
|
|
556
|
-
computeCrc32: K,
|
|
557
|
-
clearError: x
|
|
349
|
+
persist: v,
|
|
350
|
+
restore: w
|
|
558
351
|
};
|
|
559
352
|
}
|
|
560
353
|
export {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
fe as createFileSystem,
|
|
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
|
|
354
|
+
V as createFileSystem,
|
|
355
|
+
Y as useFileSystem
|
|
573
356
|
};
|