@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.
@@ -1,60 +1,60 @@
1
- import { shallowRef as ue, computed as N, ref as _ } from "vue";
2
- function fe() {
3
- const n = {
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
- }, o = /* @__PURE__ */ new Set();
10
- function s(e, t, i) {
11
- for (const r of o)
12
- r(e, t, i);
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 c(e) {
15
- const t = e.split(/[/\\]/).filter((r) => r.length > 0 && r !== "."), i = [];
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 === ".." ? i.pop() : i.push(r);
18
- return "/" + i.join("/");
17
+ r === ".." ? n.pop() : n.push(r);
18
+ return "/" + n.join("/");
19
19
  }
20
- function l(e) {
21
- const t = c(e);
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 f(e) {
25
- const { segments: t } = l(e);
24
+ function d(e) {
25
+ const { segments: t } = u(e);
26
26
  if (t.length === 0)
27
27
  return { parentPath: "/", name: "" };
28
- const i = t[t.length - 1] ?? "";
29
- return { parentPath: "/" + t.slice(0, -1).join("/"), name: i };
30
- }
31
- function u(e, t = !1) {
32
- const { segments: i } = l(e);
33
- let r = n;
34
- for (const a of i) {
35
- let d = r.directories.get(a);
36
- if (!d) {
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
- d = {
40
- name: a,
41
- path: r.path === "/" ? `/${a}` : `${r.path}/${a}`,
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(a, d), s("create", d.path, "directory");
45
+ }, r.directories.set(o, i), p("create", i.path, "directory");
46
46
  }
47
- r = d;
47
+ r = i;
48
48
  }
49
49
  return r;
50
50
  }
51
- function w(e) {
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 h(e) {
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 x(e) {
95
+ function w(e) {
96
96
  return new Uint8Array(e);
97
97
  }
98
- function p(e, t, i = {}) {
99
- const { parentPath: r, name: a } = f(e), { normalized: d } = l(e);
100
- if (!a)
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 S = u(r, !0);
103
- if (!S)
102
+ const c = s(r, !0);
103
+ if (!c)
104
104
  return { success: !1, error: `Failed to create parent directory: ${r}` };
105
- const E = S.files.get(a);
106
- if (E && i.overwrite === !1)
107
- return { success: !1, error: `File already exists: ${d}` };
108
- const $ = typeof t == "string" ? w(t) : x(t), H = Date.now(), ae = {
109
- name: a,
110
- path: d,
111
- content: $,
112
- size: $.length,
113
- mimeType: i.mimeType ?? h(a),
114
- createdAt: E?.createdAt ?? H,
115
- modifiedAt: H
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 S.files.set(a, ae), s(E ? "modify" : "create", d, "file"), { success: !0 };
118
- }
119
- function m(e, t) {
120
- const i = y(e, { encoding: "binary" }), r = typeof t == "string" ? w(t) : t;
121
- if (i === void 0)
122
- return p(e, r);
123
- const a = i, d = new Uint8Array(a.length + r.length);
124
- return d.set(a, 0), d.set(r, a.length), p(e, d);
125
- }
126
- function y(e, t = {}) {
127
- const { parentPath: i, name: r } = f(e), d = u(i)?.files.get(r);
128
- return d ? (t.encoding ?? "utf8") === "binary" ? x(d.content) : A(d.content) : void 0;
129
- }
130
- function T(e) {
131
- const { parentPath: t, name: i } = f(e), a = u(t)?.files.get(i);
132
- if (a)
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: a.name,
135
- path: a.path,
136
- size: a.size,
137
- mimeType: a.mimeType,
138
- createdAt: a.createdAt,
139
- modifiedAt: a.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 U(e) {
143
- return T(e) !== void 0 || b(e);
142
+ function N(e) {
143
+ return x(e) !== void 0 || $(e);
144
144
  }
145
- function v(e) {
146
- return T(e) !== void 0;
145
+ function B(e) {
146
+ return x(e) !== void 0;
147
147
  }
148
- function b(e) {
149
- return u(e) !== void 0;
148
+ function $(e) {
149
+ return s(e) !== void 0;
150
150
  }
151
- function O(e) {
152
- const { parentPath: t, name: i } = f(e), { normalized: r } = l(e), a = u(t);
153
- return a ? a.files.has(i) ? (a.files.delete(i), s("delete", r, "file"), { success: !0 }) : { success: !1, error: `File not found: ${r}` } : { success: !1, error: `Parent directory not found: ${t}` };
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 z(e, t, i = {}) {
156
- const r = y(e, { encoding: "binary" });
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 a = T(e);
160
- return p(t, r, {
161
- mimeType: a?.mimeType,
162
- overwrite: i.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 B(e, t, i = {}) {
166
- const r = z(e, t, { overwrite: i.overwrite });
167
- return r.success ? O(e) : r;
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 C(e, t) {
170
- return B(e, t, { overwrite: !1 });
169
+ function J(e, t) {
170
+ return F(e, t, { overwrite: !1 });
171
171
  }
172
172
  function R(e) {
173
- return u(e, !0) ? { success: !0 } : { success: !1, error: `Failed to create directory: ${e}` };
173
+ return s(e, !0) ? { success: !0 } : { success: !1, error: `Failed to create directory: ${e}` };
174
174
  }
175
- function L(e) {
176
- const { parentPath: t, name: i } = f(e), { normalized: r } = l(e);
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 a = u(t);
180
- if (!a)
179
+ const o = s(t);
180
+ if (!o)
181
181
  return { success: !1, error: `Parent directory not found: ${t}` };
182
- const d = a.directories.get(i);
183
- return d ? d.files.size > 0 || d.directories.size > 0 ? { success: !1, error: `Directory not empty: ${r}` } : (a.directories.delete(i), s("delete", r, "directory"), { success: !0 }) : { success: !1, error: `Directory not found: ${r}` };
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 D(e) {
186
- const { parentPath: t, name: i } = f(e), { normalized: r } = l(e);
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 a = u(t);
190
- return a ? a.directories.get(i) ? (a.directories.delete(i), s("delete", r, "directory"), { success: !0 }) : { success: !1, error: `Directory not found: ${r}` } : { success: !1, error: `Parent directory not found: ${t}` };
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 F(e, t = {}) {
193
- const { recursive: i = !1, filesOnly: r = !1, directoriesOnly: a = !1 } = t, d = e === "/" || e === "" ? n : u(e);
194
- if (!d)
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 S = [];
197
- if (!a)
198
- for (const E of d.files.values())
199
- S.push({
200
- name: E.name,
201
- path: E.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: E.size
203
+ size: a.size
204
204
  });
205
205
  if (!r) {
206
- for (const E of d.directories.values())
207
- if (S.push({
208
- name: E.name,
209
- path: E.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
- }), i) {
212
- const $ = F(E.path, t);
213
- S.push(...$);
211
+ }), n) {
212
+ const z = O(a.path, t);
213
+ c.push(...z);
214
214
  }
215
215
  }
216
- return S;
216
+ return c;
217
217
  }
218
- function g(e) {
219
- const t = u(e);
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(i) {
230
- for (const r of i.files.values())
229
+ function t(n) {
230
+ for (const r of n.files.values())
231
231
  e.push(r);
232
- for (const r of i.directories.values())
232
+ for (const r of n.directories.values())
233
233
  t(r);
234
234
  }
235
- return t(n), e;
235
+ return t(m), e;
236
236
  }
237
- function I() {
237
+ function S() {
238
238
  return P().map((e) => e.path);
239
239
  }
240
- function ne() {
241
- let e = 0, t = 0, i = 0;
242
- function r(a) {
243
- for (const d of a.files.values())
244
- e++, i += d.size;
245
- for (const d of a.directories.values())
246
- t++, r(d);
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(n), { totalFiles: e, totalDirectories: t, totalSize: i };
248
+ return r(m), { totalFiles: e, totalDirectories: t, totalSize: n };
249
249
  }
250
- function W() {
251
- n.files.clear(), n.directories.clear(), s("delete", "/", "directory");
250
+ function C() {
251
+ m.files.clear(), m.directories.clear(), p("delete", "/", "directory");
252
252
  }
253
- function re(e) {
254
- const t = I(), i = e.replace(/\./g, "\\.").replace(/\*\*/g, "<<<GLOBSTAR>>>").replace(/\*/g, "[^/]*").replace(/<<<GLOBSTAR>>>/g, ".*"), r = new RegExp(`^${i}$`);
255
- return t.filter((a) => r.test(a));
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 oe(e) {
257
+ function k(e) {
258
258
  const t = e.startsWith(".") ? e : `.${e}`;
259
- return I().filter((i) => i.endsWith(t));
259
+ return S().filter((n) => n.endsWith(t));
260
260
  }
261
- function se(e) {
262
- return o.add(e), () => {
263
- o.delete(e);
261
+ function I(e) {
262
+ return l.add(e), () => {
263
+ l.delete(e);
264
264
  };
265
265
  }
266
- function ie() {
266
+ function q() {
267
267
  const e = {};
268
268
  for (const t of P()) {
269
- const i = btoa(
269
+ const n = btoa(
270
270
  Array.from(t.content, (r) => String.fromCharCode(r)).join("")
271
271
  );
272
272
  e[t.path] = {
273
- content: i,
273
+ content: n,
274
274
  mimeType: t.mimeType
275
275
  };
276
276
  }
277
277
  return e;
278
278
  }
279
- function ce(e) {
280
- W();
281
- for (const [t, { content: i, mimeType: r }] of Object.entries(e)) {
282
- const a = atob(i), d = Uint8Array.from(a, (S) => S.charCodeAt(0));
283
- p(t, d, { mimeType: r });
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: p,
289
- appendFile: m,
290
- readFile: y,
291
- stat: T,
292
- exists: U,
293
- isFile: v,
294
- isDirectory: b,
295
- remove: O,
296
- copy: z,
297
- move: B,
298
- rename: C,
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: L,
302
- rmdirRecursive: D,
303
- list: F,
304
- statDirectory: g,
301
+ rmdir: M,
302
+ rmdirRecursive: U,
303
+ list: O,
304
+ statDirectory: L,
305
305
  // Bulk operations
306
306
  getAllFiles: P,
307
- getAllPaths: I,
308
- getStats: ne,
309
- clear: W,
307
+ getAllPaths: S,
308
+ getStats: G,
309
+ clear: C,
310
310
  // Search
311
- find: re,
312
- findByExtension: oe,
311
+ find: W,
312
+ findByExtension: k,
313
313
  // Watchers
314
- watch: se,
314
+ watch: I,
315
315
  // Serialization
316
- toJSON: ie,
317
- fromJSON: ce
316
+ toJSON: q,
317
+ fromJSON: H
318
318
  };
319
319
  }
320
- function he(n = {}) {
321
- const { adapter: o, autoPersist: s = !1 } = n, c = fe(), l = ue(0);
322
- function f() {
323
- l.value++, s && o && h();
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
- c.watch(() => {
326
- f();
325
+ y.watch(() => {
326
+ d();
327
327
  });
328
- const u = N(() => (l.value, c.getStats())), w = N(() => u.value.totalFiles), A = N(() => u.value.totalSize);
329
- async function h() {
330
- if (!o)
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 p = c.toJSON(), m = new TextEncoder().encode(JSON.stringify(p));
333
- await o.save("filesystem", m);
332
+ const f = y.toJSON(), g = new TextEncoder().encode(JSON.stringify(f));
333
+ await l.save("filesystem", g);
334
334
  }
335
- async function x() {
336
- if (!o)
335
+ async function w() {
336
+ if (!l)
337
337
  throw new Error("No storage adapter configured");
338
- const p = await o.load("filesystem");
339
- if (p) {
340
- const m = JSON.parse(new TextDecoder().decode(p));
341
- c.fromJSON(m), f();
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
- ...c,
346
- stats: u,
347
- fileCount: w,
345
+ ...y,
346
+ stats: s,
347
+ fileCount: h,
348
348
  totalSize: A,
349
- persist: h,
350
- restore: x
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
- X as compress,
562
- K as computeCrc32,
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
  };