@struktoai/mirage-browser 0.0.4 → 0.0.5
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 +2 -1
- package/dist/aliyun-DR6KT3H6.js +8 -0
- package/dist/backblaze-XCLZXTES.js +8 -0
- package/dist/box-XBCSU3AA.js +8 -0
- package/dist/ceph-F5S2NMTO.js +8 -0
- package/dist/{chunk-DGP3N4WM.js → chunk-2J35WXX5.js} +7 -2
- package/dist/chunk-2J35WXX5.js.map +1 -0
- package/dist/{chunk-LW56WZDS.js → chunk-2WNXK742.js} +2 -2
- package/dist/{chunk-PSEXJ5S5.js → chunk-2WSKXBSV.js} +11 -2
- package/dist/chunk-2WSKXBSV.js.map +1 -0
- package/dist/{chunk-DKPDXQML.js → chunk-3IYCVC7W.js} +7 -3
- package/dist/chunk-3IYCVC7W.js.map +1 -0
- package/dist/{chunk-NVGB3B7J.js → chunk-46HNNKFR.js} +7 -3
- package/dist/chunk-46HNNKFR.js.map +1 -0
- package/dist/chunk-4IF4TGAI.js +11 -0
- package/dist/chunk-4IF4TGAI.js.map +1 -0
- package/dist/{chunk-AUXZEXCG.js → chunk-5OZJMTYW.js} +7 -3
- package/dist/{chunk-AUXZEXCG.js.map → chunk-5OZJMTYW.js.map} +1 -1
- package/dist/{chunk-6BXVYCIC.js → chunk-5UM6EBVW.js} +10 -2
- package/dist/chunk-5UM6EBVW.js.map +1 -0
- package/dist/{chunk-JV4T5HNB.js → chunk-6HRSCX2U.js} +7 -3
- package/dist/chunk-6HRSCX2U.js.map +1 -0
- package/dist/{chunk-EDS5Q5B7.js → chunk-7HWQAYXR.js} +7 -3
- package/dist/chunk-7HWQAYXR.js.map +1 -0
- package/dist/{chunk-2R7SPBTM.js → chunk-AUZNQ7EI.js} +5 -10
- package/dist/chunk-AUZNQ7EI.js.map +1 -0
- package/dist/{chunk-DC6VA36O.js → chunk-BGA2F226.js} +19 -7
- package/dist/chunk-BGA2F226.js.map +1 -0
- package/dist/{chunk-NYTRDAWX.js → chunk-BV372CUO.js} +6 -11
- package/dist/chunk-BV372CUO.js.map +1 -0
- package/dist/{chunk-HTQ4GBKM.js → chunk-C4THTILY.js} +7 -3
- package/dist/chunk-C4THTILY.js.map +1 -0
- package/dist/{chunk-GENFT46X.js → chunk-D4MEOKNQ.js} +7 -3
- package/dist/chunk-D4MEOKNQ.js.map +1 -0
- package/dist/chunk-D4RAMWYH.js +88 -0
- package/dist/chunk-D4RAMWYH.js.map +1 -0
- package/dist/{chunk-3FZ3GHZO.js → chunk-EHIT6WCY.js} +7 -3
- package/dist/chunk-EHIT6WCY.js.map +1 -0
- package/dist/{chunk-PCC6EZIE.js → chunk-EN6TZYT2.js} +7 -3
- package/dist/chunk-EN6TZYT2.js.map +1 -0
- package/dist/{chunk-MB4TUUJQ.js → chunk-FTDVV7EQ.js} +7 -3
- package/dist/chunk-FTDVV7EQ.js.map +1 -0
- package/dist/{chunk-VASFK7V6.js → chunk-G67Q2Z6I.js} +7 -3
- package/dist/{chunk-VASFK7V6.js.map → chunk-G67Q2Z6I.js.map} +1 -1
- package/dist/{chunk-AAJQ6AQT.js → chunk-GM2QMJAY.js} +5 -10
- package/dist/chunk-GM2QMJAY.js.map +1 -0
- package/dist/{chunk-POJ3IQMQ.js → chunk-HRWLHJX2.js} +5 -11
- package/dist/chunk-HRWLHJX2.js.map +1 -0
- package/dist/{chunk-AUKVYHNZ.js → chunk-INEXV2PN.js} +7 -3
- package/dist/chunk-INEXV2PN.js.map +1 -0
- package/dist/chunk-IZMKMD3O.js +11 -0
- package/dist/chunk-IZMKMD3O.js.map +1 -0
- package/dist/{chunk-N5VRBFRT.js → chunk-JUVMJ5GI.js} +5 -10
- package/dist/{chunk-HPID7BWJ.js.map → chunk-JUVMJ5GI.js.map} +1 -1
- package/dist/{chunk-GQVJTQXU.js → chunk-L64GRKOD.js} +7 -2
- package/dist/chunk-L64GRKOD.js.map +1 -0
- package/dist/chunk-M2UF2JHJ.js +11 -0
- package/dist/chunk-M2UF2JHJ.js.map +1 -0
- package/dist/{chunk-5ZNWDS5I.js → chunk-NVHPJ5CV.js} +11 -2
- package/dist/chunk-NVHPJ5CV.js.map +1 -0
- package/dist/{chunk-MQMUOJZ2.js → chunk-OSTDTTWI.js} +7 -2
- package/dist/chunk-OSTDTTWI.js.map +1 -0
- package/dist/{chunk-GZFNGV55.js → chunk-PQCRGTSA.js} +7 -3
- package/dist/chunk-PQCRGTSA.js.map +1 -0
- package/dist/{chunk-6ETIHSTA.js → chunk-QE7QNA45.js} +6 -2
- package/dist/{chunk-6ETIHSTA.js.map → chunk-QE7QNA45.js.map} +1 -1
- package/dist/{chunk-EHTYPBGX.js → chunk-QG2NUNCY.js} +7 -3
- package/dist/chunk-QG2NUNCY.js.map +1 -0
- package/dist/chunk-UFHBDBZD.js +1212 -0
- package/dist/chunk-UFHBDBZD.js.map +1 -0
- package/dist/{chunk-E77ESWWV.js → chunk-UY22T4AC.js} +11 -3
- package/dist/chunk-UY22T4AC.js.map +1 -0
- package/dist/chunk-XJBC3OYX.js +11 -0
- package/dist/chunk-XJBC3OYX.js.map +1 -0
- package/dist/{chunk-TCFD6YJ5.js → chunk-Y6DYUK6J.js} +7 -3
- package/dist/chunk-Y6DYUK6J.js.map +1 -0
- package/dist/{chunk-HPID7BWJ.js → chunk-YOCTIHQZ.js} +5 -1
- package/dist/chunk-YOCTIHQZ.js.map +1 -0
- package/dist/{chunk-PDZSZ5CB.js → chunk-ZDJPUXYH.js} +6 -2
- package/dist/{chunk-PDZSZ5CB.js.map → chunk-ZDJPUXYH.js.map} +1 -1
- package/dist/{chunk-CQERQTAZ.js → chunk-ZKCOSE3R.js} +6 -9
- package/dist/chunk-ZKCOSE3R.js.map +1 -0
- package/dist/chunk-ZTHVEXIV.js +11 -0
- package/dist/chunk-ZTHVEXIV.js.map +1 -0
- package/dist/{config-MHBKYS53.js → config-2Y6LZKLV.js} +2 -2
- package/dist/config-4GSOMUMF.js +9 -0
- package/dist/config-5YBUWFUP.js +9 -0
- package/dist/{config-PWZXYJOI.js → config-DE5OZ4I7.js} +2 -2
- package/dist/config-ELDOFRJW.js +9 -0
- package/dist/config-FPM3LAW7.js +9 -0
- package/dist/{config-22T7HJBJ.js → config-JY557MA6.js} +2 -2
- package/dist/config-WRACCRPN.js +9 -0
- package/dist/digitalocean-QDHTRS2W.js +8 -0
- package/dist/discord-ERUI7OAQ.js +7 -0
- package/dist/dropbox-3U6D4HLE.js +8 -0
- package/dist/gcal-MTBSDG34.js +8 -0
- package/dist/gcs-KNGRBBET.js +8 -0
- package/dist/gdocs-RUIOIRKP.js +8 -0
- package/dist/gdrive-5JB7ZKEP.js +8 -0
- package/dist/github-CIXBFBVO.js +7 -0
- package/dist/github_ci-HR6YOYAO.js +8 -0
- package/dist/{gmail-HLZIMKQU.js → gmail-JHGWTQU5.js} +2 -2
- package/dist/gsheets-N54JO2RS.js +8 -0
- package/dist/gslides-B4VMNLMB.js +8 -0
- package/dist/index.d.ts +284 -352
- package/dist/index.js +165 -104
- package/dist/index.js.map +1 -1
- package/dist/langfuse-HEUJGDOC.js +7 -0
- package/dist/linear-J4QQ3CA6.js +7 -0
- package/dist/minio-BXWHJ6K5.js +8 -0
- package/dist/notion-I5S5SRLO.js +7 -0
- package/dist/oci-XOPKH4AE.js +8 -0
- package/dist/opfs-36QO72Y5.js +7 -0
- package/dist/qingstor-JKAHLK62.js +8 -0
- package/dist/r2-L3QXQ76M.js +8 -0
- package/dist/{s3-CSFY3PLT.js → s3-LRZJPGHK.js} +2 -2
- package/dist/scaleway-CGNDYNKS.js +8 -0
- package/dist/seaweedfs-BSQWCBIR.js +8 -0
- package/dist/slack-62ECSENR.js +7 -0
- package/dist/supabase-J66NXWAF.js +8 -0
- package/dist/tencent-AC667LV3.js +8 -0
- package/dist/trello-SUPG6VDF.js +7 -0
- package/dist/trello-SUPG6VDF.js.map +1 -0
- package/dist/wasabi-5KKPW6LH.js +8 -0
- package/dist/wasabi-5KKPW6LH.js.map +1 -0
- package/package.json +2 -2
- package/dist/aliyun-YEWHEWCL.js +0 -8
- package/dist/backblaze-LWE2HEDK.js +0 -8
- package/dist/box-GTWWIB6F.js +0 -8
- package/dist/ceph-ATSCSVGU.js +0 -8
- package/dist/chunk-23NO22WD.js +0 -25
- package/dist/chunk-23NO22WD.js.map +0 -1
- package/dist/chunk-2R7SPBTM.js.map +0 -1
- package/dist/chunk-3FZ3GHZO.js.map +0 -1
- package/dist/chunk-4YUYQTRN.js +0 -2334
- package/dist/chunk-4YUYQTRN.js.map +0 -1
- package/dist/chunk-5ZNWDS5I.js.map +0 -1
- package/dist/chunk-6BXVYCIC.js.map +0 -1
- package/dist/chunk-AAJQ6AQT.js.map +0 -1
- package/dist/chunk-AUKVYHNZ.js.map +0 -1
- package/dist/chunk-CQERQTAZ.js.map +0 -1
- package/dist/chunk-DC6VA36O.js.map +0 -1
- package/dist/chunk-DGP3N4WM.js.map +0 -1
- package/dist/chunk-DKPDXQML.js.map +0 -1
- package/dist/chunk-DQK6H5LW.js +0 -25
- package/dist/chunk-DQK6H5LW.js.map +0 -1
- package/dist/chunk-E77ESWWV.js.map +0 -1
- package/dist/chunk-EDS5Q5B7.js.map +0 -1
- package/dist/chunk-EHTYPBGX.js.map +0 -1
- package/dist/chunk-GENFT46X.js.map +0 -1
- package/dist/chunk-GQVJTQXU.js.map +0 -1
- package/dist/chunk-GZFNGV55.js.map +0 -1
- package/dist/chunk-HTQ4GBKM.js.map +0 -1
- package/dist/chunk-JV4T5HNB.js.map +0 -1
- package/dist/chunk-MB4TUUJQ.js.map +0 -1
- package/dist/chunk-MQMUOJZ2.js.map +0 -1
- package/dist/chunk-N5VRBFRT.js.map +0 -1
- package/dist/chunk-NVGB3B7J.js.map +0 -1
- package/dist/chunk-NYTRDAWX.js.map +0 -1
- package/dist/chunk-PCC6EZIE.js.map +0 -1
- package/dist/chunk-POJ3IQMQ.js.map +0 -1
- package/dist/chunk-PSEXJ5S5.js.map +0 -1
- package/dist/chunk-QXJP6TWI.js +0 -27
- package/dist/chunk-QXJP6TWI.js.map +0 -1
- package/dist/chunk-TCFD6YJ5.js.map +0 -1
- package/dist/chunk-ZLHC2CZ6.js +0 -25
- package/dist/chunk-ZLHC2CZ6.js.map +0 -1
- package/dist/config-A56HUM6C.js +0 -9
- package/dist/config-DIWQZBOK.js +0 -9
- package/dist/config-HGJ2MGAC.js +0 -9
- package/dist/config-PAHALM2T.js +0 -9
- package/dist/digitalocean-SQA6MJJQ.js +0 -8
- package/dist/discord-ASNFJP6A.js +0 -7
- package/dist/dropbox-VV2WZE6I.js +0 -8
- package/dist/gcs-2W6DDWM7.js +0 -8
- package/dist/gdocs-QPM7VXXE.js +0 -8
- package/dist/gdrive-KT6R7EVB.js +0 -8
- package/dist/github-3IFZGW6I.js +0 -7
- package/dist/github_ci-CKKF2Y4S.js +0 -8
- package/dist/gsheets-HF4YPIEF.js +0 -8
- package/dist/gslides-EV2JJH7I.js +0 -8
- package/dist/langfuse-74ZCR6QL.js +0 -7
- package/dist/linear-XABGTU6E.js +0 -7
- package/dist/minio-JPNSX2NP.js +0 -8
- package/dist/notion-YJOTGH7J.js +0 -7
- package/dist/oci-R4VYQKGJ.js +0 -8
- package/dist/opfs-4RWMJBCI.js +0 -7
- package/dist/qingstor-ZWWK2ZGV.js +0 -8
- package/dist/r2-PZAN2YFG.js +0 -8
- package/dist/scaleway-BFROPDBB.js +0 -8
- package/dist/seaweedfs-X6THZT26.js +0 -8
- package/dist/slack-O7BTJ4YR.js +0 -7
- package/dist/supabase-PHN3MIXW.js +0 -8
- package/dist/tencent-JGCJEKHV.js +0 -8
- package/dist/trello-QUDOP3M2.js +0 -7
- package/dist/wasabi-5VMNAFOC.js +0 -8
- /package/dist/{aliyun-YEWHEWCL.js.map → aliyun-DR6KT3H6.js.map} +0 -0
- /package/dist/{backblaze-LWE2HEDK.js.map → backblaze-XCLZXTES.js.map} +0 -0
- /package/dist/{box-GTWWIB6F.js.map → box-XBCSU3AA.js.map} +0 -0
- /package/dist/{ceph-ATSCSVGU.js.map → ceph-F5S2NMTO.js.map} +0 -0
- /package/dist/{chunk-LW56WZDS.js.map → chunk-2WNXK742.js.map} +0 -0
- /package/dist/{config-22T7HJBJ.js.map → config-2Y6LZKLV.js.map} +0 -0
- /package/dist/{config-A56HUM6C.js.map → config-4GSOMUMF.js.map} +0 -0
- /package/dist/{config-DIWQZBOK.js.map → config-5YBUWFUP.js.map} +0 -0
- /package/dist/{config-HGJ2MGAC.js.map → config-DE5OZ4I7.js.map} +0 -0
- /package/dist/{config-MHBKYS53.js.map → config-ELDOFRJW.js.map} +0 -0
- /package/dist/{config-PAHALM2T.js.map → config-FPM3LAW7.js.map} +0 -0
- /package/dist/{config-PWZXYJOI.js.map → config-JY557MA6.js.map} +0 -0
- /package/dist/{digitalocean-SQA6MJJQ.js.map → config-WRACCRPN.js.map} +0 -0
- /package/dist/{discord-ASNFJP6A.js.map → digitalocean-QDHTRS2W.js.map} +0 -0
- /package/dist/{dropbox-VV2WZE6I.js.map → discord-ERUI7OAQ.js.map} +0 -0
- /package/dist/{gcs-2W6DDWM7.js.map → dropbox-3U6D4HLE.js.map} +0 -0
- /package/dist/{gdocs-QPM7VXXE.js.map → gcal-MTBSDG34.js.map} +0 -0
- /package/dist/{gdrive-KT6R7EVB.js.map → gcs-KNGRBBET.js.map} +0 -0
- /package/dist/{github-3IFZGW6I.js.map → gdocs-RUIOIRKP.js.map} +0 -0
- /package/dist/{github_ci-CKKF2Y4S.js.map → gdrive-5JB7ZKEP.js.map} +0 -0
- /package/dist/{gmail-HLZIMKQU.js.map → github-CIXBFBVO.js.map} +0 -0
- /package/dist/{gsheets-HF4YPIEF.js.map → github_ci-HR6YOYAO.js.map} +0 -0
- /package/dist/{gslides-EV2JJH7I.js.map → gmail-JHGWTQU5.js.map} +0 -0
- /package/dist/{langfuse-74ZCR6QL.js.map → gsheets-N54JO2RS.js.map} +0 -0
- /package/dist/{linear-XABGTU6E.js.map → gslides-B4VMNLMB.js.map} +0 -0
- /package/dist/{minio-JPNSX2NP.js.map → langfuse-HEUJGDOC.js.map} +0 -0
- /package/dist/{notion-YJOTGH7J.js.map → linear-J4QQ3CA6.js.map} +0 -0
- /package/dist/{oci-R4VYQKGJ.js.map → minio-BXWHJ6K5.js.map} +0 -0
- /package/dist/{opfs-4RWMJBCI.js.map → notion-I5S5SRLO.js.map} +0 -0
- /package/dist/{qingstor-ZWWK2ZGV.js.map → oci-XOPKH4AE.js.map} +0 -0
- /package/dist/{r2-PZAN2YFG.js.map → opfs-36QO72Y5.js.map} +0 -0
- /package/dist/{s3-CSFY3PLT.js.map → qingstor-JKAHLK62.js.map} +0 -0
- /package/dist/{scaleway-BFROPDBB.js.map → r2-L3QXQ76M.js.map} +0 -0
- /package/dist/{seaweedfs-X6THZT26.js.map → s3-LRZJPGHK.js.map} +0 -0
- /package/dist/{slack-O7BTJ4YR.js.map → scaleway-CGNDYNKS.js.map} +0 -0
- /package/dist/{supabase-PHN3MIXW.js.map → seaweedfs-BSQWCBIR.js.map} +0 -0
- /package/dist/{tencent-JGCJEKHV.js.map → slack-62ECSENR.js.map} +0 -0
- /package/dist/{trello-QUDOP3M2.js.map → supabase-J66NXWAF.js.map} +0 -0
- /package/dist/{wasabi-5VMNAFOC.js.map → tencent-AC667LV3.js.map} +0 -0
package/dist/chunk-4YUYQTRN.js
DELETED
|
@@ -1,2334 +0,0 @@
|
|
|
1
|
-
// src/resource/opfs/opfs.ts
|
|
2
|
-
import {
|
|
3
|
-
ResourceName as ResourceName86,
|
|
4
|
-
lstripSlash,
|
|
5
|
-
makeResolveGlob as makeResolveGlob2
|
|
6
|
-
} from "@struktoai/mirage-core";
|
|
7
|
-
|
|
8
|
-
// src/accessor/opfs.ts
|
|
9
|
-
import { Accessor } from "@struktoai/mirage-core";
|
|
10
|
-
var OPFSAccessor = class extends Accessor {
|
|
11
|
-
provider;
|
|
12
|
-
constructor(provider) {
|
|
13
|
-
super();
|
|
14
|
-
this.provider = provider;
|
|
15
|
-
}
|
|
16
|
-
get rootHandle() {
|
|
17
|
-
return this.provider.requireHandle();
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// src/commands/builtin/opfs/index.ts
|
|
22
|
-
import {
|
|
23
|
-
makeFiletypeCommands,
|
|
24
|
-
makeResolveGlob,
|
|
25
|
-
ResourceName as ResourceName73,
|
|
26
|
-
withDefaultProvisions
|
|
27
|
-
} from "@struktoai/mirage-core";
|
|
28
|
-
|
|
29
|
-
// src/core/opfs/constants.ts
|
|
30
|
-
var SCOPE_ERROR = 5e4;
|
|
31
|
-
|
|
32
|
-
// src/core/opfs/read.ts
|
|
33
|
-
import { record, ResourceName } from "@struktoai/mirage-core";
|
|
34
|
-
import { eisdir, enoent } from "@struktoai/mirage-core";
|
|
35
|
-
|
|
36
|
-
// src/core/opfs/utils.ts
|
|
37
|
-
import { norm, parent, gnuBasename } from "@struktoai/mirage-core";
|
|
38
|
-
function splitSegments(virtual) {
|
|
39
|
-
const parts = [];
|
|
40
|
-
for (const seg of virtual.split("/")) {
|
|
41
|
-
if (seg === "" || seg === ".") continue;
|
|
42
|
-
if (seg === "..") {
|
|
43
|
-
if (parts.length === 0) {
|
|
44
|
-
throw new Error(`path escapes root: ${virtual}`);
|
|
45
|
-
}
|
|
46
|
-
parts.pop();
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
parts.push(seg);
|
|
50
|
-
}
|
|
51
|
-
return parts;
|
|
52
|
-
}
|
|
53
|
-
async function resolveDirHandle(root, virtual, options = {}) {
|
|
54
|
-
const segs = splitSegments(virtual);
|
|
55
|
-
let handle = root;
|
|
56
|
-
for (const seg of segs) {
|
|
57
|
-
handle = await handle.getDirectoryHandle(seg, { create: options.create ?? false });
|
|
58
|
-
}
|
|
59
|
-
return handle;
|
|
60
|
-
}
|
|
61
|
-
async function resolveFileHandle(root, virtual, options = {}) {
|
|
62
|
-
const segs = splitSegments(virtual);
|
|
63
|
-
const fileName = segs.pop();
|
|
64
|
-
if (fileName === void 0) {
|
|
65
|
-
throw new Error(`not a file: ${virtual}`);
|
|
66
|
-
}
|
|
67
|
-
let dir = root;
|
|
68
|
-
for (const seg of segs) {
|
|
69
|
-
dir = await dir.getDirectoryHandle(seg, { create: options.create ?? false });
|
|
70
|
-
}
|
|
71
|
-
return dir.getFileHandle(fileName, { create: options.create ?? false });
|
|
72
|
-
}
|
|
73
|
-
async function resolveParentDirHandle(root, virtual, options = {}) {
|
|
74
|
-
const segs = splitSegments(virtual);
|
|
75
|
-
const name = segs.pop();
|
|
76
|
-
if (name === void 0) {
|
|
77
|
-
throw new Error(`no parent directory: ${virtual}`);
|
|
78
|
-
}
|
|
79
|
-
let dir = root;
|
|
80
|
-
for (const seg of segs) {
|
|
81
|
-
dir = await dir.getDirectoryHandle(seg, { create: options.create ?? false });
|
|
82
|
-
}
|
|
83
|
-
return [dir, name];
|
|
84
|
-
}
|
|
85
|
-
function isNotFound(err) {
|
|
86
|
-
if (err instanceof DOMException) {
|
|
87
|
-
return err.name === "NotFoundError";
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
function toWritableChunk(data) {
|
|
92
|
-
const copy2 = new Uint8Array(data.byteLength);
|
|
93
|
-
copy2.set(data);
|
|
94
|
-
return new Blob([copy2]);
|
|
95
|
-
}
|
|
96
|
-
async function* iterEntries(dir) {
|
|
97
|
-
const iter = dir.entries();
|
|
98
|
-
for await (const [name, handle] of iter) {
|
|
99
|
-
yield [name, handle];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/core/opfs/read.ts
|
|
104
|
-
async function read(accessor, path) {
|
|
105
|
-
const root = accessor.rootHandle;
|
|
106
|
-
const start = performance.now();
|
|
107
|
-
const virtual = path.mountPath;
|
|
108
|
-
let handle;
|
|
109
|
-
try {
|
|
110
|
-
handle = await resolveFileHandle(root, virtual, { create: false });
|
|
111
|
-
} catch (err) {
|
|
112
|
-
if (isNotFound(err)) throw enoent(path);
|
|
113
|
-
if (err instanceof DOMException && err.name === "TypeMismatchError") throw eisdir(path);
|
|
114
|
-
throw err;
|
|
115
|
-
}
|
|
116
|
-
const file = await handle.getFile();
|
|
117
|
-
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
118
|
-
record("read", virtual, ResourceName.OPFS, bytes.byteLength, start);
|
|
119
|
-
return bytes;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// src/core/opfs/readdir.ts
|
|
123
|
-
import { mountPrefixOf } from "@struktoai/mirage-core";
|
|
124
|
-
import { enotdir } from "@struktoai/mirage-core";
|
|
125
|
-
async function readdir(accessor, path) {
|
|
126
|
-
const root = accessor.rootHandle;
|
|
127
|
-
const virtual = path.pattern !== null ? path.directory : path.mountPath;
|
|
128
|
-
let dir;
|
|
129
|
-
try {
|
|
130
|
-
dir = await resolveDirHandle(root, virtual, { create: false });
|
|
131
|
-
} catch (err) {
|
|
132
|
-
if (isNotFound(err)) throw enotdir(path);
|
|
133
|
-
if (err instanceof DOMException && err.name === "TypeMismatchError") {
|
|
134
|
-
throw enotdir(path);
|
|
135
|
-
}
|
|
136
|
-
throw err;
|
|
137
|
-
}
|
|
138
|
-
const names = [];
|
|
139
|
-
for await (const [name] of iterEntries(dir)) {
|
|
140
|
-
names.push(name);
|
|
141
|
-
}
|
|
142
|
-
const base = norm(virtual);
|
|
143
|
-
const dirPrefix = base === "/" ? "/" : `${base}/`;
|
|
144
|
-
const mountPrefix = mountPrefixOf(path.virtual, path.resourcePath);
|
|
145
|
-
return names.map((n) => `${mountPrefix}${dirPrefix}${n}`).sort();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// src/core/opfs/stat.ts
|
|
149
|
-
import { FileStat, FileType, guessType } from "@struktoai/mirage-core";
|
|
150
|
-
import { enoent as enoent2 } from "@struktoai/mirage-core";
|
|
151
|
-
async function stat(accessor, p) {
|
|
152
|
-
const root = accessor.rootHandle;
|
|
153
|
-
const virtual = p.mountPath;
|
|
154
|
-
const segs = splitSegments(virtual);
|
|
155
|
-
const last = segs.at(-1);
|
|
156
|
-
if (last === void 0) {
|
|
157
|
-
return new FileStat({
|
|
158
|
-
name: "/",
|
|
159
|
-
size: null,
|
|
160
|
-
modified: null,
|
|
161
|
-
type: FileType.DIRECTORY
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
const name = last;
|
|
165
|
-
let parentDir;
|
|
166
|
-
let entryName;
|
|
167
|
-
try {
|
|
168
|
-
;
|
|
169
|
-
[parentDir, entryName] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
170
|
-
} catch (err) {
|
|
171
|
-
if (isNotFound(err)) throw enoent2(p);
|
|
172
|
-
throw err;
|
|
173
|
-
}
|
|
174
|
-
try {
|
|
175
|
-
const fileHandle = await parentDir.getFileHandle(entryName, { create: false });
|
|
176
|
-
const file = await fileHandle.getFile();
|
|
177
|
-
const modified = new Date(file.lastModified).toISOString();
|
|
178
|
-
return new FileStat({
|
|
179
|
-
name,
|
|
180
|
-
size: file.size,
|
|
181
|
-
modified,
|
|
182
|
-
fingerprint: modified,
|
|
183
|
-
type: guessType(name)
|
|
184
|
-
});
|
|
185
|
-
} catch (err) {
|
|
186
|
-
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
187
|
-
throw err;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
let dirHandle;
|
|
191
|
-
try {
|
|
192
|
-
dirHandle = await resolveDirHandle(root, virtual, { create: false });
|
|
193
|
-
} catch (err) {
|
|
194
|
-
if (isNotFound(err)) throw enoent2(p);
|
|
195
|
-
throw err;
|
|
196
|
-
}
|
|
197
|
-
let latest = 0;
|
|
198
|
-
for await (const [, handle] of iterEntries(dirHandle)) {
|
|
199
|
-
if (handle.kind !== "file") continue;
|
|
200
|
-
const file = await handle.getFile();
|
|
201
|
-
if (file.lastModified > latest) latest = file.lastModified;
|
|
202
|
-
}
|
|
203
|
-
return new FileStat({
|
|
204
|
-
name,
|
|
205
|
-
size: null,
|
|
206
|
-
modified: latest > 0 ? new Date(latest).toISOString() : null,
|
|
207
|
-
type: FileType.DIRECTORY
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// src/commands/builtin/opfs/awk.ts
|
|
212
|
-
import { ResourceName as ResourceName3, awkGeneric, command, specOf } from "@struktoai/mirage-core";
|
|
213
|
-
|
|
214
|
-
// src/core/opfs/stream.ts
|
|
215
|
-
import { recordStream, ResourceName as ResourceName2 } from "@struktoai/mirage-core";
|
|
216
|
-
import { eisdir as eisdir2, enoent as enoent3 } from "@struktoai/mirage-core";
|
|
217
|
-
async function* stream(accessor, path) {
|
|
218
|
-
const root = accessor.rootHandle;
|
|
219
|
-
const virtual = path.mountPath;
|
|
220
|
-
let handle;
|
|
221
|
-
try {
|
|
222
|
-
handle = await resolveFileHandle(root, virtual, { create: false });
|
|
223
|
-
} catch (err) {
|
|
224
|
-
if (isNotFound(err)) throw enoent3(path);
|
|
225
|
-
if (err instanceof DOMException && err.name === "TypeMismatchError") throw eisdir2(path);
|
|
226
|
-
throw err;
|
|
227
|
-
}
|
|
228
|
-
const file = await handle.getFile();
|
|
229
|
-
const rec = recordStream("read", virtual, ResourceName2.OPFS);
|
|
230
|
-
const reader = file.stream().getReader();
|
|
231
|
-
for (; ; ) {
|
|
232
|
-
const { value, done } = await reader.read();
|
|
233
|
-
if (done) break;
|
|
234
|
-
if (rec !== null) rec.bytes += value.byteLength;
|
|
235
|
-
yield value;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// src/commands/builtin/opfs/awk.ts
|
|
240
|
-
var OPFS_AWK = command({
|
|
241
|
-
name: "awk",
|
|
242
|
-
resource: ResourceName3.OPFS,
|
|
243
|
-
spec: specOf("awk"),
|
|
244
|
-
fn: (accessor, paths, texts, opts) => awkGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// src/commands/builtin/opfs/base64_cmd.ts
|
|
248
|
-
import { ResourceName as ResourceName4, command as command2, specOf as specOf2, base64Generic } from "@struktoai/mirage-core";
|
|
249
|
-
var OPFS_BASE64 = command2({
|
|
250
|
-
name: "base64",
|
|
251
|
-
resource: ResourceName4.OPFS,
|
|
252
|
-
spec: specOf2("base64"),
|
|
253
|
-
fn: (accessor, paths, _texts, opts) => base64Generic(paths, opts, (p) => stream(accessor, p))
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
// src/commands/builtin/opfs/basename.ts
|
|
257
|
-
import { ResourceName as ResourceName5, command as command3, specOf as specOf3, basenameFn } from "@struktoai/mirage-core";
|
|
258
|
-
var OPFS_BASENAME = command3({
|
|
259
|
-
name: "basename",
|
|
260
|
-
resource: ResourceName5.OPFS,
|
|
261
|
-
spec: specOf3("basename"),
|
|
262
|
-
fn: basenameFn
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// src/commands/builtin/opfs/cat/cat.ts
|
|
266
|
-
import { ResourceName as ResourceName6, catGeneric, command as command4, concatAggregate, specOf as specOf4 } from "@struktoai/mirage-core";
|
|
267
|
-
var OPFS_CAT = command4({
|
|
268
|
-
name: "cat",
|
|
269
|
-
resource: ResourceName6.OPFS,
|
|
270
|
-
spec: specOf4("cat"),
|
|
271
|
-
fn: (accessor, paths, texts, opts) => catGeneric(
|
|
272
|
-
paths,
|
|
273
|
-
texts,
|
|
274
|
-
opts,
|
|
275
|
-
(p) => stat(accessor, p),
|
|
276
|
-
(p) => stream(accessor, p)
|
|
277
|
-
),
|
|
278
|
-
aggregate: concatAggregate
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
// src/commands/builtin/opfs/cmp.ts
|
|
282
|
-
import { ResourceName as ResourceName7, command as command5, specOf as specOf5, cmpGeneric } from "@struktoai/mirage-core";
|
|
283
|
-
var OPFS_CMP = command5({
|
|
284
|
-
name: "cmp",
|
|
285
|
-
resource: ResourceName7.OPFS,
|
|
286
|
-
spec: specOf5("cmp"),
|
|
287
|
-
fn: (accessor, paths, _texts, opts) => cmpGeneric(paths, opts, (p) => stream(accessor, p))
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
// src/commands/builtin/opfs/column.ts
|
|
291
|
-
import { ResourceName as ResourceName8, command as command6, specOf as specOf6, columnGeneric } from "@struktoai/mirage-core";
|
|
292
|
-
var OPFS_COLUMN = command6({
|
|
293
|
-
name: "column",
|
|
294
|
-
resource: ResourceName8.OPFS,
|
|
295
|
-
spec: specOf6("column"),
|
|
296
|
-
fn: (accessor, paths, _texts, opts) => columnGeneric(paths, opts, (p) => stream(accessor, p))
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// src/commands/builtin/opfs/comm.ts
|
|
300
|
-
import { ResourceName as ResourceName9, command as command7, specOf as specOf7, commGeneric } from "@struktoai/mirage-core";
|
|
301
|
-
var OPFS_COMM = command7({
|
|
302
|
-
name: "comm",
|
|
303
|
-
resource: ResourceName9.OPFS,
|
|
304
|
-
spec: specOf7("comm"),
|
|
305
|
-
fn: (accessor, paths, _texts, opts) => commGeneric(paths, opts, (p) => stream(accessor, p))
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
// src/commands/builtin/opfs/cp.ts
|
|
309
|
-
import {
|
|
310
|
-
IOResult,
|
|
311
|
-
ResourceName as ResourceName10,
|
|
312
|
-
command as command8,
|
|
313
|
-
cpGeneric,
|
|
314
|
-
specOf as specOf8
|
|
315
|
-
} from "@struktoai/mirage-core";
|
|
316
|
-
|
|
317
|
-
// src/core/opfs/copy.ts
|
|
318
|
-
async function copy(accessor, src, dst) {
|
|
319
|
-
const root = accessor.rootHandle;
|
|
320
|
-
let srcHandle;
|
|
321
|
-
try {
|
|
322
|
-
srcHandle = await resolveFileHandle(root, src.mountPath, { create: false });
|
|
323
|
-
} catch (err) {
|
|
324
|
-
if (isNotFound(err)) throw new Error(`file not found: ${src.mountPath}`);
|
|
325
|
-
throw err;
|
|
326
|
-
}
|
|
327
|
-
const file = await srcHandle.getFile();
|
|
328
|
-
const data = new Uint8Array(await file.arrayBuffer());
|
|
329
|
-
const dstHandle = await resolveFileHandle(root, dst.mountPath, { create: true });
|
|
330
|
-
const writable = await dstHandle.createWritable();
|
|
331
|
-
await writable.write(toWritableChunk(data));
|
|
332
|
-
await writable.close();
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// src/core/opfs/find.ts
|
|
336
|
-
import {
|
|
337
|
-
buildTree,
|
|
338
|
-
emitStartPath,
|
|
339
|
-
keep,
|
|
340
|
-
startBasename
|
|
341
|
-
} from "@struktoai/mirage-core";
|
|
342
|
-
async function walk(ctx, dir, current, depth) {
|
|
343
|
-
const opts = ctx.options;
|
|
344
|
-
if (opts.maxDepth !== null && opts.maxDepth !== void 0 && depth > opts.maxDepth) return;
|
|
345
|
-
let iter;
|
|
346
|
-
try {
|
|
347
|
-
iter = iterEntries(dir);
|
|
348
|
-
} catch {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
for await (const [entryName, handle] of iter) {
|
|
352
|
-
const kind = handle.kind === "directory" ? "d" : "f";
|
|
353
|
-
const entryPath = current === "/" ? `/${entryName}` : `${current}/${entryName}`;
|
|
354
|
-
const entryDepth = depth + 1;
|
|
355
|
-
let accept = true;
|
|
356
|
-
if (opts.maxDepth !== null && opts.maxDepth !== void 0 && entryDepth > opts.maxDepth) {
|
|
357
|
-
accept = false;
|
|
358
|
-
}
|
|
359
|
-
let isEmpty = null;
|
|
360
|
-
if (accept && opts.empty === true) {
|
|
361
|
-
try {
|
|
362
|
-
if (kind === "f") {
|
|
363
|
-
isEmpty = (await handle.getFile()).size === 0;
|
|
364
|
-
} else {
|
|
365
|
-
isEmpty = true;
|
|
366
|
-
for await (const _child of iterEntries(handle)) {
|
|
367
|
-
void _child;
|
|
368
|
-
isEmpty = false;
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
} catch {
|
|
373
|
-
isEmpty = null;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (accept && !keep(
|
|
377
|
-
{ key: entryPath, name: entryName, kind, depth: entryDepth, isEmpty },
|
|
378
|
-
ctx.tree,
|
|
379
|
-
opts.minDepth
|
|
380
|
-
)) {
|
|
381
|
-
accept = false;
|
|
382
|
-
}
|
|
383
|
-
if (accept && kind !== "f" && (opts.minSize != null || opts.maxSize != null)) {
|
|
384
|
-
if (opts.minSize != null && opts.minSize > 0) accept = false;
|
|
385
|
-
if (opts.maxSize != null && opts.maxSize < 0) accept = false;
|
|
386
|
-
}
|
|
387
|
-
if (accept && kind === "f" && (opts.minSize !== null || opts.maxSize !== null || opts.mtimeMin !== null || opts.mtimeMax !== null)) {
|
|
388
|
-
try {
|
|
389
|
-
const fh = await dir.getFileHandle(entryName, { create: false });
|
|
390
|
-
const file = await fh.getFile();
|
|
391
|
-
if (opts.minSize !== null && opts.minSize !== void 0 && file.size < opts.minSize)
|
|
392
|
-
accept = false;
|
|
393
|
-
if (opts.maxSize !== null && opts.maxSize !== void 0 && file.size > opts.maxSize)
|
|
394
|
-
accept = false;
|
|
395
|
-
if (accept && (opts.mtimeMin !== void 0 || opts.mtimeMax !== void 0)) {
|
|
396
|
-
const mtime = file.lastModified / 1e3;
|
|
397
|
-
if (opts.mtimeMin !== null && opts.mtimeMin !== void 0 && mtime < opts.mtimeMin)
|
|
398
|
-
accept = false;
|
|
399
|
-
if (opts.mtimeMax !== null && opts.mtimeMax !== void 0 && mtime > opts.mtimeMax)
|
|
400
|
-
accept = false;
|
|
401
|
-
}
|
|
402
|
-
} catch {
|
|
403
|
-
accept = false;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
if (accept) ctx.results.push(entryPath);
|
|
407
|
-
if (kind === "d") {
|
|
408
|
-
try {
|
|
409
|
-
const child = await dir.getDirectoryHandle(entryName, { create: false });
|
|
410
|
-
await walk(ctx, child, entryPath, depth + 1);
|
|
411
|
-
} catch {
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
async function find(accessor, p, options = {}) {
|
|
417
|
-
const root = accessor.rootHandle;
|
|
418
|
-
const virtual = norm(p.mountPath);
|
|
419
|
-
const startName = startBasename(p.virtual);
|
|
420
|
-
const results = [];
|
|
421
|
-
const tree = options.tree ?? buildTree({
|
|
422
|
-
name: options.name,
|
|
423
|
-
iname: options.iname,
|
|
424
|
-
pathPattern: options.pathPattern,
|
|
425
|
-
type: options.type,
|
|
426
|
-
nameExclude: options.nameExclude,
|
|
427
|
-
orNames: options.orNames,
|
|
428
|
-
empty: options.empty
|
|
429
|
-
});
|
|
430
|
-
let dir;
|
|
431
|
-
try {
|
|
432
|
-
dir = await resolveDirHandle(root, virtual, { create: false });
|
|
433
|
-
} catch (err) {
|
|
434
|
-
if (isNotFound(err)) return results;
|
|
435
|
-
throw err;
|
|
436
|
-
}
|
|
437
|
-
if (options.maxDepth == null || options.maxDepth >= 0) {
|
|
438
|
-
let rootEmpty = null;
|
|
439
|
-
if (options.empty === true) {
|
|
440
|
-
rootEmpty = true;
|
|
441
|
-
for await (const _child of iterEntries(dir)) {
|
|
442
|
-
void _child;
|
|
443
|
-
rootEmpty = false;
|
|
444
|
-
break;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
emitStartPath(results, virtual, startName, {
|
|
448
|
-
kind: "d",
|
|
449
|
-
isEmpty: rootEmpty,
|
|
450
|
-
exists: true,
|
|
451
|
-
tree,
|
|
452
|
-
maxDepth: options.maxDepth,
|
|
453
|
-
minDepth: options.minDepth,
|
|
454
|
-
minSize: options.minSize,
|
|
455
|
-
maxSize: options.maxSize
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
await walk({ options, tree, results }, dir, virtual, 0);
|
|
459
|
-
results.sort();
|
|
460
|
-
return results;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// src/commands/builtin/opfs/cp.ts
|
|
464
|
-
function cpCommand(accessor, paths, _texts, opts) {
|
|
465
|
-
if (paths.length < 2) {
|
|
466
|
-
return Promise.resolve([
|
|
467
|
-
null,
|
|
468
|
-
new IOResult({ exitCode: 1, stderr: new TextEncoder().encode("cp: missing operand\n") })
|
|
469
|
-
]);
|
|
470
|
-
}
|
|
471
|
-
const recursive = opts.flags.r === true || opts.flags.R === true || opts.flags.a === true;
|
|
472
|
-
return cpGeneric(
|
|
473
|
-
paths,
|
|
474
|
-
(p) => stat(accessor, p),
|
|
475
|
-
{
|
|
476
|
-
copy: (src, target) => copy(accessor, src, target),
|
|
477
|
-
find: (src, options) => find(accessor, src, options)
|
|
478
|
-
},
|
|
479
|
-
recursive,
|
|
480
|
-
opts.flags.n === true,
|
|
481
|
-
opts.flags.v === true,
|
|
482
|
-
opts.index ?? void 0
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
var OPFS_CP = command8({
|
|
486
|
-
name: "cp",
|
|
487
|
-
resource: ResourceName10.OPFS,
|
|
488
|
-
spec: specOf8("cp"),
|
|
489
|
-
fn: cpCommand,
|
|
490
|
-
write: true
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
// src/commands/builtin/opfs/csplit.ts
|
|
494
|
-
import { ResourceName as ResourceName12, command as command9, specOf as specOf9, csplitGeneric } from "@struktoai/mirage-core";
|
|
495
|
-
|
|
496
|
-
// src/core/opfs/write.ts
|
|
497
|
-
import { record as record2, ResourceName as ResourceName11 } from "@struktoai/mirage-core";
|
|
498
|
-
async function writeBytes(accessor, p, data) {
|
|
499
|
-
const root = accessor.rootHandle;
|
|
500
|
-
const start = performance.now();
|
|
501
|
-
const virtual = p.mountPath;
|
|
502
|
-
const handle = await resolveFileHandle(root, virtual, { create: true });
|
|
503
|
-
const writable = await handle.createWritable();
|
|
504
|
-
await writable.write(toWritableChunk(data));
|
|
505
|
-
await writable.close();
|
|
506
|
-
record2("write", virtual, ResourceName11.OPFS, data.byteLength, start);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// src/commands/builtin/opfs/csplit.ts
|
|
510
|
-
var OPFS_CSPLIT = command9({
|
|
511
|
-
name: "csplit",
|
|
512
|
-
resource: ResourceName12.OPFS,
|
|
513
|
-
spec: specOf9("csplit"),
|
|
514
|
-
fn: (accessor, paths, texts, opts) => csplitGeneric(
|
|
515
|
-
paths,
|
|
516
|
-
texts,
|
|
517
|
-
opts,
|
|
518
|
-
(p) => stream(accessor, p),
|
|
519
|
-
(p, d) => writeBytes(accessor, p, d)
|
|
520
|
-
),
|
|
521
|
-
write: true
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
// src/commands/builtin/opfs/cut/cut.ts
|
|
525
|
-
import { ResourceName as ResourceName13, command as command10, cutGeneric, specOf as specOf10 } from "@struktoai/mirage-core";
|
|
526
|
-
var OPFS_CUT = command10({
|
|
527
|
-
name: "cut",
|
|
528
|
-
resource: ResourceName13.OPFS,
|
|
529
|
-
spec: specOf10("cut"),
|
|
530
|
-
fn: (accessor, paths, _texts, opts) => cutGeneric(paths, opts, (p) => stream(accessor, p))
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
// src/commands/builtin/opfs/diff.ts
|
|
534
|
-
import { ResourceName as ResourceName14, command as command11, diffGeneric, specOf as specOf11 } from "@struktoai/mirage-core";
|
|
535
|
-
var OPFS_DIFF = command11({
|
|
536
|
-
name: "diff",
|
|
537
|
-
resource: ResourceName14.OPFS,
|
|
538
|
-
spec: specOf11("diff"),
|
|
539
|
-
fn: (accessor, paths, _texts, opts) => diffGeneric(
|
|
540
|
-
paths,
|
|
541
|
-
opts,
|
|
542
|
-
(p) => stream(accessor, p),
|
|
543
|
-
(p) => readdir(accessor, p),
|
|
544
|
-
(p) => stat(accessor, p)
|
|
545
|
-
)
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
// src/commands/builtin/opfs/dirname.ts
|
|
549
|
-
import { ResourceName as ResourceName15, command as command12, specOf as specOf12, dirnameFn } from "@struktoai/mirage-core";
|
|
550
|
-
var OPFS_DIRNAME = command12({
|
|
551
|
-
name: "dirname",
|
|
552
|
-
resource: ResourceName15.OPFS,
|
|
553
|
-
spec: specOf12("dirname"),
|
|
554
|
-
fn: dirnameFn
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
// src/commands/builtin/opfs/du.ts
|
|
558
|
-
import { ResourceName as ResourceName16, command as command13, duGeneric, specOf as specOf13 } from "@struktoai/mirage-core";
|
|
559
|
-
|
|
560
|
-
// src/core/opfs/du.ts
|
|
561
|
-
async function walkSizes(dir) {
|
|
562
|
-
let total = 0;
|
|
563
|
-
for await (const [name, handle] of iterEntries(dir)) {
|
|
564
|
-
if (handle.kind === "file") {
|
|
565
|
-
try {
|
|
566
|
-
const fh = await dir.getFileHandle(name, { create: false });
|
|
567
|
-
const file = await fh.getFile();
|
|
568
|
-
total += file.size;
|
|
569
|
-
} catch {
|
|
570
|
-
}
|
|
571
|
-
} else {
|
|
572
|
-
try {
|
|
573
|
-
const child = await dir.getDirectoryHandle(name, { create: false });
|
|
574
|
-
total += await walkSizes(child);
|
|
575
|
-
} catch {
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
return total;
|
|
580
|
-
}
|
|
581
|
-
async function walkAll(dir, currentPath, entries) {
|
|
582
|
-
let total = 0;
|
|
583
|
-
for await (const [name, handle] of iterEntries(dir)) {
|
|
584
|
-
const childPath = currentPath === "/" ? `/${name}` : `${currentPath}/${name}`;
|
|
585
|
-
if (handle.kind === "file") {
|
|
586
|
-
try {
|
|
587
|
-
const fh = await dir.getFileHandle(name, { create: false });
|
|
588
|
-
const file = await fh.getFile();
|
|
589
|
-
entries.push([childPath, file.size]);
|
|
590
|
-
total += file.size;
|
|
591
|
-
} catch {
|
|
592
|
-
}
|
|
593
|
-
} else {
|
|
594
|
-
try {
|
|
595
|
-
const child = await dir.getDirectoryHandle(name, { create: false });
|
|
596
|
-
total += await walkAll(child, childPath, entries);
|
|
597
|
-
} catch {
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
return total;
|
|
602
|
-
}
|
|
603
|
-
async function sizeOfPath(root, virtual) {
|
|
604
|
-
try {
|
|
605
|
-
const [parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
606
|
-
try {
|
|
607
|
-
const fh = await parentDir.getFileHandle(name, { create: false });
|
|
608
|
-
const file = await fh.getFile();
|
|
609
|
-
return file.size;
|
|
610
|
-
} catch (err) {
|
|
611
|
-
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
612
|
-
throw err;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
const dir = await parentDir.getDirectoryHandle(name, { create: false });
|
|
616
|
-
return await walkSizes(dir);
|
|
617
|
-
} catch (err) {
|
|
618
|
-
if (isNotFound(err)) return 0;
|
|
619
|
-
if (err instanceof Error && err.message.startsWith("no parent directory")) {
|
|
620
|
-
try {
|
|
621
|
-
const rootDir = await resolveDirHandle(root, virtual, { create: false });
|
|
622
|
-
return await walkSizes(rootDir);
|
|
623
|
-
} catch {
|
|
624
|
-
return 0;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
throw err;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
async function du(accessor, p) {
|
|
631
|
-
return sizeOfPath(accessor.rootHandle, p.mountPath);
|
|
632
|
-
}
|
|
633
|
-
async function duAll(accessor, p) {
|
|
634
|
-
const root = accessor.rootHandle;
|
|
635
|
-
const virtual = norm(p.mountPath);
|
|
636
|
-
const entries = [];
|
|
637
|
-
try {
|
|
638
|
-
const [parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
639
|
-
try {
|
|
640
|
-
const fh = await parentDir.getFileHandle(name, { create: false });
|
|
641
|
-
const file = await fh.getFile();
|
|
642
|
-
entries.push([virtual, file.size]);
|
|
643
|
-
return [entries, file.size];
|
|
644
|
-
} catch (err) {
|
|
645
|
-
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
646
|
-
throw err;
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
const dir = await parentDir.getDirectoryHandle(name, { create: false });
|
|
650
|
-
const total = await walkAll(dir, virtual, entries);
|
|
651
|
-
entries.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
652
|
-
return [entries, total];
|
|
653
|
-
} catch (err) {
|
|
654
|
-
if (isNotFound(err)) return [entries, 0];
|
|
655
|
-
if (err instanceof Error && err.message.startsWith("no parent directory")) {
|
|
656
|
-
try {
|
|
657
|
-
const rootDir = await resolveDirHandle(root, virtual, { create: false });
|
|
658
|
-
const total = await walkAll(rootDir, virtual, entries);
|
|
659
|
-
entries.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
660
|
-
return [entries, total];
|
|
661
|
-
} catch {
|
|
662
|
-
return [entries, 0];
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
throw err;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
// src/commands/builtin/opfs/du.ts
|
|
670
|
-
var OPFS_DU = command13({
|
|
671
|
-
name: "du",
|
|
672
|
-
resource: ResourceName16.OPFS,
|
|
673
|
-
spec: specOf13("du"),
|
|
674
|
-
fn: (accessor, paths, _texts, opts) => duGeneric(
|
|
675
|
-
paths,
|
|
676
|
-
opts,
|
|
677
|
-
(p) => du(accessor, p),
|
|
678
|
-
(p) => duAll(accessor, p)
|
|
679
|
-
)
|
|
680
|
-
});
|
|
681
|
-
|
|
682
|
-
// src/commands/builtin/opfs/expand.ts
|
|
683
|
-
import { ResourceName as ResourceName17, command as command14, specOf as specOf14, expandGeneric } from "@struktoai/mirage-core";
|
|
684
|
-
var OPFS_EXPAND = command14({
|
|
685
|
-
name: "expand",
|
|
686
|
-
resource: ResourceName17.OPFS,
|
|
687
|
-
spec: specOf14("expand"),
|
|
688
|
-
fn: (accessor, paths, _texts, opts) => expandGeneric(paths, opts, (p) => stream(accessor, p))
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
// src/commands/builtin/opfs/file/file.ts
|
|
692
|
-
import { ResourceName as ResourceName18, command as command15, fileGeneric, specOf as specOf15 } from "@struktoai/mirage-core";
|
|
693
|
-
var OPFS_FILE = command15({
|
|
694
|
-
name: "file",
|
|
695
|
-
resource: ResourceName18.OPFS,
|
|
696
|
-
spec: specOf15("file"),
|
|
697
|
-
fn: (accessor, paths, _texts, opts) => fileGeneric(
|
|
698
|
-
paths,
|
|
699
|
-
opts,
|
|
700
|
-
(p) => stat(accessor, p),
|
|
701
|
-
(p) => read(accessor, p)
|
|
702
|
-
)
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
// src/commands/builtin/opfs/find.ts
|
|
706
|
-
import { ResourceName as ResourceName19, command as command16, findGeneric, specOf as specOf16 } from "@struktoai/mirage-core";
|
|
707
|
-
var OPFS_FIND = command16({
|
|
708
|
-
name: "find",
|
|
709
|
-
resource: ResourceName19.OPFS,
|
|
710
|
-
spec: specOf16("find"),
|
|
711
|
-
fn: (accessor, paths, texts, opts) => findGeneric(paths, texts, opts, (root, options) => find(accessor, root, options))
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
// src/commands/builtin/opfs/fmt.ts
|
|
715
|
-
import {
|
|
716
|
-
ResourceName as ResourceName20,
|
|
717
|
-
command as command17,
|
|
718
|
-
fmtGeneric,
|
|
719
|
-
specOf as specOf17
|
|
720
|
-
} from "@struktoai/mirage-core";
|
|
721
|
-
async function fmtCommand(accessor, paths, _texts, opts) {
|
|
722
|
-
return fmtGeneric(paths, opts, (p) => stream(accessor, p));
|
|
723
|
-
}
|
|
724
|
-
var OPFS_FMT = command17({
|
|
725
|
-
name: "fmt",
|
|
726
|
-
resource: ResourceName20.OPFS,
|
|
727
|
-
spec: specOf17("fmt"),
|
|
728
|
-
fn: fmtCommand
|
|
729
|
-
});
|
|
730
|
-
|
|
731
|
-
// src/commands/builtin/opfs/fold.ts
|
|
732
|
-
import { ResourceName as ResourceName21, command as command18, specOf as specOf18, foldGeneric } from "@struktoai/mirage-core";
|
|
733
|
-
var OPFS_FOLD = command18({
|
|
734
|
-
name: "fold",
|
|
735
|
-
resource: ResourceName21.OPFS,
|
|
736
|
-
spec: specOf18("fold"),
|
|
737
|
-
fn: (accessor, paths, _texts, opts) => foldGeneric(paths, opts, (p) => stream(accessor, p))
|
|
738
|
-
});
|
|
739
|
-
|
|
740
|
-
// src/commands/builtin/opfs/grep/grep.ts
|
|
741
|
-
import { ResourceName as ResourceName22, command as command19, grepGeneric, prefixAggregate, specOf as specOf19 } from "@struktoai/mirage-core";
|
|
742
|
-
var OPFS_GREP = command19({
|
|
743
|
-
name: "grep",
|
|
744
|
-
resource: ResourceName22.OPFS,
|
|
745
|
-
spec: specOf19("grep"),
|
|
746
|
-
fn: (accessor, paths, texts, opts) => grepGeneric(
|
|
747
|
-
"grep",
|
|
748
|
-
paths,
|
|
749
|
-
texts,
|
|
750
|
-
opts,
|
|
751
|
-
(p) => stat(accessor, p),
|
|
752
|
-
(p) => readdir(accessor, p),
|
|
753
|
-
(p) => stream(accessor, p)
|
|
754
|
-
),
|
|
755
|
-
aggregate: prefixAggregate
|
|
756
|
-
});
|
|
757
|
-
|
|
758
|
-
// src/commands/builtin/opfs/gunzip.ts
|
|
759
|
-
import { ResourceName as ResourceName23, command as command20, specOf as specOf20, gunzipGeneric } from "@struktoai/mirage-core";
|
|
760
|
-
|
|
761
|
-
// src/core/opfs/unlink.ts
|
|
762
|
-
async function unlink(accessor, path) {
|
|
763
|
-
const root = accessor.rootHandle;
|
|
764
|
-
const virtual = path.mountPath;
|
|
765
|
-
let parentDir;
|
|
766
|
-
let name;
|
|
767
|
-
try {
|
|
768
|
-
;
|
|
769
|
-
[parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
770
|
-
} catch (err) {
|
|
771
|
-
if (isNotFound(err)) return;
|
|
772
|
-
if (err instanceof Error && err.message.startsWith("no parent directory")) return;
|
|
773
|
-
throw err;
|
|
774
|
-
}
|
|
775
|
-
try {
|
|
776
|
-
await parentDir.removeEntry(name);
|
|
777
|
-
} catch (err) {
|
|
778
|
-
if (isNotFound(err)) return;
|
|
779
|
-
throw err;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
// src/commands/builtin/opfs/gunzip.ts
|
|
784
|
-
var OPFS_GUNZIP = command20({
|
|
785
|
-
name: "gunzip",
|
|
786
|
-
resource: ResourceName23.OPFS,
|
|
787
|
-
spec: specOf20("gunzip"),
|
|
788
|
-
fn: (accessor, paths, _texts, opts) => gunzipGeneric(
|
|
789
|
-
paths,
|
|
790
|
-
opts,
|
|
791
|
-
(p) => stream(accessor, p),
|
|
792
|
-
(p, d) => writeBytes(accessor, p, d),
|
|
793
|
-
(p) => unlink(accessor, p)
|
|
794
|
-
),
|
|
795
|
-
write: true
|
|
796
|
-
});
|
|
797
|
-
|
|
798
|
-
// src/commands/builtin/opfs/gzip.ts
|
|
799
|
-
import { ResourceName as ResourceName24, command as command21, specOf as specOf21, gzipGeneric } from "@struktoai/mirage-core";
|
|
800
|
-
var OPFS_GZIP = command21({
|
|
801
|
-
name: "gzip",
|
|
802
|
-
resource: ResourceName24.OPFS,
|
|
803
|
-
spec: specOf21("gzip"),
|
|
804
|
-
fn: (accessor, paths, _texts, opts) => gzipGeneric(
|
|
805
|
-
paths,
|
|
806
|
-
opts,
|
|
807
|
-
(p) => stream(accessor, p),
|
|
808
|
-
(p, d) => writeBytes(accessor, p, d),
|
|
809
|
-
(p) => unlink(accessor, p)
|
|
810
|
-
),
|
|
811
|
-
write: true
|
|
812
|
-
});
|
|
813
|
-
|
|
814
|
-
// src/commands/builtin/opfs/head/head.ts
|
|
815
|
-
import { ResourceName as ResourceName25, command as command22, headGeneric, headerAggregate, specOf as specOf22 } from "@struktoai/mirage-core";
|
|
816
|
-
var OPFS_HEAD = command22({
|
|
817
|
-
name: "head",
|
|
818
|
-
resource: ResourceName25.OPFS,
|
|
819
|
-
spec: specOf22("head"),
|
|
820
|
-
fn: (accessor, paths, texts, opts) => headGeneric(
|
|
821
|
-
paths,
|
|
822
|
-
texts,
|
|
823
|
-
opts,
|
|
824
|
-
(p) => stat(accessor, p),
|
|
825
|
-
(p) => stream(accessor, p)
|
|
826
|
-
),
|
|
827
|
-
aggregate: headerAggregate
|
|
828
|
-
});
|
|
829
|
-
|
|
830
|
-
// src/commands/builtin/opfs/iconv.ts
|
|
831
|
-
import { ResourceName as ResourceName26, command as command23, specOf as specOf23, iconvGeneric } from "@struktoai/mirage-core";
|
|
832
|
-
var OPFS_ICONV = command23({
|
|
833
|
-
name: "iconv",
|
|
834
|
-
resource: ResourceName26.OPFS,
|
|
835
|
-
spec: specOf23("iconv"),
|
|
836
|
-
fn: (accessor, paths, _texts, opts) => iconvGeneric(
|
|
837
|
-
paths,
|
|
838
|
-
opts,
|
|
839
|
-
(p) => stream(accessor, p),
|
|
840
|
-
(p, d) => writeBytes(accessor, p, d)
|
|
841
|
-
),
|
|
842
|
-
write: true
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
// src/commands/builtin/opfs/join.ts
|
|
846
|
-
import { ResourceName as ResourceName27, command as command24, specOf as specOf24, joinGeneric } from "@struktoai/mirage-core";
|
|
847
|
-
var OPFS_JOIN = command24({
|
|
848
|
-
name: "join",
|
|
849
|
-
resource: ResourceName27.OPFS,
|
|
850
|
-
spec: specOf24("join"),
|
|
851
|
-
fn: (accessor, paths, _texts, opts) => joinGeneric(paths, opts, (p) => stream(accessor, p))
|
|
852
|
-
});
|
|
853
|
-
|
|
854
|
-
// src/commands/builtin/opfs/jq.ts
|
|
855
|
-
import { ResourceName as ResourceName28, command as command25, jqGeneric, specOf as specOf25 } from "@struktoai/mirage-core";
|
|
856
|
-
var OPFS_JQ = command25({
|
|
857
|
-
name: "jq",
|
|
858
|
-
resource: ResourceName28.OPFS,
|
|
859
|
-
spec: specOf25("jq"),
|
|
860
|
-
fn: (accessor, paths, texts, opts) => jqGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
861
|
-
});
|
|
862
|
-
|
|
863
|
-
// src/commands/builtin/opfs/ln.ts
|
|
864
|
-
import {
|
|
865
|
-
IOResult as IOResult2,
|
|
866
|
-
ResourceName as ResourceName29,
|
|
867
|
-
command as command26,
|
|
868
|
-
materialize,
|
|
869
|
-
specOf as specOf26
|
|
870
|
-
} from "@struktoai/mirage-core";
|
|
871
|
-
|
|
872
|
-
// src/core/opfs/exists.ts
|
|
873
|
-
async function exists(accessor, path) {
|
|
874
|
-
const root = accessor.rootHandle;
|
|
875
|
-
const virtual = path.mountPath;
|
|
876
|
-
if (virtual === "/" || virtual === "") return true;
|
|
877
|
-
try {
|
|
878
|
-
const [parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
879
|
-
try {
|
|
880
|
-
await parentDir.getFileHandle(name, { create: false });
|
|
881
|
-
return true;
|
|
882
|
-
} catch (err) {
|
|
883
|
-
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
884
|
-
throw err;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
try {
|
|
888
|
-
await parentDir.getDirectoryHandle(name, { create: false });
|
|
889
|
-
return true;
|
|
890
|
-
} catch (err) {
|
|
891
|
-
if (isNotFound(err) || err instanceof DOMException && err.name === "TypeMismatchError") {
|
|
892
|
-
return false;
|
|
893
|
-
}
|
|
894
|
-
throw err;
|
|
895
|
-
}
|
|
896
|
-
} catch (err) {
|
|
897
|
-
if (isNotFound(err)) return false;
|
|
898
|
-
if (err instanceof Error && err.message.startsWith("path escapes root")) return false;
|
|
899
|
-
if (err instanceof Error && err.message.startsWith("no parent directory")) {
|
|
900
|
-
try {
|
|
901
|
-
await resolveDirHandle(root, virtual, { create: false });
|
|
902
|
-
return true;
|
|
903
|
-
} catch {
|
|
904
|
-
return false;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
throw err;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
// src/commands/builtin/opfs/ln.ts
|
|
912
|
-
var ENC = new TextEncoder();
|
|
913
|
-
async function lnCommand(accessor, paths, texts, opts) {
|
|
914
|
-
if (paths.length < 2) {
|
|
915
|
-
return [
|
|
916
|
-
null,
|
|
917
|
-
new IOResult2({ exitCode: 1, stderr: ENC.encode("ln: usage: ln [-s] [-f] source dest\n") })
|
|
918
|
-
];
|
|
919
|
-
}
|
|
920
|
-
const source = paths[0];
|
|
921
|
-
const dest = paths[1];
|
|
922
|
-
if (source === void 0 || dest === void 0) return [null, new IOResult2()];
|
|
923
|
-
if (opts.flags.n === true && await exists(accessor, dest)) {
|
|
924
|
-
return [null, new IOResult2()];
|
|
925
|
-
}
|
|
926
|
-
const data = await materialize(stream(accessor, source));
|
|
927
|
-
await writeBytes(accessor, dest, data);
|
|
928
|
-
const out = opts.flags.v === true ? ENC.encode(`'${source.virtual}' -> '${dest.virtual}'
|
|
929
|
-
`) : null;
|
|
930
|
-
return [out, new IOResult2({ writes: { [dest.mountPath]: data } })];
|
|
931
|
-
}
|
|
932
|
-
var OPFS_LN = command26({
|
|
933
|
-
name: "ln",
|
|
934
|
-
resource: ResourceName29.OPFS,
|
|
935
|
-
spec: specOf26("ln"),
|
|
936
|
-
fn: lnCommand,
|
|
937
|
-
write: true
|
|
938
|
-
});
|
|
939
|
-
|
|
940
|
-
// src/commands/builtin/opfs/look.ts
|
|
941
|
-
import { ResourceName as ResourceName30, command as command27, specOf as specOf27, lookGeneric } from "@struktoai/mirage-core";
|
|
942
|
-
var OPFS_LOOK = command27({
|
|
943
|
-
name: "look",
|
|
944
|
-
resource: ResourceName30.OPFS,
|
|
945
|
-
spec: specOf27("look"),
|
|
946
|
-
fn: (accessor, paths, texts, opts) => lookGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
947
|
-
});
|
|
948
|
-
|
|
949
|
-
// src/commands/builtin/opfs/ls/ls.ts
|
|
950
|
-
import { ResourceName as ResourceName31, command as command28, lsGeneric, specOf as specOf28 } from "@struktoai/mirage-core";
|
|
951
|
-
var OPFS_LS = command28({
|
|
952
|
-
name: "ls",
|
|
953
|
-
resource: ResourceName31.OPFS,
|
|
954
|
-
spec: specOf28("ls"),
|
|
955
|
-
fn: (accessor, paths, _texts, opts) => {
|
|
956
|
-
const overlay = opts.statOverlay;
|
|
957
|
-
const stat2 = overlay !== void 0 ? async (p) => overlay(p.virtual, await stat(accessor, p)) : (p) => stat(accessor, p);
|
|
958
|
-
return lsGeneric(paths, opts, (p) => readdir(accessor, p), stat2);
|
|
959
|
-
}
|
|
960
|
-
});
|
|
961
|
-
|
|
962
|
-
// src/commands/builtin/opfs/md5.ts
|
|
963
|
-
import { ResourceName as ResourceName32, command as command29, specOf as specOf29, md5Generic } from "@struktoai/mirage-core";
|
|
964
|
-
var OPFS_MD5 = command29({
|
|
965
|
-
name: "md5",
|
|
966
|
-
resource: ResourceName32.OPFS,
|
|
967
|
-
spec: specOf29("md5"),
|
|
968
|
-
fn: (accessor, paths, _texts, opts) => md5Generic(paths, opts, (p) => stream(accessor, p))
|
|
969
|
-
});
|
|
970
|
-
|
|
971
|
-
// src/commands/builtin/opfs/md5sum.ts
|
|
972
|
-
import { ResourceName as ResourceName33, command as command30, md5sumGeneric, specOf as specOf30 } from "@struktoai/mirage-core";
|
|
973
|
-
var OPFS_MD5SUM = command30({
|
|
974
|
-
name: "md5sum",
|
|
975
|
-
resource: ResourceName33.OPFS,
|
|
976
|
-
spec: specOf30("md5sum"),
|
|
977
|
-
fn: (accessor, paths, _texts, opts) => md5sumGeneric(paths, opts, (p) => stream(accessor, p))
|
|
978
|
-
});
|
|
979
|
-
|
|
980
|
-
// src/commands/builtin/opfs/mkdir.ts
|
|
981
|
-
import {
|
|
982
|
-
IOResult as IOResult3,
|
|
983
|
-
ResourceName as ResourceName34,
|
|
984
|
-
command as command31,
|
|
985
|
-
formatRecords,
|
|
986
|
-
specOf as specOf31
|
|
987
|
-
} from "@struktoai/mirage-core";
|
|
988
|
-
|
|
989
|
-
// src/core/opfs/mkdir.ts
|
|
990
|
-
import { invalidateAfterWrite, invalidateAncestors } from "@struktoai/mirage-core";
|
|
991
|
-
async function mkdir(accessor, path, parents = false) {
|
|
992
|
-
const root = accessor.rootHandle;
|
|
993
|
-
const virtual = path.mountPath;
|
|
994
|
-
const segs = splitSegments(virtual);
|
|
995
|
-
if (segs.length === 0) return;
|
|
996
|
-
if (parents) {
|
|
997
|
-
await resolveDirHandle(root, virtual, { create: true });
|
|
998
|
-
await invalidateAfterWrite(path);
|
|
999
|
-
await invalidateAncestors(path);
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
|
-
let parentDir;
|
|
1003
|
-
let name;
|
|
1004
|
-
try {
|
|
1005
|
-
;
|
|
1006
|
-
[parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
1007
|
-
} catch (err) {
|
|
1008
|
-
if (isNotFound(err)) {
|
|
1009
|
-
throw new Error(`parent directory does not exist: ${virtual}`);
|
|
1010
|
-
}
|
|
1011
|
-
throw err;
|
|
1012
|
-
}
|
|
1013
|
-
try {
|
|
1014
|
-
await parentDir.getDirectoryHandle(name, { create: false });
|
|
1015
|
-
return;
|
|
1016
|
-
} catch (err) {
|
|
1017
|
-
if (!isNotFound(err)) {
|
|
1018
|
-
if (err instanceof DOMException && err.name === "TypeMismatchError") {
|
|
1019
|
-
throw new Error(`path exists and is not a directory: ${virtual}`);
|
|
1020
|
-
}
|
|
1021
|
-
throw err;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
await parentDir.getDirectoryHandle(name, { create: true });
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
// src/commands/builtin/opfs/mkdir.ts
|
|
1028
|
-
async function mkdirCommand(accessor, paths, texts, opts) {
|
|
1029
|
-
const parents = opts.flags.p === true;
|
|
1030
|
-
const verbose = opts.flags.v === true;
|
|
1031
|
-
if (paths.length === 0) {
|
|
1032
|
-
return [
|
|
1033
|
-
null,
|
|
1034
|
-
new IOResult3({
|
|
1035
|
-
exitCode: 1,
|
|
1036
|
-
stderr: new TextEncoder().encode("mkdir: missing operand\n")
|
|
1037
|
-
})
|
|
1038
|
-
];
|
|
1039
|
-
}
|
|
1040
|
-
const lines = [];
|
|
1041
|
-
for (const p of paths) {
|
|
1042
|
-
await mkdir(accessor, p, parents);
|
|
1043
|
-
if (verbose) lines.push(`mkdir: created directory '${p.virtual.replace(/\/+$/, "") || "/"}'`);
|
|
1044
|
-
}
|
|
1045
|
-
const output = verbose && lines.length > 0 ? formatRecords(lines) : null;
|
|
1046
|
-
return [output, new IOResult3()];
|
|
1047
|
-
}
|
|
1048
|
-
var OPFS_MKDIR = command31({
|
|
1049
|
-
name: "mkdir",
|
|
1050
|
-
resource: ResourceName34.OPFS,
|
|
1051
|
-
spec: specOf31("mkdir"),
|
|
1052
|
-
fn: mkdirCommand,
|
|
1053
|
-
write: true
|
|
1054
|
-
});
|
|
1055
|
-
|
|
1056
|
-
// src/commands/builtin/opfs/mktemp.ts
|
|
1057
|
-
import { ResourceName as ResourceName35, command as command32, mktempGeneric, specOf as specOf32 } from "@struktoai/mirage-core";
|
|
1058
|
-
var OPFS_MKTEMP = command32({
|
|
1059
|
-
name: "mktemp",
|
|
1060
|
-
resource: ResourceName35.OPFS,
|
|
1061
|
-
spec: specOf32("mktemp"),
|
|
1062
|
-
fn: (accessor, _paths, texts, opts) => mktempGeneric(
|
|
1063
|
-
texts,
|
|
1064
|
-
opts,
|
|
1065
|
-
(p, parents) => mkdir(accessor, p, parents),
|
|
1066
|
-
(p, d) => writeBytes(accessor, p, d)
|
|
1067
|
-
),
|
|
1068
|
-
write: true
|
|
1069
|
-
});
|
|
1070
|
-
|
|
1071
|
-
// src/commands/builtin/opfs/mv.ts
|
|
1072
|
-
import {
|
|
1073
|
-
IOResult as IOResult4,
|
|
1074
|
-
ResourceName as ResourceName36,
|
|
1075
|
-
command as command33,
|
|
1076
|
-
mvGeneric,
|
|
1077
|
-
specOf as specOf33
|
|
1078
|
-
} from "@struktoai/mirage-core";
|
|
1079
|
-
|
|
1080
|
-
// src/core/opfs/rename.ts
|
|
1081
|
-
async function copyDirRecursive(root, srcPath, dstPath) {
|
|
1082
|
-
const srcDir = await resolveDirHandle(root, srcPath, { create: false });
|
|
1083
|
-
const dstDir = await resolveDirHandle(root, dstPath, { create: true });
|
|
1084
|
-
for await (const [name, handle] of iterEntries(srcDir)) {
|
|
1085
|
-
if (handle.kind === "file") {
|
|
1086
|
-
const srcFile = await srcDir.getFileHandle(name, { create: false });
|
|
1087
|
-
const file = await srcFile.getFile();
|
|
1088
|
-
const data = new Uint8Array(await file.arrayBuffer());
|
|
1089
|
-
const dstFile = await dstDir.getFileHandle(name, { create: true });
|
|
1090
|
-
const writable = await dstFile.createWritable();
|
|
1091
|
-
await writable.write(toWritableChunk(data));
|
|
1092
|
-
await writable.close();
|
|
1093
|
-
} else {
|
|
1094
|
-
await copyDirRecursive(root, `${srcPath}/${name}`, `${dstPath}/${name}`);
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
async function rename(accessor, src, dst) {
|
|
1099
|
-
const root = accessor.rootHandle;
|
|
1100
|
-
const srcPath = src.mountPath;
|
|
1101
|
-
const dstPath = dst.mountPath;
|
|
1102
|
-
let srcParent;
|
|
1103
|
-
let srcName;
|
|
1104
|
-
try {
|
|
1105
|
-
;
|
|
1106
|
-
[srcParent, srcName] = await resolveParentDirHandle(root, srcPath, { create: false });
|
|
1107
|
-
} catch (err) {
|
|
1108
|
-
if (isNotFound(err)) throw new Error(`file or directory not found: ${srcPath}`);
|
|
1109
|
-
throw err;
|
|
1110
|
-
}
|
|
1111
|
-
let isFile = false;
|
|
1112
|
-
try {
|
|
1113
|
-
await srcParent.getFileHandle(srcName, { create: false });
|
|
1114
|
-
isFile = true;
|
|
1115
|
-
} catch (err) {
|
|
1116
|
-
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
1117
|
-
throw err;
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
if (!isFile) {
|
|
1121
|
-
try {
|
|
1122
|
-
await srcParent.getDirectoryHandle(srcName, { create: false });
|
|
1123
|
-
} catch (err) {
|
|
1124
|
-
if (isNotFound(err)) throw new Error(`file or directory not found: ${srcPath}`);
|
|
1125
|
-
throw err;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
if (isFile) {
|
|
1129
|
-
const srcFile = await resolveFileHandle(root, srcPath, { create: false });
|
|
1130
|
-
const file = await srcFile.getFile();
|
|
1131
|
-
const data = new Uint8Array(await file.arrayBuffer());
|
|
1132
|
-
const dstFile = await resolveFileHandle(root, dstPath, { create: true });
|
|
1133
|
-
const writable = await dstFile.createWritable();
|
|
1134
|
-
await writable.write(toWritableChunk(data));
|
|
1135
|
-
await writable.close();
|
|
1136
|
-
await srcParent.removeEntry(srcName);
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
await copyDirRecursive(root, srcPath, dstPath);
|
|
1140
|
-
await srcParent.removeEntry(srcName, { recursive: true });
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// src/commands/builtin/opfs/mv.ts
|
|
1144
|
-
function mvCommand(accessor, paths, _texts, opts) {
|
|
1145
|
-
if (paths.length < 2) {
|
|
1146
|
-
return Promise.resolve([
|
|
1147
|
-
null,
|
|
1148
|
-
new IOResult4({ exitCode: 1, stderr: new TextEncoder().encode("mv: missing operand\n") })
|
|
1149
|
-
]);
|
|
1150
|
-
}
|
|
1151
|
-
return mvGeneric(
|
|
1152
|
-
paths,
|
|
1153
|
-
(p) => stat(accessor, p),
|
|
1154
|
-
{ rename: (src, target) => rename(accessor, src, target) },
|
|
1155
|
-
opts.flags.n === true,
|
|
1156
|
-
opts.flags.v === true,
|
|
1157
|
-
opts.index ?? void 0
|
|
1158
|
-
);
|
|
1159
|
-
}
|
|
1160
|
-
var OPFS_MV = command33({
|
|
1161
|
-
name: "mv",
|
|
1162
|
-
resource: ResourceName36.OPFS,
|
|
1163
|
-
spec: specOf33("mv"),
|
|
1164
|
-
fn: mvCommand,
|
|
1165
|
-
write: true
|
|
1166
|
-
});
|
|
1167
|
-
|
|
1168
|
-
// src/commands/builtin/opfs/nl.ts
|
|
1169
|
-
import { ResourceName as ResourceName37, command as command34, specOf as specOf34, nlGeneric } from "@struktoai/mirage-core";
|
|
1170
|
-
var OPFS_NL = command34({
|
|
1171
|
-
name: "nl",
|
|
1172
|
-
resource: ResourceName37.OPFS,
|
|
1173
|
-
spec: specOf34("nl"),
|
|
1174
|
-
fn: (accessor, paths, _texts, opts) => nlGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1175
|
-
});
|
|
1176
|
-
|
|
1177
|
-
// src/commands/builtin/opfs/paste.ts
|
|
1178
|
-
import { ResourceName as ResourceName38, command as command35, specOf as specOf35, pasteGeneric } from "@struktoai/mirage-core";
|
|
1179
|
-
var OPFS_PASTE = command35({
|
|
1180
|
-
name: "paste",
|
|
1181
|
-
resource: ResourceName38.OPFS,
|
|
1182
|
-
spec: specOf35("paste"),
|
|
1183
|
-
fn: (accessor, paths, _texts, opts) => pasteGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1184
|
-
});
|
|
1185
|
-
|
|
1186
|
-
// src/commands/builtin/opfs/patch.ts
|
|
1187
|
-
import { ResourceName as ResourceName39, command as command36, specOf as specOf36, patchGeneric } from "@struktoai/mirage-core";
|
|
1188
|
-
var OPFS_PATCH = command36({
|
|
1189
|
-
name: "patch",
|
|
1190
|
-
resource: ResourceName39.OPFS,
|
|
1191
|
-
spec: specOf36("patch"),
|
|
1192
|
-
fn: (accessor, paths, _texts, opts) => patchGeneric(
|
|
1193
|
-
paths,
|
|
1194
|
-
opts,
|
|
1195
|
-
(p) => stream(accessor, p),
|
|
1196
|
-
(p, d) => writeBytes(accessor, p, d)
|
|
1197
|
-
),
|
|
1198
|
-
write: true
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
// src/commands/builtin/opfs/readlink.ts
|
|
1202
|
-
import {
|
|
1203
|
-
ResourceName as ResourceName40,
|
|
1204
|
-
command as command37,
|
|
1205
|
-
readlinkGeneric,
|
|
1206
|
-
specOf as specOf37
|
|
1207
|
-
} from "@struktoai/mirage-core";
|
|
1208
|
-
var OPFS_READLINK = command37({
|
|
1209
|
-
name: "readlink",
|
|
1210
|
-
resource: ResourceName40.OPFS,
|
|
1211
|
-
spec: specOf37("readlink"),
|
|
1212
|
-
fn: (_accessor, paths, texts, opts) => readlinkGeneric(paths, texts, opts)
|
|
1213
|
-
});
|
|
1214
|
-
|
|
1215
|
-
// src/commands/builtin/opfs/realpath.ts
|
|
1216
|
-
import { ResourceName as ResourceName41, command as command38, realpathGeneric, specOf as specOf38 } from "@struktoai/mirage-core";
|
|
1217
|
-
var OPFS_REALPATH = command38({
|
|
1218
|
-
name: "realpath",
|
|
1219
|
-
resource: ResourceName41.OPFS,
|
|
1220
|
-
spec: specOf38("realpath"),
|
|
1221
|
-
fn: (accessor, paths, texts, opts) => realpathGeneric(paths, texts, opts, (p) => stat(accessor, p))
|
|
1222
|
-
});
|
|
1223
|
-
|
|
1224
|
-
// src/commands/builtin/opfs/rev.ts
|
|
1225
|
-
import { ResourceName as ResourceName42, command as command39, specOf as specOf39, revGeneric } from "@struktoai/mirage-core";
|
|
1226
|
-
var OPFS_REV = command39({
|
|
1227
|
-
name: "rev",
|
|
1228
|
-
resource: ResourceName42.OPFS,
|
|
1229
|
-
spec: specOf39("rev"),
|
|
1230
|
-
fn: (accessor, paths, _texts, opts) => revGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1231
|
-
});
|
|
1232
|
-
|
|
1233
|
-
// src/commands/builtin/opfs/rg.ts
|
|
1234
|
-
import { ResourceName as ResourceName43, command as command40, rgGeneric, specOf as specOf40 } from "@struktoai/mirage-core";
|
|
1235
|
-
var OPFS_RG = command40({
|
|
1236
|
-
name: "rg",
|
|
1237
|
-
resource: ResourceName43.OPFS,
|
|
1238
|
-
spec: specOf40("rg"),
|
|
1239
|
-
fn: (accessor, paths, texts, opts) => rgGeneric(
|
|
1240
|
-
paths,
|
|
1241
|
-
texts,
|
|
1242
|
-
opts,
|
|
1243
|
-
(p) => stat(accessor, p),
|
|
1244
|
-
(p) => readdir(accessor, p),
|
|
1245
|
-
(p) => stream(accessor, p)
|
|
1246
|
-
)
|
|
1247
|
-
});
|
|
1248
|
-
|
|
1249
|
-
// src/commands/builtin/opfs/rm.ts
|
|
1250
|
-
import {
|
|
1251
|
-
FileType as FileType2,
|
|
1252
|
-
IOResult as IOResult5,
|
|
1253
|
-
ResourceName as ResourceName44,
|
|
1254
|
-
command as command41,
|
|
1255
|
-
cpWalk,
|
|
1256
|
-
formatRecords as formatRecords2,
|
|
1257
|
-
removalLines,
|
|
1258
|
-
specOf as specOf41
|
|
1259
|
-
} from "@struktoai/mirage-core";
|
|
1260
|
-
|
|
1261
|
-
// src/core/opfs/rmdir.ts
|
|
1262
|
-
async function rmdir(accessor, path) {
|
|
1263
|
-
const root = accessor.rootHandle;
|
|
1264
|
-
const virtual = path.mountPath;
|
|
1265
|
-
let parentDir;
|
|
1266
|
-
let name;
|
|
1267
|
-
try {
|
|
1268
|
-
;
|
|
1269
|
-
[parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
1270
|
-
} catch (err) {
|
|
1271
|
-
if (isNotFound(err)) return;
|
|
1272
|
-
if (err instanceof Error && err.message.startsWith("no parent directory")) return;
|
|
1273
|
-
throw err;
|
|
1274
|
-
}
|
|
1275
|
-
try {
|
|
1276
|
-
await parentDir.removeEntry(name, { recursive: false });
|
|
1277
|
-
} catch (err) {
|
|
1278
|
-
if (isNotFound(err)) return;
|
|
1279
|
-
throw err;
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
// src/core/opfs/rm.ts
|
|
1284
|
-
async function rmR(accessor, path) {
|
|
1285
|
-
const root = accessor.rootHandle;
|
|
1286
|
-
const virtual = path.mountPath;
|
|
1287
|
-
let parentDir;
|
|
1288
|
-
let name;
|
|
1289
|
-
try {
|
|
1290
|
-
;
|
|
1291
|
-
[parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
1292
|
-
} catch (err) {
|
|
1293
|
-
if (isNotFound(err)) return;
|
|
1294
|
-
if (err instanceof Error && err.message.startsWith("no parent directory")) return;
|
|
1295
|
-
throw err;
|
|
1296
|
-
}
|
|
1297
|
-
try {
|
|
1298
|
-
await parentDir.removeEntry(name, { recursive: true });
|
|
1299
|
-
} catch (err) {
|
|
1300
|
-
if (isNotFound(err)) return;
|
|
1301
|
-
throw err;
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
// src/commands/builtin/opfs/rm.ts
|
|
1306
|
-
async function rmCommand(accessor, paths, texts, opts) {
|
|
1307
|
-
if (paths.length === 0) {
|
|
1308
|
-
return [
|
|
1309
|
-
null,
|
|
1310
|
-
new IOResult5({
|
|
1311
|
-
exitCode: 1,
|
|
1312
|
-
stderr: new TextEncoder().encode("rm: missing operand\n")
|
|
1313
|
-
})
|
|
1314
|
-
];
|
|
1315
|
-
}
|
|
1316
|
-
const recursive = opts.flags.r === true || opts.flags.R === true;
|
|
1317
|
-
const dirFlag = opts.flags.d === true;
|
|
1318
|
-
const force = opts.flags.f === true;
|
|
1319
|
-
const verbose = opts.flags.v === true;
|
|
1320
|
-
const errors = [];
|
|
1321
|
-
const verboseParts = [];
|
|
1322
|
-
const writes = {};
|
|
1323
|
-
for (const p of paths) {
|
|
1324
|
-
let isDir = false;
|
|
1325
|
-
try {
|
|
1326
|
-
const st = await stat(accessor, p);
|
|
1327
|
-
isDir = st.type === FileType2.DIRECTORY;
|
|
1328
|
-
} catch {
|
|
1329
|
-
if (force) continue;
|
|
1330
|
-
errors.push(`rm: cannot remove '${p.virtual}': No such file or directory`);
|
|
1331
|
-
continue;
|
|
1332
|
-
}
|
|
1333
|
-
let entryLines = [];
|
|
1334
|
-
if (isDir) {
|
|
1335
|
-
if (recursive) {
|
|
1336
|
-
if (verbose) {
|
|
1337
|
-
entryLines = removalLines(
|
|
1338
|
-
await cpWalk(
|
|
1339
|
-
(dir) => readdir(accessor, dir),
|
|
1340
|
-
(spec) => stat(accessor, spec),
|
|
1341
|
-
p
|
|
1342
|
-
)
|
|
1343
|
-
);
|
|
1344
|
-
}
|
|
1345
|
-
await rmR(accessor, p);
|
|
1346
|
-
} else if (dirFlag) {
|
|
1347
|
-
if ((await readdir(accessor, p)).length > 0) {
|
|
1348
|
-
errors.push(`rm: cannot remove '${p.virtual}': Directory not empty`);
|
|
1349
|
-
continue;
|
|
1350
|
-
}
|
|
1351
|
-
await rmdir(accessor, p);
|
|
1352
|
-
entryLines = [`removed directory '${p.virtual.replace(/\/+$/, "") || "/"}'`];
|
|
1353
|
-
} else {
|
|
1354
|
-
errors.push(`rm: cannot remove '${p.virtual}': Is a directory`);
|
|
1355
|
-
continue;
|
|
1356
|
-
}
|
|
1357
|
-
} else {
|
|
1358
|
-
await unlink(accessor, p);
|
|
1359
|
-
entryLines = [`removed '${p.virtual.replace(/\/+$/, "") || "/"}'`];
|
|
1360
|
-
}
|
|
1361
|
-
writes[p.mountPath] = new Uint8Array();
|
|
1362
|
-
if (verbose) verboseParts.push(...entryLines);
|
|
1363
|
-
}
|
|
1364
|
-
const output = verbose && verboseParts.length > 0 ? formatRecords2(verboseParts) : null;
|
|
1365
|
-
const stderr = errors.length > 0 ? new TextEncoder().encode(errors.join("\n") + "\n") : void 0;
|
|
1366
|
-
return [
|
|
1367
|
-
output,
|
|
1368
|
-
new IOResult5({
|
|
1369
|
-
writes,
|
|
1370
|
-
exitCode: errors.length > 0 ? 1 : 0,
|
|
1371
|
-
...stderr !== void 0 ? { stderr } : {}
|
|
1372
|
-
})
|
|
1373
|
-
];
|
|
1374
|
-
}
|
|
1375
|
-
var OPFS_RM = command41({
|
|
1376
|
-
name: "rm",
|
|
1377
|
-
resource: ResourceName44.OPFS,
|
|
1378
|
-
spec: specOf41("rm"),
|
|
1379
|
-
fn: rmCommand,
|
|
1380
|
-
write: true
|
|
1381
|
-
});
|
|
1382
|
-
|
|
1383
|
-
// src/commands/builtin/opfs/rmdir.ts
|
|
1384
|
-
import {
|
|
1385
|
-
FileType as FileType3,
|
|
1386
|
-
IOResult as IOResult6,
|
|
1387
|
-
ResourceName as ResourceName45,
|
|
1388
|
-
command as command42,
|
|
1389
|
-
formatRecords as formatRecords3,
|
|
1390
|
-
specOf as specOf42
|
|
1391
|
-
} from "@struktoai/mirage-core";
|
|
1392
|
-
async function rmdirCommand(accessor, paths, _texts, opts) {
|
|
1393
|
-
const enc = new TextEncoder();
|
|
1394
|
-
if (paths.length === 0) {
|
|
1395
|
-
return [
|
|
1396
|
-
null,
|
|
1397
|
-
new IOResult6({
|
|
1398
|
-
exitCode: 1,
|
|
1399
|
-
stderr: enc.encode("rmdir: missing operand\nTry 'rmdir --help' for more information.\n")
|
|
1400
|
-
})
|
|
1401
|
-
];
|
|
1402
|
-
}
|
|
1403
|
-
const verbose = opts.flags.v === true;
|
|
1404
|
-
const errors = [];
|
|
1405
|
-
const verboseParts = [];
|
|
1406
|
-
const writes = {};
|
|
1407
|
-
for (const p of paths) {
|
|
1408
|
-
let isDir = false;
|
|
1409
|
-
try {
|
|
1410
|
-
isDir = (await stat(accessor, p)).type === FileType3.DIRECTORY;
|
|
1411
|
-
} catch {
|
|
1412
|
-
errors.push(`rmdir: failed to remove '${p.virtual}': No such file or directory`);
|
|
1413
|
-
continue;
|
|
1414
|
-
}
|
|
1415
|
-
if (!isDir) {
|
|
1416
|
-
errors.push(`rmdir: failed to remove '${p.virtual}': Not a directory`);
|
|
1417
|
-
continue;
|
|
1418
|
-
}
|
|
1419
|
-
if ((await readdir(accessor, p)).length > 0) {
|
|
1420
|
-
errors.push(`rmdir: failed to remove '${p.virtual}': Directory not empty`);
|
|
1421
|
-
continue;
|
|
1422
|
-
}
|
|
1423
|
-
await rmdir(accessor, p);
|
|
1424
|
-
writes[p.mountPath] = new Uint8Array();
|
|
1425
|
-
if (verbose) verboseParts.push(`rmdir: removing directory, '${p.virtual}'`);
|
|
1426
|
-
}
|
|
1427
|
-
const output = verbose && verboseParts.length > 0 ? formatRecords3(verboseParts) : null;
|
|
1428
|
-
const stderr = errors.length > 0 ? enc.encode(errors.join("\n") + "\n") : void 0;
|
|
1429
|
-
return [
|
|
1430
|
-
output,
|
|
1431
|
-
new IOResult6({
|
|
1432
|
-
writes,
|
|
1433
|
-
exitCode: errors.length > 0 ? 1 : 0,
|
|
1434
|
-
...stderr !== void 0 ? { stderr } : {}
|
|
1435
|
-
})
|
|
1436
|
-
];
|
|
1437
|
-
}
|
|
1438
|
-
var OPFS_RMDIR = command42({
|
|
1439
|
-
name: "rmdir",
|
|
1440
|
-
resource: ResourceName45.OPFS,
|
|
1441
|
-
spec: specOf42("rmdir"),
|
|
1442
|
-
fn: rmdirCommand,
|
|
1443
|
-
write: true
|
|
1444
|
-
});
|
|
1445
|
-
|
|
1446
|
-
// src/commands/builtin/opfs/sed.ts
|
|
1447
|
-
import {
|
|
1448
|
-
PathSpec,
|
|
1449
|
-
ResourceName as ResourceName46,
|
|
1450
|
-
command as command43,
|
|
1451
|
-
makeSedProvision,
|
|
1452
|
-
mountKey,
|
|
1453
|
-
resolvePath,
|
|
1454
|
-
rstripSlash,
|
|
1455
|
-
sedGeneric,
|
|
1456
|
-
specOf as specOf43
|
|
1457
|
-
} from "@struktoai/mirage-core";
|
|
1458
|
-
function positionalAsPaths(texts, opts) {
|
|
1459
|
-
const prefix = opts.mountPrefix !== void 0 ? rstripSlash(opts.mountPrefix) : "";
|
|
1460
|
-
return texts.map((t) => {
|
|
1461
|
-
const resolved = resolvePath(t, opts.cwd);
|
|
1462
|
-
const slash = resolved.lastIndexOf("/");
|
|
1463
|
-
return new PathSpec({
|
|
1464
|
-
virtual: resolved,
|
|
1465
|
-
directory: slash >= 0 ? resolved.slice(0, slash + 1) : "/",
|
|
1466
|
-
resolved: true,
|
|
1467
|
-
resourcePath: mountKey(resolved, prefix)
|
|
1468
|
-
});
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
var OPFS_SED = command43({
|
|
1472
|
-
name: "sed",
|
|
1473
|
-
resource: ResourceName46.OPFS,
|
|
1474
|
-
spec: specOf43("sed"),
|
|
1475
|
-
provision: makeSedProvision((a, p) => stat(a, p)),
|
|
1476
|
-
fn: async (accessor, paths, texts, opts) => {
|
|
1477
|
-
const usingE = opts.flags.e !== void 0 && opts.flags.e !== false;
|
|
1478
|
-
const usingF = opts.flags.f !== void 0 && opts.flags.f !== false;
|
|
1479
|
-
const operands = usingE || usingF ? [...positionalAsPaths(texts, opts), ...paths] : paths;
|
|
1480
|
-
return sedGeneric(
|
|
1481
|
-
operands,
|
|
1482
|
-
texts,
|
|
1483
|
-
opts,
|
|
1484
|
-
(p) => stream(accessor, p),
|
|
1485
|
-
(p, d) => writeBytes(accessor, p, d)
|
|
1486
|
-
);
|
|
1487
|
-
}
|
|
1488
|
-
});
|
|
1489
|
-
|
|
1490
|
-
// src/commands/builtin/opfs/sha1sum.ts
|
|
1491
|
-
import { ResourceName as ResourceName47, command as command44, sha1sumGeneric, specOf as specOf44 } from "@struktoai/mirage-core";
|
|
1492
|
-
var OPFS_SHA1SUM = command44({
|
|
1493
|
-
name: "sha1sum",
|
|
1494
|
-
resource: ResourceName47.OPFS,
|
|
1495
|
-
spec: specOf44("sha1sum"),
|
|
1496
|
-
fn: (accessor, paths, _texts, opts) => sha1sumGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1497
|
-
});
|
|
1498
|
-
|
|
1499
|
-
// src/commands/builtin/opfs/sha256sum.ts
|
|
1500
|
-
import { ResourceName as ResourceName48, command as command45, sha256sumGeneric, specOf as specOf45 } from "@struktoai/mirage-core";
|
|
1501
|
-
var OPFS_SHA256SUM = command45({
|
|
1502
|
-
name: "sha256sum",
|
|
1503
|
-
resource: ResourceName48.OPFS,
|
|
1504
|
-
spec: specOf45("sha256sum"),
|
|
1505
|
-
fn: (accessor, paths, _texts, opts) => sha256sumGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1506
|
-
});
|
|
1507
|
-
|
|
1508
|
-
// src/commands/builtin/opfs/sha384sum.ts
|
|
1509
|
-
import { ResourceName as ResourceName49, command as command46, sha384sumGeneric, specOf as specOf46 } from "@struktoai/mirage-core";
|
|
1510
|
-
var OPFS_SHA384SUM = command46({
|
|
1511
|
-
name: "sha384sum",
|
|
1512
|
-
resource: ResourceName49.OPFS,
|
|
1513
|
-
spec: specOf46("sha384sum"),
|
|
1514
|
-
fn: (accessor, paths, _texts, opts) => sha384sumGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1515
|
-
});
|
|
1516
|
-
|
|
1517
|
-
// src/commands/builtin/opfs/sha512sum.ts
|
|
1518
|
-
import { ResourceName as ResourceName50, command as command47, sha512sumGeneric, specOf as specOf47 } from "@struktoai/mirage-core";
|
|
1519
|
-
var OPFS_SHA512SUM = command47({
|
|
1520
|
-
name: "sha512sum",
|
|
1521
|
-
resource: ResourceName50.OPFS,
|
|
1522
|
-
spec: specOf47("sha512sum"),
|
|
1523
|
-
fn: (accessor, paths, _texts, opts) => sha512sumGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1524
|
-
});
|
|
1525
|
-
|
|
1526
|
-
// src/commands/builtin/opfs/shuf.ts
|
|
1527
|
-
import { ResourceName as ResourceName51, command as command48, specOf as specOf48, shufGeneric } from "@struktoai/mirage-core";
|
|
1528
|
-
var OPFS_SHUF = command48({
|
|
1529
|
-
name: "shuf",
|
|
1530
|
-
resource: ResourceName51.OPFS,
|
|
1531
|
-
spec: specOf48("shuf"),
|
|
1532
|
-
fn: (accessor, paths, texts, opts) => shufGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
1533
|
-
});
|
|
1534
|
-
|
|
1535
|
-
// src/commands/builtin/opfs/sort.ts
|
|
1536
|
-
import { ResourceName as ResourceName52, command as command49, specOf as specOf49, sortGeneric } from "@struktoai/mirage-core";
|
|
1537
|
-
var OPFS_SORT = command49({
|
|
1538
|
-
name: "sort",
|
|
1539
|
-
resource: ResourceName52.OPFS,
|
|
1540
|
-
spec: specOf49("sort"),
|
|
1541
|
-
fn: (accessor, paths, _texts, opts) => sortGeneric(
|
|
1542
|
-
paths,
|
|
1543
|
-
opts,
|
|
1544
|
-
(p) => stream(accessor, p),
|
|
1545
|
-
(p, data) => writeBytes(accessor, p, data)
|
|
1546
|
-
)
|
|
1547
|
-
});
|
|
1548
|
-
|
|
1549
|
-
// src/commands/builtin/opfs/split.ts
|
|
1550
|
-
import { ResourceName as ResourceName53, command as command50, specOf as specOf50, splitGeneric } from "@struktoai/mirage-core";
|
|
1551
|
-
var OPFS_SPLIT = command50({
|
|
1552
|
-
name: "split",
|
|
1553
|
-
resource: ResourceName53.OPFS,
|
|
1554
|
-
spec: specOf50("split"),
|
|
1555
|
-
fn: (accessor, paths, _texts, opts) => splitGeneric(
|
|
1556
|
-
paths,
|
|
1557
|
-
opts,
|
|
1558
|
-
(p) => stream(accessor, p),
|
|
1559
|
-
(p, d) => writeBytes(accessor, p, d)
|
|
1560
|
-
),
|
|
1561
|
-
write: true
|
|
1562
|
-
});
|
|
1563
|
-
|
|
1564
|
-
// src/commands/builtin/opfs/stat/stat.ts
|
|
1565
|
-
import { ResourceName as ResourceName54, command as command51, specOf as specOf51, statGeneric } from "@struktoai/mirage-core";
|
|
1566
|
-
var OPFS_STAT = command51({
|
|
1567
|
-
name: "stat",
|
|
1568
|
-
resource: ResourceName54.OPFS,
|
|
1569
|
-
spec: specOf51("stat"),
|
|
1570
|
-
fn: (accessor, paths, _texts, opts) => statGeneric(paths, opts, (p) => stat(accessor, p))
|
|
1571
|
-
});
|
|
1572
|
-
|
|
1573
|
-
// src/commands/builtin/opfs/strings.ts
|
|
1574
|
-
import { ResourceName as ResourceName55, command as command52, specOf as specOf52, stringsGeneric } from "@struktoai/mirage-core";
|
|
1575
|
-
var OPFS_STRINGS = command52({
|
|
1576
|
-
name: "strings",
|
|
1577
|
-
resource: ResourceName55.OPFS,
|
|
1578
|
-
spec: specOf52("strings"),
|
|
1579
|
-
fn: (accessor, paths, _texts, opts) => stringsGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1580
|
-
});
|
|
1581
|
-
|
|
1582
|
-
// src/commands/builtin/opfs/tac.ts
|
|
1583
|
-
import { ResourceName as ResourceName56, command as command53, specOf as specOf53, tacGeneric } from "@struktoai/mirage-core";
|
|
1584
|
-
var OPFS_TAC = command53({
|
|
1585
|
-
name: "tac",
|
|
1586
|
-
resource: ResourceName56.OPFS,
|
|
1587
|
-
spec: specOf53("tac"),
|
|
1588
|
-
fn: (accessor, paths, _texts, opts) => tacGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1589
|
-
});
|
|
1590
|
-
|
|
1591
|
-
// src/commands/builtin/opfs/tail/tail.ts
|
|
1592
|
-
import { ResourceName as ResourceName57, command as command54, headerAggregate as headerAggregate2, specOf as specOf54, tailGeneric } from "@struktoai/mirage-core";
|
|
1593
|
-
var OPFS_TAIL = command54({
|
|
1594
|
-
name: "tail",
|
|
1595
|
-
resource: ResourceName57.OPFS,
|
|
1596
|
-
spec: specOf54("tail"),
|
|
1597
|
-
fn: (accessor, paths, texts, opts) => tailGeneric(paths, texts, opts, (p) => stream(accessor, p)),
|
|
1598
|
-
aggregate: headerAggregate2
|
|
1599
|
-
});
|
|
1600
|
-
|
|
1601
|
-
// src/commands/builtin/opfs/tar.ts
|
|
1602
|
-
import { ResourceName as ResourceName58, command as command55, specOf as specOf55, tarGeneric } from "@struktoai/mirage-core";
|
|
1603
|
-
var OPFS_TAR = command55({
|
|
1604
|
-
name: "tar",
|
|
1605
|
-
resource: ResourceName58.OPFS,
|
|
1606
|
-
spec: specOf55("tar"),
|
|
1607
|
-
fn: (accessor, paths, _texts, opts) => tarGeneric(
|
|
1608
|
-
paths,
|
|
1609
|
-
opts,
|
|
1610
|
-
(p) => stream(accessor, p),
|
|
1611
|
-
(p, data) => writeBytes(accessor, p, data),
|
|
1612
|
-
(p) => mkdir(accessor, p)
|
|
1613
|
-
),
|
|
1614
|
-
write: true
|
|
1615
|
-
});
|
|
1616
|
-
|
|
1617
|
-
// src/commands/builtin/opfs/tee.ts
|
|
1618
|
-
import { ResourceName as ResourceName59, command as command56, specOf as specOf56, teeGeneric } from "@struktoai/mirage-core";
|
|
1619
|
-
var OPFS_TEE = command56({
|
|
1620
|
-
name: "tee",
|
|
1621
|
-
resource: ResourceName59.OPFS,
|
|
1622
|
-
spec: specOf56("tee"),
|
|
1623
|
-
fn: (accessor, paths, texts, opts) => teeGeneric(
|
|
1624
|
-
paths,
|
|
1625
|
-
texts,
|
|
1626
|
-
opts,
|
|
1627
|
-
(p) => stream(accessor, p),
|
|
1628
|
-
(p, d) => writeBytes(accessor, p, d)
|
|
1629
|
-
),
|
|
1630
|
-
write: true
|
|
1631
|
-
});
|
|
1632
|
-
|
|
1633
|
-
// src/commands/builtin/opfs/touch.ts
|
|
1634
|
-
import {
|
|
1635
|
-
IOResult as IOResult7,
|
|
1636
|
-
ResourceName as ResourceName60,
|
|
1637
|
-
command as command57,
|
|
1638
|
-
specOf as specOf57
|
|
1639
|
-
} from "@struktoai/mirage-core";
|
|
1640
|
-
var ENC2 = new TextEncoder();
|
|
1641
|
-
async function touchCommand(accessor, paths, texts, opts) {
|
|
1642
|
-
if (paths.length === 0) {
|
|
1643
|
-
return [null, new IOResult7({ exitCode: 1, stderr: ENC2.encode("touch: missing operand\n") })];
|
|
1644
|
-
}
|
|
1645
|
-
const createOnly = opts.flags.c === true;
|
|
1646
|
-
for (const p of paths) {
|
|
1647
|
-
if (createOnly) continue;
|
|
1648
|
-
if (!await exists(accessor, p)) {
|
|
1649
|
-
await writeBytes(accessor, p, new Uint8Array(0));
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
return [null, new IOResult7()];
|
|
1653
|
-
}
|
|
1654
|
-
var OPFS_TOUCH = command57({
|
|
1655
|
-
name: "touch",
|
|
1656
|
-
resource: ResourceName60.OPFS,
|
|
1657
|
-
spec: specOf57("touch"),
|
|
1658
|
-
fn: touchCommand,
|
|
1659
|
-
write: true
|
|
1660
|
-
});
|
|
1661
|
-
|
|
1662
|
-
// src/commands/builtin/opfs/tr.ts
|
|
1663
|
-
import { ResourceName as ResourceName61, command as command58, specOf as specOf58, trGeneric } from "@struktoai/mirage-core";
|
|
1664
|
-
var OPFS_TR = command58({
|
|
1665
|
-
name: "tr",
|
|
1666
|
-
resource: ResourceName61.OPFS,
|
|
1667
|
-
spec: specOf58("tr"),
|
|
1668
|
-
fn: (accessor, paths, texts, opts) => trGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
1669
|
-
});
|
|
1670
|
-
|
|
1671
|
-
// src/commands/builtin/opfs/tree.ts
|
|
1672
|
-
import { ResourceName as ResourceName62, command as command59, specOf as specOf59, treeGeneric } from "@struktoai/mirage-core";
|
|
1673
|
-
var OPFS_TREE = command59({
|
|
1674
|
-
name: "tree",
|
|
1675
|
-
resource: ResourceName62.OPFS,
|
|
1676
|
-
spec: specOf59("tree"),
|
|
1677
|
-
fn: (accessor, paths, _texts, opts) => treeGeneric(
|
|
1678
|
-
paths,
|
|
1679
|
-
opts,
|
|
1680
|
-
(p) => readdir(accessor, p),
|
|
1681
|
-
(p) => stat(accessor, p)
|
|
1682
|
-
)
|
|
1683
|
-
});
|
|
1684
|
-
|
|
1685
|
-
// src/commands/builtin/opfs/tsort.ts
|
|
1686
|
-
import { ResourceName as ResourceName63, command as command60, specOf as specOf60, tsortGeneric } from "@struktoai/mirage-core";
|
|
1687
|
-
var OPFS_TSORT = command60({
|
|
1688
|
-
name: "tsort",
|
|
1689
|
-
resource: ResourceName63.OPFS,
|
|
1690
|
-
spec: specOf60("tsort"),
|
|
1691
|
-
fn: (accessor, paths, _texts, opts) => tsortGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1692
|
-
});
|
|
1693
|
-
|
|
1694
|
-
// src/commands/builtin/opfs/unexpand.ts
|
|
1695
|
-
import { ResourceName as ResourceName64, command as command61, specOf as specOf61, unexpandGeneric } from "@struktoai/mirage-core";
|
|
1696
|
-
var OPFS_UNEXPAND = command61({
|
|
1697
|
-
name: "unexpand",
|
|
1698
|
-
resource: ResourceName64.OPFS,
|
|
1699
|
-
spec: specOf61("unexpand"),
|
|
1700
|
-
fn: (accessor, paths, _texts, opts) => unexpandGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1701
|
-
});
|
|
1702
|
-
|
|
1703
|
-
// src/commands/builtin/opfs/uniq.ts
|
|
1704
|
-
import { ResourceName as ResourceName65, command as command62, specOf as specOf62, uniqGeneric } from "@struktoai/mirage-core";
|
|
1705
|
-
var OPFS_UNIQ = command62({
|
|
1706
|
-
name: "uniq",
|
|
1707
|
-
resource: ResourceName65.OPFS,
|
|
1708
|
-
spec: specOf62("uniq"),
|
|
1709
|
-
fn: (accessor, paths, _texts, opts) => uniqGeneric(
|
|
1710
|
-
paths,
|
|
1711
|
-
opts,
|
|
1712
|
-
(p) => stream(accessor, p),
|
|
1713
|
-
(p, data) => writeBytes(accessor, p, data)
|
|
1714
|
-
)
|
|
1715
|
-
});
|
|
1716
|
-
|
|
1717
|
-
// src/commands/builtin/opfs/unlink.ts
|
|
1718
|
-
import {
|
|
1719
|
-
FileType as FileType4,
|
|
1720
|
-
IOResult as IOResult8,
|
|
1721
|
-
ResourceName as ResourceName66,
|
|
1722
|
-
command as command63,
|
|
1723
|
-
specOf as specOf63
|
|
1724
|
-
} from "@struktoai/mirage-core";
|
|
1725
|
-
async function unlinkCommand(accessor, paths, _texts, _opts) {
|
|
1726
|
-
const enc = new TextEncoder();
|
|
1727
|
-
if (paths.length === 0) {
|
|
1728
|
-
return [
|
|
1729
|
-
null,
|
|
1730
|
-
new IOResult8({
|
|
1731
|
-
exitCode: 1,
|
|
1732
|
-
stderr: enc.encode("unlink: missing operand\nTry 'unlink --help' for more information.\n")
|
|
1733
|
-
})
|
|
1734
|
-
];
|
|
1735
|
-
}
|
|
1736
|
-
if (paths.length > 1) {
|
|
1737
|
-
const extra = paths[1];
|
|
1738
|
-
const raw = extra === void 0 ? "" : extra.rawPath;
|
|
1739
|
-
return [
|
|
1740
|
-
null,
|
|
1741
|
-
new IOResult8({
|
|
1742
|
-
exitCode: 1,
|
|
1743
|
-
stderr: enc.encode(
|
|
1744
|
-
`unlink: extra operand '${raw}'
|
|
1745
|
-
Try 'unlink --help' for more information.
|
|
1746
|
-
`
|
|
1747
|
-
)
|
|
1748
|
-
})
|
|
1749
|
-
];
|
|
1750
|
-
}
|
|
1751
|
-
const p = paths[0];
|
|
1752
|
-
if (p === void 0) return [null, new IOResult8()];
|
|
1753
|
-
try {
|
|
1754
|
-
if ((await stat(accessor, p)).type === FileType4.DIRECTORY) {
|
|
1755
|
-
return [
|
|
1756
|
-
null,
|
|
1757
|
-
new IOResult8({
|
|
1758
|
-
exitCode: 1,
|
|
1759
|
-
stderr: enc.encode(`unlink: cannot unlink '${p.virtual}': Is a directory
|
|
1760
|
-
`)
|
|
1761
|
-
})
|
|
1762
|
-
];
|
|
1763
|
-
}
|
|
1764
|
-
} catch {
|
|
1765
|
-
return [
|
|
1766
|
-
null,
|
|
1767
|
-
new IOResult8({
|
|
1768
|
-
exitCode: 1,
|
|
1769
|
-
stderr: enc.encode(`unlink: cannot unlink '${p.virtual}': No such file or directory
|
|
1770
|
-
`)
|
|
1771
|
-
})
|
|
1772
|
-
];
|
|
1773
|
-
}
|
|
1774
|
-
await unlink(accessor, p);
|
|
1775
|
-
return [null, new IOResult8({ writes: { [p.mountPath]: new Uint8Array() } })];
|
|
1776
|
-
}
|
|
1777
|
-
var OPFS_UNLINK = command63({
|
|
1778
|
-
name: "unlink",
|
|
1779
|
-
resource: ResourceName66.OPFS,
|
|
1780
|
-
spec: specOf63("unlink"),
|
|
1781
|
-
fn: unlinkCommand,
|
|
1782
|
-
write: true
|
|
1783
|
-
});
|
|
1784
|
-
|
|
1785
|
-
// src/commands/builtin/opfs/unzip.ts
|
|
1786
|
-
import { ResourceName as ResourceName67, command as command64, specOf as specOf64, unzipGeneric } from "@struktoai/mirage-core";
|
|
1787
|
-
var OPFS_UNZIP = command64({
|
|
1788
|
-
name: "unzip",
|
|
1789
|
-
resource: ResourceName67.OPFS,
|
|
1790
|
-
spec: specOf64("unzip"),
|
|
1791
|
-
fn: (accessor, paths, _texts, opts) => unzipGeneric(
|
|
1792
|
-
paths,
|
|
1793
|
-
opts,
|
|
1794
|
-
(p) => stream(accessor, p),
|
|
1795
|
-
(p, d) => writeBytes(accessor, p, d),
|
|
1796
|
-
(p, parents) => mkdir(accessor, p, parents)
|
|
1797
|
-
),
|
|
1798
|
-
write: true
|
|
1799
|
-
});
|
|
1800
|
-
|
|
1801
|
-
// src/commands/builtin/opfs/wc/wc.ts
|
|
1802
|
-
import { ResourceName as ResourceName68, command as command65, specOf as specOf65, wcAggregate, wcGeneric } from "@struktoai/mirage-core";
|
|
1803
|
-
var OPFS_WC = command65({
|
|
1804
|
-
name: "wc",
|
|
1805
|
-
resource: ResourceName68.OPFS,
|
|
1806
|
-
spec: specOf65("wc"),
|
|
1807
|
-
fn: (accessor, paths, texts, opts) => wcGeneric(paths, texts, opts, (p) => stream(accessor, p)),
|
|
1808
|
-
aggregate: wcAggregate
|
|
1809
|
-
});
|
|
1810
|
-
|
|
1811
|
-
// src/commands/builtin/opfs/xxd.ts
|
|
1812
|
-
import { ResourceName as ResourceName69, command as command66, specOf as specOf66, xxdGeneric } from "@struktoai/mirage-core";
|
|
1813
|
-
var OPFS_XXD = command66({
|
|
1814
|
-
name: "xxd",
|
|
1815
|
-
resource: ResourceName69.OPFS,
|
|
1816
|
-
spec: specOf66("xxd"),
|
|
1817
|
-
fn: (accessor, paths, _texts, opts) => xxdGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1818
|
-
});
|
|
1819
|
-
|
|
1820
|
-
// src/commands/builtin/opfs/zcat.ts
|
|
1821
|
-
import { ResourceName as ResourceName70, command as command67, specOf as specOf67, zcatGeneric } from "@struktoai/mirage-core";
|
|
1822
|
-
var OPFS_ZCAT = command67({
|
|
1823
|
-
name: "zcat",
|
|
1824
|
-
resource: ResourceName70.OPFS,
|
|
1825
|
-
spec: specOf67("zcat"),
|
|
1826
|
-
fn: (accessor, paths, _texts, opts) => zcatGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1827
|
-
});
|
|
1828
|
-
|
|
1829
|
-
// src/commands/builtin/opfs/zgrep.ts
|
|
1830
|
-
import { ResourceName as ResourceName71, command as command68, specOf as specOf68, zgrepGeneric } from "@struktoai/mirage-core";
|
|
1831
|
-
var OPFS_ZGREP = command68({
|
|
1832
|
-
name: "zgrep",
|
|
1833
|
-
resource: ResourceName71.OPFS,
|
|
1834
|
-
spec: specOf68("zgrep"),
|
|
1835
|
-
fn: (accessor, paths, texts, opts) => zgrepGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
1836
|
-
});
|
|
1837
|
-
|
|
1838
|
-
// src/commands/builtin/opfs/zip_cmd.ts
|
|
1839
|
-
import { ResourceName as ResourceName72, command as command69, specOf as specOf69, zipGeneric } from "@struktoai/mirage-core";
|
|
1840
|
-
var OPFS_ZIP = command69({
|
|
1841
|
-
name: "zip",
|
|
1842
|
-
resource: ResourceName72.OPFS,
|
|
1843
|
-
spec: specOf69("zip"),
|
|
1844
|
-
fn: (accessor, paths, _texts, opts) => zipGeneric(
|
|
1845
|
-
paths,
|
|
1846
|
-
opts,
|
|
1847
|
-
(p) => stream(accessor, p),
|
|
1848
|
-
(p, d) => writeBytes(accessor, p, d)
|
|
1849
|
-
),
|
|
1850
|
-
write: true
|
|
1851
|
-
});
|
|
1852
|
-
|
|
1853
|
-
// src/commands/builtin/opfs/index.ts
|
|
1854
|
-
var opfsResolveGlob = makeResolveGlob(readdir, SCOPE_ERROR);
|
|
1855
|
-
var OPFS_COMMANDS = withDefaultProvisions(
|
|
1856
|
-
[
|
|
1857
|
-
...makeFiletypeCommands({
|
|
1858
|
-
resource: ResourceName73.OPFS,
|
|
1859
|
-
readBytes: read,
|
|
1860
|
-
statEntry: stat
|
|
1861
|
-
}),
|
|
1862
|
-
...OPFS_AWK,
|
|
1863
|
-
...OPFS_BASE64,
|
|
1864
|
-
...OPFS_BASENAME,
|
|
1865
|
-
...OPFS_CAT,
|
|
1866
|
-
...OPFS_CMP,
|
|
1867
|
-
...OPFS_COLUMN,
|
|
1868
|
-
...OPFS_COMM,
|
|
1869
|
-
...OPFS_CP,
|
|
1870
|
-
...OPFS_CSPLIT,
|
|
1871
|
-
...OPFS_CUT,
|
|
1872
|
-
...OPFS_DIFF,
|
|
1873
|
-
...OPFS_DIRNAME,
|
|
1874
|
-
...OPFS_DU,
|
|
1875
|
-
...OPFS_EXPAND,
|
|
1876
|
-
...OPFS_FILE,
|
|
1877
|
-
...OPFS_FIND,
|
|
1878
|
-
...OPFS_FMT,
|
|
1879
|
-
...OPFS_FOLD,
|
|
1880
|
-
...OPFS_GREP,
|
|
1881
|
-
...OPFS_GUNZIP,
|
|
1882
|
-
...OPFS_GZIP,
|
|
1883
|
-
...OPFS_HEAD,
|
|
1884
|
-
...OPFS_ICONV,
|
|
1885
|
-
...OPFS_JOIN,
|
|
1886
|
-
...OPFS_JQ,
|
|
1887
|
-
...OPFS_LN,
|
|
1888
|
-
...OPFS_LOOK,
|
|
1889
|
-
...OPFS_LS,
|
|
1890
|
-
...OPFS_MD5,
|
|
1891
|
-
...OPFS_MD5SUM,
|
|
1892
|
-
...OPFS_MKDIR,
|
|
1893
|
-
...OPFS_MKTEMP,
|
|
1894
|
-
...OPFS_MV,
|
|
1895
|
-
...OPFS_NL,
|
|
1896
|
-
...OPFS_PASTE,
|
|
1897
|
-
...OPFS_PATCH,
|
|
1898
|
-
...OPFS_READLINK,
|
|
1899
|
-
...OPFS_REALPATH,
|
|
1900
|
-
...OPFS_REV,
|
|
1901
|
-
...OPFS_RG,
|
|
1902
|
-
...OPFS_RM,
|
|
1903
|
-
...OPFS_RMDIR,
|
|
1904
|
-
...OPFS_SED,
|
|
1905
|
-
...OPFS_SHA1SUM,
|
|
1906
|
-
...OPFS_SHA256SUM,
|
|
1907
|
-
...OPFS_SHA384SUM,
|
|
1908
|
-
...OPFS_SHA512SUM,
|
|
1909
|
-
...OPFS_SHUF,
|
|
1910
|
-
...OPFS_SORT,
|
|
1911
|
-
...OPFS_SPLIT,
|
|
1912
|
-
...OPFS_STAT,
|
|
1913
|
-
...OPFS_STRINGS,
|
|
1914
|
-
...OPFS_TAC,
|
|
1915
|
-
...OPFS_TAIL,
|
|
1916
|
-
...OPFS_TAR,
|
|
1917
|
-
...OPFS_TEE,
|
|
1918
|
-
...OPFS_TOUCH,
|
|
1919
|
-
...OPFS_TR,
|
|
1920
|
-
...OPFS_TREE,
|
|
1921
|
-
...OPFS_TSORT,
|
|
1922
|
-
...OPFS_UNEXPAND,
|
|
1923
|
-
...OPFS_UNIQ,
|
|
1924
|
-
...OPFS_UNLINK,
|
|
1925
|
-
...OPFS_UNZIP,
|
|
1926
|
-
...OPFS_WC,
|
|
1927
|
-
...OPFS_XXD,
|
|
1928
|
-
...OPFS_ZCAT,
|
|
1929
|
-
...OPFS_ZGREP,
|
|
1930
|
-
...OPFS_ZIP
|
|
1931
|
-
],
|
|
1932
|
-
stat,
|
|
1933
|
-
opfsResolveGlob,
|
|
1934
|
-
readdir
|
|
1935
|
-
);
|
|
1936
|
-
|
|
1937
|
-
// src/core/opfs/append.ts
|
|
1938
|
-
import { record as record3, ResourceName as ResourceName74 } from "@struktoai/mirage-core";
|
|
1939
|
-
async function appendBytes(accessor, p, data) {
|
|
1940
|
-
const root = accessor.rootHandle;
|
|
1941
|
-
const start = performance.now();
|
|
1942
|
-
const virtual = p.mountPath;
|
|
1943
|
-
const handle = await resolveFileHandle(root, virtual, { create: true });
|
|
1944
|
-
const existing = await handle.getFile();
|
|
1945
|
-
const existingBytes = new Uint8Array(await existing.arrayBuffer());
|
|
1946
|
-
const merged = new Uint8Array(existingBytes.byteLength + data.byteLength);
|
|
1947
|
-
merged.set(existingBytes, 0);
|
|
1948
|
-
merged.set(data, existingBytes.byteLength);
|
|
1949
|
-
const writable = await handle.createWritable();
|
|
1950
|
-
await writable.write(toWritableChunk(merged));
|
|
1951
|
-
await writable.close();
|
|
1952
|
-
record3("append", virtual, ResourceName74.OPFS, data.byteLength, start);
|
|
1953
|
-
}
|
|
1954
|
-
|
|
1955
|
-
// src/core/opfs/truncate.ts
|
|
1956
|
-
async function truncate(accessor, path, length) {
|
|
1957
|
-
const root = accessor.rootHandle;
|
|
1958
|
-
const virtual = path.mountPath;
|
|
1959
|
-
let handle;
|
|
1960
|
-
let existing;
|
|
1961
|
-
try {
|
|
1962
|
-
handle = await resolveFileHandle(root, virtual, { create: false });
|
|
1963
|
-
const file = await handle.getFile();
|
|
1964
|
-
existing = new Uint8Array(await file.arrayBuffer());
|
|
1965
|
-
} catch (err) {
|
|
1966
|
-
if (isNotFound(err)) {
|
|
1967
|
-
handle = await resolveFileHandle(root, virtual, { create: true });
|
|
1968
|
-
existing = new Uint8Array();
|
|
1969
|
-
} else {
|
|
1970
|
-
throw err;
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
const out = new Uint8Array(length);
|
|
1974
|
-
out.set(existing.subarray(0, Math.min(existing.byteLength, length)));
|
|
1975
|
-
const writable = await handle.createWritable();
|
|
1976
|
-
await writable.write(toWritableChunk(out));
|
|
1977
|
-
await writable.close();
|
|
1978
|
-
}
|
|
1979
|
-
|
|
1980
|
-
// src/ops/opfs/append.ts
|
|
1981
|
-
import { ResourceName as ResourceName75 } from "@struktoai/mirage-core";
|
|
1982
|
-
var appendOp = {
|
|
1983
|
-
name: "append",
|
|
1984
|
-
resource: ResourceName75.OPFS,
|
|
1985
|
-
filetype: null,
|
|
1986
|
-
write: true,
|
|
1987
|
-
fn: (accessor, path, args) => {
|
|
1988
|
-
const data = args[0];
|
|
1989
|
-
if (!(data instanceof Uint8Array)) {
|
|
1990
|
-
throw new TypeError("append op requires a Uint8Array as the first arg");
|
|
1991
|
-
}
|
|
1992
|
-
return appendBytes(accessor, path, data);
|
|
1993
|
-
}
|
|
1994
|
-
};
|
|
1995
|
-
|
|
1996
|
-
// src/ops/opfs/create.ts
|
|
1997
|
-
import { ResourceName as ResourceName76 } from "@struktoai/mirage-core";
|
|
1998
|
-
|
|
1999
|
-
// src/core/opfs/create.ts
|
|
2000
|
-
function create(accessor, path) {
|
|
2001
|
-
return writeBytes(accessor, path, new Uint8Array());
|
|
2002
|
-
}
|
|
2003
|
-
|
|
2004
|
-
// src/ops/opfs/create.ts
|
|
2005
|
-
var createOp = {
|
|
2006
|
-
name: "create",
|
|
2007
|
-
resource: ResourceName76.OPFS,
|
|
2008
|
-
filetype: null,
|
|
2009
|
-
write: true,
|
|
2010
|
-
fn: (accessor, path) => create(accessor, path)
|
|
2011
|
-
};
|
|
2012
|
-
|
|
2013
|
-
// src/ops/opfs/mkdir.ts
|
|
2014
|
-
import { ResourceName as ResourceName77 } from "@struktoai/mirage-core";
|
|
2015
|
-
var mkdirOp = {
|
|
2016
|
-
name: "mkdir",
|
|
2017
|
-
resource: ResourceName77.OPFS,
|
|
2018
|
-
filetype: null,
|
|
2019
|
-
write: true,
|
|
2020
|
-
fn: (accessor, path) => mkdir(accessor, path, true)
|
|
2021
|
-
};
|
|
2022
|
-
|
|
2023
|
-
// src/ops/opfs/read.ts
|
|
2024
|
-
import { ResourceName as ResourceName78 } from "@struktoai/mirage-core";
|
|
2025
|
-
var readOp = {
|
|
2026
|
-
name: "read",
|
|
2027
|
-
resource: ResourceName78.OPFS,
|
|
2028
|
-
filetype: null,
|
|
2029
|
-
write: false,
|
|
2030
|
-
fn: (accessor, path) => read(accessor, path)
|
|
2031
|
-
};
|
|
2032
|
-
|
|
2033
|
-
// src/ops/opfs/readdir.ts
|
|
2034
|
-
import { ResourceName as ResourceName79 } from "@struktoai/mirage-core";
|
|
2035
|
-
var readdirOp = {
|
|
2036
|
-
name: "readdir",
|
|
2037
|
-
resource: ResourceName79.OPFS,
|
|
2038
|
-
filetype: null,
|
|
2039
|
-
write: false,
|
|
2040
|
-
fn: (accessor, path) => readdir(accessor, path)
|
|
2041
|
-
};
|
|
2042
|
-
|
|
2043
|
-
// src/ops/opfs/rename.ts
|
|
2044
|
-
import { ResourceName as ResourceName80 } from "@struktoai/mirage-core";
|
|
2045
|
-
var renameOp = {
|
|
2046
|
-
name: "rename",
|
|
2047
|
-
resource: ResourceName80.OPFS,
|
|
2048
|
-
filetype: null,
|
|
2049
|
-
write: true,
|
|
2050
|
-
fn: (accessor, path, args) => {
|
|
2051
|
-
const dst = args[0];
|
|
2052
|
-
if (dst === void 0 || dst === null || typeof dst !== "object" || !("virtual" in dst)) {
|
|
2053
|
-
throw new TypeError("rename op requires a PathSpec destination as the first arg");
|
|
2054
|
-
}
|
|
2055
|
-
return rename(accessor, path, dst);
|
|
2056
|
-
}
|
|
2057
|
-
};
|
|
2058
|
-
|
|
2059
|
-
// src/ops/opfs/rmdir.ts
|
|
2060
|
-
import { ResourceName as ResourceName81 } from "@struktoai/mirage-core";
|
|
2061
|
-
var rmdirOp = {
|
|
2062
|
-
name: "rmdir",
|
|
2063
|
-
resource: ResourceName81.OPFS,
|
|
2064
|
-
filetype: null,
|
|
2065
|
-
write: true,
|
|
2066
|
-
fn: (accessor, path) => rmdir(accessor, path)
|
|
2067
|
-
};
|
|
2068
|
-
|
|
2069
|
-
// src/ops/opfs/stat.ts
|
|
2070
|
-
import { ResourceName as ResourceName82 } from "@struktoai/mirage-core";
|
|
2071
|
-
var statOp = {
|
|
2072
|
-
name: "stat",
|
|
2073
|
-
resource: ResourceName82.OPFS,
|
|
2074
|
-
filetype: null,
|
|
2075
|
-
write: false,
|
|
2076
|
-
fn: (accessor, path) => stat(accessor, path)
|
|
2077
|
-
};
|
|
2078
|
-
|
|
2079
|
-
// src/ops/opfs/truncate.ts
|
|
2080
|
-
import { ResourceName as ResourceName83 } from "@struktoai/mirage-core";
|
|
2081
|
-
var truncateOp = {
|
|
2082
|
-
name: "truncate",
|
|
2083
|
-
resource: ResourceName83.OPFS,
|
|
2084
|
-
filetype: null,
|
|
2085
|
-
write: true,
|
|
2086
|
-
fn: (accessor, path, args) => {
|
|
2087
|
-
const length = args[0];
|
|
2088
|
-
if (typeof length !== "number") {
|
|
2089
|
-
throw new TypeError("truncate op requires a number length as the first arg");
|
|
2090
|
-
}
|
|
2091
|
-
return truncate(accessor, path, length);
|
|
2092
|
-
}
|
|
2093
|
-
};
|
|
2094
|
-
|
|
2095
|
-
// src/ops/opfs/unlink.ts
|
|
2096
|
-
import { ResourceName as ResourceName84 } from "@struktoai/mirage-core";
|
|
2097
|
-
var unlinkOp = {
|
|
2098
|
-
name: "unlink",
|
|
2099
|
-
resource: ResourceName84.OPFS,
|
|
2100
|
-
filetype: null,
|
|
2101
|
-
write: true,
|
|
2102
|
-
fn: (accessor, path) => unlink(accessor, path)
|
|
2103
|
-
};
|
|
2104
|
-
|
|
2105
|
-
// src/ops/opfs/write.ts
|
|
2106
|
-
import { ResourceName as ResourceName85 } from "@struktoai/mirage-core";
|
|
2107
|
-
var writeOp = {
|
|
2108
|
-
name: "write",
|
|
2109
|
-
resource: ResourceName85.OPFS,
|
|
2110
|
-
filetype: null,
|
|
2111
|
-
write: true,
|
|
2112
|
-
fn: (accessor, path, args) => {
|
|
2113
|
-
const data = args[0];
|
|
2114
|
-
if (!(data instanceof Uint8Array)) {
|
|
2115
|
-
throw new TypeError("write op requires a Uint8Array as the first arg");
|
|
2116
|
-
}
|
|
2117
|
-
return writeBytes(accessor, path, data);
|
|
2118
|
-
}
|
|
2119
|
-
};
|
|
2120
|
-
|
|
2121
|
-
// src/ops/opfs/index.ts
|
|
2122
|
-
var OPFS_OPS = [
|
|
2123
|
-
appendOp,
|
|
2124
|
-
createOp,
|
|
2125
|
-
mkdirOp,
|
|
2126
|
-
readOp,
|
|
2127
|
-
readdirOp,
|
|
2128
|
-
renameOp,
|
|
2129
|
-
rmdirOp,
|
|
2130
|
-
statOp,
|
|
2131
|
-
truncateOp,
|
|
2132
|
-
unlinkOp,
|
|
2133
|
-
writeOp
|
|
2134
|
-
];
|
|
2135
|
-
|
|
2136
|
-
// src/resource/opfs/prompt.ts
|
|
2137
|
-
var OPFS_PROMPT = `{prefix}
|
|
2138
|
-
Browser Origin Private File System. Persistent per-origin storage that survives page reloads.
|
|
2139
|
-
Standard commands: ls, cat, head, tail, grep, wc, find, tree, mkdir, touch, cp, mv, rm, tee.`;
|
|
2140
|
-
|
|
2141
|
-
// src/resource/opfs/opfs.ts
|
|
2142
|
-
var globCore = makeResolveGlob2(readdir, SCOPE_ERROR);
|
|
2143
|
-
async function walkFiles(dir, currentPath, files) {
|
|
2144
|
-
for await (const [name, handle] of iterEntries(dir)) {
|
|
2145
|
-
const childPath = currentPath === "" ? name : `${currentPath}/${name}`;
|
|
2146
|
-
if (handle.kind === "file") {
|
|
2147
|
-
const fh = await dir.getFileHandle(name, { create: false });
|
|
2148
|
-
const file = await fh.getFile();
|
|
2149
|
-
files[childPath] = new Uint8Array(await file.arrayBuffer());
|
|
2150
|
-
} else {
|
|
2151
|
-
const child = await dir.getDirectoryHandle(name, { create: false });
|
|
2152
|
-
await walkFiles(child, childPath, files);
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
async function walkDirs(dir, currentPath, dirs) {
|
|
2157
|
-
for await (const [name, handle] of iterEntries(dir)) {
|
|
2158
|
-
if (handle.kind !== "directory") continue;
|
|
2159
|
-
const childPath = currentPath === "" ? `/${name}` : `${currentPath}/${name}`;
|
|
2160
|
-
dirs.push(childPath);
|
|
2161
|
-
const child = await dir.getDirectoryHandle(name, { create: false });
|
|
2162
|
-
await walkDirs(child, childPath, dirs);
|
|
2163
|
-
}
|
|
2164
|
-
}
|
|
2165
|
-
async function splitAndCreate(root, relativePath) {
|
|
2166
|
-
let handle = root;
|
|
2167
|
-
for (const seg of relativePath.split("/")) {
|
|
2168
|
-
if (seg === "" || seg === ".") continue;
|
|
2169
|
-
handle = await handle.getDirectoryHandle(seg, { create: true });
|
|
2170
|
-
}
|
|
2171
|
-
return handle;
|
|
2172
|
-
}
|
|
2173
|
-
var OPFSResource = class {
|
|
2174
|
-
kind = ResourceName86.OPFS;
|
|
2175
|
-
prompt = OPFS_PROMPT;
|
|
2176
|
-
rootName;
|
|
2177
|
-
accessor;
|
|
2178
|
-
rootHandle = null;
|
|
2179
|
-
openPromise = null;
|
|
2180
|
-
constructor(options = {}) {
|
|
2181
|
-
this.rootName = options.root ?? "";
|
|
2182
|
-
this.accessor = new OPFSAccessor(this);
|
|
2183
|
-
}
|
|
2184
|
-
open() {
|
|
2185
|
-
return this.ensureOpen().then(() => void 0);
|
|
2186
|
-
}
|
|
2187
|
-
close() {
|
|
2188
|
-
this.rootHandle = null;
|
|
2189
|
-
this.openPromise = null;
|
|
2190
|
-
return Promise.resolve();
|
|
2191
|
-
}
|
|
2192
|
-
/**
|
|
2193
|
-
* Lazily resolve to a usable root handle. Memoizes `navigator.storage`
|
|
2194
|
-
* traversal so the resource self-initializes on first method call without
|
|
2195
|
-
* relying on an external orchestrator.
|
|
2196
|
-
*/
|
|
2197
|
-
ensureOpen() {
|
|
2198
|
-
if (this.rootHandle !== null) return Promise.resolve(this.rootHandle);
|
|
2199
|
-
this.openPromise ??= (async () => {
|
|
2200
|
-
const origin = await navigator.storage.getDirectory();
|
|
2201
|
-
let handle = origin;
|
|
2202
|
-
for (const seg of this.rootName.split("/")) {
|
|
2203
|
-
if (seg === "" || seg === ".") continue;
|
|
2204
|
-
handle = await handle.getDirectoryHandle(seg, { create: true });
|
|
2205
|
-
}
|
|
2206
|
-
this.rootHandle = handle;
|
|
2207
|
-
return handle;
|
|
2208
|
-
})();
|
|
2209
|
-
return this.openPromise;
|
|
2210
|
-
}
|
|
2211
|
-
requireHandle() {
|
|
2212
|
-
if (this.rootHandle === null) {
|
|
2213
|
-
throw new Error("OPFSResource is not open \u2014 call open() first");
|
|
2214
|
-
}
|
|
2215
|
-
return this.rootHandle;
|
|
2216
|
-
}
|
|
2217
|
-
ops() {
|
|
2218
|
-
return OPFS_OPS;
|
|
2219
|
-
}
|
|
2220
|
-
commands() {
|
|
2221
|
-
return OPFS_COMMANDS;
|
|
2222
|
-
}
|
|
2223
|
-
async *streamPath(p) {
|
|
2224
|
-
await this.ensureOpen();
|
|
2225
|
-
yield* stream(this.accessor, p);
|
|
2226
|
-
}
|
|
2227
|
-
async readFile(p) {
|
|
2228
|
-
await this.ensureOpen();
|
|
2229
|
-
return read(this.accessor, p);
|
|
2230
|
-
}
|
|
2231
|
-
async writeFile(p, data) {
|
|
2232
|
-
await this.ensureOpen();
|
|
2233
|
-
return writeBytes(this.accessor, p, data);
|
|
2234
|
-
}
|
|
2235
|
-
async appendFile(p, data) {
|
|
2236
|
-
await this.ensureOpen();
|
|
2237
|
-
return appendBytes(this.accessor, p, data);
|
|
2238
|
-
}
|
|
2239
|
-
async readdir(p) {
|
|
2240
|
-
await this.ensureOpen();
|
|
2241
|
-
return readdir(this.accessor, p);
|
|
2242
|
-
}
|
|
2243
|
-
async stat(p) {
|
|
2244
|
-
await this.ensureOpen();
|
|
2245
|
-
return stat(this.accessor, p);
|
|
2246
|
-
}
|
|
2247
|
-
async exists(p) {
|
|
2248
|
-
await this.ensureOpen();
|
|
2249
|
-
return exists(this.accessor, p);
|
|
2250
|
-
}
|
|
2251
|
-
async mkdir(p, options) {
|
|
2252
|
-
await this.ensureOpen();
|
|
2253
|
-
return mkdir(this.accessor, p, options?.recursive === true);
|
|
2254
|
-
}
|
|
2255
|
-
async rmdir(p) {
|
|
2256
|
-
await this.ensureOpen();
|
|
2257
|
-
return rmdir(this.accessor, p);
|
|
2258
|
-
}
|
|
2259
|
-
async unlink(p) {
|
|
2260
|
-
await this.ensureOpen();
|
|
2261
|
-
return unlink(this.accessor, p);
|
|
2262
|
-
}
|
|
2263
|
-
async rename(src, dst) {
|
|
2264
|
-
await this.ensureOpen();
|
|
2265
|
-
return rename(this.accessor, src, dst);
|
|
2266
|
-
}
|
|
2267
|
-
async truncate(p, length) {
|
|
2268
|
-
await this.ensureOpen();
|
|
2269
|
-
return truncate(this.accessor, p, length);
|
|
2270
|
-
}
|
|
2271
|
-
async copy(src, dst) {
|
|
2272
|
-
await this.ensureOpen();
|
|
2273
|
-
return copy(this.accessor, src, dst);
|
|
2274
|
-
}
|
|
2275
|
-
async rmR(p) {
|
|
2276
|
-
await this.ensureOpen();
|
|
2277
|
-
return rmR(this.accessor, p);
|
|
2278
|
-
}
|
|
2279
|
-
async du(p) {
|
|
2280
|
-
await this.ensureOpen();
|
|
2281
|
-
return du(this.accessor, p);
|
|
2282
|
-
}
|
|
2283
|
-
async find(p, options = {}) {
|
|
2284
|
-
await this.ensureOpen();
|
|
2285
|
-
return find(this.accessor, p, options);
|
|
2286
|
-
}
|
|
2287
|
-
async glob(paths) {
|
|
2288
|
-
await this.ensureOpen();
|
|
2289
|
-
return globCore(this.accessor, paths);
|
|
2290
|
-
}
|
|
2291
|
-
async getState() {
|
|
2292
|
-
const handle = await this.ensureOpen();
|
|
2293
|
-
const files = {};
|
|
2294
|
-
await walkFiles(handle, "", files);
|
|
2295
|
-
const dirs = [];
|
|
2296
|
-
await walkDirs(handle, "", dirs);
|
|
2297
|
-
dirs.sort();
|
|
2298
|
-
return {
|
|
2299
|
-
type: this.kind,
|
|
2300
|
-
files,
|
|
2301
|
-
dirs
|
|
2302
|
-
};
|
|
2303
|
-
}
|
|
2304
|
-
async loadState(state) {
|
|
2305
|
-
const handle = await this.ensureOpen();
|
|
2306
|
-
for (const dir of state.dirs) {
|
|
2307
|
-
const rel = lstripSlash(dir);
|
|
2308
|
-
if (rel === "") continue;
|
|
2309
|
-
await splitAndCreate(handle, rel);
|
|
2310
|
-
}
|
|
2311
|
-
for (const [rel, data] of Object.entries(state.files)) {
|
|
2312
|
-
const segs = rel.split("/").filter((s) => s !== "" && s !== ".");
|
|
2313
|
-
const fileName = segs.pop();
|
|
2314
|
-
if (fileName === void 0) continue;
|
|
2315
|
-
let dir = handle;
|
|
2316
|
-
for (const seg of segs) {
|
|
2317
|
-
dir = await dir.getDirectoryHandle(seg, { create: true });
|
|
2318
|
-
}
|
|
2319
|
-
const fh = await dir.getFileHandle(fileName, { create: true });
|
|
2320
|
-
const writable = await fh.createWritable();
|
|
2321
|
-
await writable.write(toWritableChunk(data));
|
|
2322
|
-
await writable.close();
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
};
|
|
2326
|
-
|
|
2327
|
-
export {
|
|
2328
|
-
OPFSAccessor,
|
|
2329
|
-
OPFS_COMMANDS,
|
|
2330
|
-
OPFS_OPS,
|
|
2331
|
-
OPFS_PROMPT,
|
|
2332
|
-
OPFSResource
|
|
2333
|
-
};
|
|
2334
|
-
//# sourceMappingURL=chunk-4YUYQTRN.js.map
|