@zenfs/dom 0.0.4 → 0.0.6
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/dist/backends/FileSystemAccess.d.ts +1 -1
- package/dist/backends/FileSystemAccess.js +154 -208
- package/dist/backends/HTTPRequest.d.ts +4 -5
- package/dist/backends/HTTPRequest.js +81 -97
- package/dist/backends/Storage.js +2 -2
- package/dist/backends/Worker.d.ts +4 -5
- package/dist/backends/Worker.js +23 -29
- package/dist/browser.min.js +3 -3
- package/dist/browser.min.js.map +3 -3
- package/dist/fetch.js +20 -33
- package/package.json +2 -2
package/dist/backends/Storage.js
CHANGED
|
@@ -2,7 +2,7 @@ var _a;
|
|
|
2
2
|
import { SyncKeyValueFileSystem, SimpleSyncRWTransaction } from '@zenfs/core/backends/SyncStore.js';
|
|
3
3
|
import { ApiError, ErrorCode } from '@zenfs/core/ApiError.js';
|
|
4
4
|
import { CreateBackend } from '@zenfs/core/backends/backend.js';
|
|
5
|
-
import { encode } from '@zenfs/core/utils.js';
|
|
5
|
+
import { decode, encode } from '@zenfs/core/utils.js';
|
|
6
6
|
/**
|
|
7
7
|
* A synchronous key-value store backed by Storage.
|
|
8
8
|
*/
|
|
@@ -33,7 +33,7 @@ export class StorageStore {
|
|
|
33
33
|
// Don't want to overwrite the key!
|
|
34
34
|
return false;
|
|
35
35
|
}
|
|
36
|
-
this._storage.setItem(key, data
|
|
36
|
+
this._storage.setItem(key, decode(data));
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
catch (e) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { BaseFileSystem, FileContents, FileSystemMetadata } from '@zenfs/core/filesystem.js';
|
|
1
|
+
import { BaseFileSystem, FileSystemMetadata } from '@zenfs/core/filesystem.js';
|
|
3
2
|
import { File, FileFlag } from '@zenfs/core/file.js';
|
|
4
3
|
import { Stats } from '@zenfs/core/stats.js';
|
|
5
4
|
import { Cred } from '@zenfs/core/cred.js';
|
|
@@ -66,9 +65,9 @@ export declare class WorkerFS extends BaseFileSystem {
|
|
|
66
65
|
exists(p: string, cred: Cred): Promise<boolean>;
|
|
67
66
|
realpath(p: string, cred: Cred): Promise<string>;
|
|
68
67
|
truncate(p: string, len: number, cred: Cred): Promise<void>;
|
|
69
|
-
readFile(fname: string,
|
|
70
|
-
writeFile(fname: string, data:
|
|
71
|
-
appendFile(fname: string, data:
|
|
68
|
+
readFile(fname: string, flag: FileFlag, cred: Cred): Promise<Uint8Array>;
|
|
69
|
+
writeFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
|
|
70
|
+
appendFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
|
|
72
71
|
chmod(p: string, mode: number, cred: Cred): Promise<void>;
|
|
73
72
|
chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void>;
|
|
74
73
|
utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void>;
|
package/dist/backends/Worker.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
var _a;
|
|
11
2
|
import { BaseFileSystem } from '@zenfs/core/filesystem.js';
|
|
12
3
|
import { ApiError, ErrorCode } from '@zenfs/core/ApiError.js';
|
|
@@ -75,19 +66,22 @@ export class WorkerFS extends BaseFileSystem {
|
|
|
75
66
|
};
|
|
76
67
|
}
|
|
77
68
|
get metadata() {
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
69
|
+
return {
|
|
70
|
+
...super.metadata,
|
|
71
|
+
...this._metadata,
|
|
72
|
+
name: _a.Name,
|
|
73
|
+
synchronous: false,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async _rpc(method, ...args) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const id = this._currentID++;
|
|
79
|
+
this._requests.set(id, { resolve, reject });
|
|
80
|
+
this._worker.postMessage({
|
|
81
|
+
isBFS: true,
|
|
82
|
+
id,
|
|
83
|
+
method,
|
|
84
|
+
args,
|
|
91
85
|
});
|
|
92
86
|
});
|
|
93
87
|
}
|
|
@@ -121,14 +115,14 @@ export class WorkerFS extends BaseFileSystem {
|
|
|
121
115
|
truncate(p, len, cred) {
|
|
122
116
|
return this._rpc('truncate', p, len, cred);
|
|
123
117
|
}
|
|
124
|
-
readFile(fname,
|
|
125
|
-
return this._rpc('readFile', fname,
|
|
118
|
+
readFile(fname, flag, cred) {
|
|
119
|
+
return this._rpc('readFile', fname, flag, cred);
|
|
126
120
|
}
|
|
127
|
-
writeFile(fname, data,
|
|
128
|
-
return this._rpc('writeFile', fname, data,
|
|
121
|
+
writeFile(fname, data, flag, mode, cred) {
|
|
122
|
+
return this._rpc('writeFile', fname, data, flag, mode, cred);
|
|
129
123
|
}
|
|
130
|
-
appendFile(fname, data,
|
|
131
|
-
return this._rpc('appendFile', fname, data,
|
|
124
|
+
appendFile(fname, data, flag, mode, cred) {
|
|
125
|
+
return this._rpc('appendFile', fname, data, flag, mode, cred);
|
|
132
126
|
}
|
|
133
127
|
chmod(p, mode, cred) {
|
|
134
128
|
return this._rpc('chmod', p, mode, cred);
|
|
@@ -161,7 +155,7 @@ WorkerFS.Options = {
|
|
|
161
155
|
description: 'The target worker that you want to connect to, or the current worker if in a worker context.',
|
|
162
156
|
validator(worker) {
|
|
163
157
|
// Check for a `postMessage` function.
|
|
164
|
-
if (typeof
|
|
158
|
+
if (typeof worker?.postMessage != 'function') {
|
|
165
159
|
throw new ApiError(ErrorCode.EINVAL, 'option must be a Web Worker instance.');
|
|
166
160
|
}
|
|
167
161
|
},
|
package/dist/browser.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ZenFS_DOM=(()=>{var
|
|
2
|
-
Option description: ${
|
|
3
|
-
Option description: ${d.description}`)}}}s=!0})}h(Yt,"checkOptions");var ge=typeof globalThis.setImmediate=="function"?globalThis.setImmediate:o=>setTimeout(o,0),A="/",b=new globalThis.TextEncoder().encode,z=new globalThis.TextDecoder().decode;function nt(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){let e=Math.random()*16|0;return(o==="x"?e:e&3|8).toString(16)})}h(nt,"randomUUID");var l;(function(o){o[o.EPERM=1]="EPERM",o[o.ENOENT=2]="ENOENT",o[o.EIO=5]="EIO",o[o.EBADF=9]="EBADF",o[o.EACCES=13]="EACCES",o[o.EBUSY=16]="EBUSY",o[o.EEXIST=17]="EEXIST",o[o.ENOTDIR=20]="ENOTDIR",o[o.EISDIR=21]="EISDIR",o[o.EINVAL=22]="EINVAL",o[o.EFBIG=27]="EFBIG",o[o.ENOSPC=28]="ENOSPC",o[o.EROFS=30]="EROFS",o[o.ENOTEMPTY=39]="ENOTEMPTY",o[o.ENOTSUP=95]="ENOTSUP"})(l=l||(l={}));var F={};F[l.EPERM]="Operation not permitted.";F[l.ENOENT]="No such file or directory.";F[l.EIO]="Input/output error.";F[l.EBADF]="Bad file descriptor.";F[l.EACCES]="Permission denied.";F[l.EBUSY]="Resource busy or locked.";F[l.EEXIST]="File exists.";F[l.ENOTDIR]="File is not a directory.";F[l.EISDIR]="File is a directory.";F[l.EINVAL]="Invalid argument.";F[l.EFBIG]="File is too big.";F[l.ENOSPC]="No space left on disk.";F[l.EROFS]="Cannot modify a read-only file system.";F[l.ENOTEMPTY]="Directory is not empty.";F[l.ENOTSUP]="Operation is not supported.";var c=class extends Error{static fromJSON(e){let t=new c(e.errno,e.message,e.path);return t.code=e.code,t.stack=e.stack,t}static Derserialize(e,t=0){let i=new DataView("buffer"in e?e.buffer:e),r=z(i.buffer.slice(t+4,t+4+i.getUint32(t,!0)));return c.fromJSON(JSON.parse(r))}static FileError(e,t){return new c(e,F[e],t)}static EACCES(e){return this.FileError(l.EACCES,e)}static ENOENT(e){return this.FileError(l.ENOENT,e)}static EEXIST(e){return this.FileError(l.EEXIST,e)}static EISDIR(e){return this.FileError(l.EISDIR,e)}static ENOTDIR(e){return this.FileError(l.ENOTDIR,e)}static EPERM(e){return this.FileError(l.EPERM,e)}static ENOTEMPTY(e){return this.FileError(l.ENOTEMPTY,e)}constructor(e,t=F[e],i){super(t),this.syscall="",this.errno=e,this.code=l[e],this.path=i,this.message=`Error: ${this.code}: ${t}${this.path?`, '${this.path}'`:""}`}toString(){return this.message}toJSON(){return{errno:this.errno,code:this.code,path:this.path,stack:this.stack,message:this.message}}serialize(e=new Uint8Array(this.bufferSize()),t=0){let i=new DataView("buffer"in e?e.buffer:e),r=new Uint8Array(i.buffer),n=b(JSON.stringify(this.toJSON()));return r.set(n),i.setUint32(t,n.byteLength,!0),r}bufferSize(){return 4+JSON.stringify(this.toJSON()).length}};h(c,"ApiError");var k=class{constructor(e,t,i,r,n,s){this.uid=e,this.gid=t,this.suid=i,this.sgid=r,this.euid=n,this.egid=s}};h(k,"Cred");k.Root=new k(0,0,0,0,0,0);var E;(function(o){o[o.FILE=32768]="FILE",o[o.DIRECTORY=16384]="DIRECTORY",o[o.SYMLINK=40960]="SYMLINK"})(E=E||(E={}));var O=class{static Deserialize(e){let t=new DataView("buffer"in e?e.buffer:e),i=t.getUint32(0,!0),r=t.getUint32(4,!0),n=t.getFloat64(8,!0),s=t.getFloat64(16,!0),a=t.getFloat64(24,!0),d=t.getUint32(32,!0),f=t.getUint32(36,!0);return new O(r&61440,i,r&-61441,n,s,a,d,f)}static clone(e){return new O(e.mode&61440,e.size,e.mode&-61441,e.atimeMs,e.mtimeMs,e.ctimeMs,e.uid,e.gid,e.birthtimeMs)}get atime(){return new Date(this.atimeMs)}get mtime(){return new Date(this.mtimeMs)}get ctime(){return new Date(this.ctimeMs)}get birthtime(){return new Date(this.birthtimeMs)}constructor(e,t,i,r,n,s,a,d,f){this.dev=0,this.ino=0,this.rdev=0,this.nlink=1,this.blksize=4096,this.uid=0,this.gid=0,this.fileData=null,this.size=t;let u=0;if(typeof r!="number"&&(u=Date.now(),r=u),typeof n!="number"&&(u||(u=Date.now()),n=u),typeof s!="number"&&(u||(u=Date.now()),s=u),typeof f!="number"&&(u||(u=Date.now()),f=u),typeof a!="number"&&(a=0),typeof d!="number"&&(d=0),this.atimeMs=r,this.ctimeMs=s,this.mtimeMs=n,this.birthtimeMs=f,i)this.mode=i;else switch(e){case E.FILE:this.mode=420;break;case E.DIRECTORY:default:this.mode=511}this.blocks=Math.ceil(t/512),this.mode&61440||(this.mode|=e)}serialize(){let e=new Uint8Array(32),t=new DataView(e.buffer);return t.setUint32(0,this.size,!0),t.setUint32(4,this.mode,!0),t.setFloat64(8,this.atime.getTime(),!0),t.setFloat64(16,this.mtime.getTime(),!0),t.setFloat64(24,this.ctime.getTime(),!0),t.setUint32(32,this.uid,!0),t.setUint32(36,this.gid,!0),e}isFile(){return(this.mode&61440)===32768}isDirectory(){return(this.mode&61440)===16384}isSymbolicLink(){return(this.mode&61440)===40960}hasAccess(e,t){if(t.euid===0||t.egid===0)return!0;let i=this.mode&-61441,r=15,n=15,s=15;if(t.euid==this.uid){let f=(3840&i)>>8;r=(e^f)&e}if(t.egid==this.gid){let f=(240&i)>>4;n=(e^f)&e}let a=15&i;return s=(e^a)&e,!(r&n&s)}getCred(e=this.uid,t=this.gid){return new k(e,t,this.uid,this.gid,e,t)}chmod(e){this.mode=this.mode&61440|e}chown(e,t){!isNaN(+e)&&0<=+e&&+e<Math.pow(2,32)&&(this.uid=e),!isNaN(+t)&&0<=+t&&+t<Math.pow(2,32)&&(this.gid=t)}isSocket(){return!1}isBlockDevice(){return!1}isCharacterDevice(){return!1}isFIFO(){return!1}};h(O,"Stats");var y=function(o,e,t,i){function r(n){return n instanceof t?n:new t(function(s){s(n)})}return h(r,"adopt"),new(t||(t=Promise))(function(n,s){function a(u){try{f(i.next(u))}catch(m){s(m)}}h(a,"fulfilled");function d(u){try{f(i.throw(u))}catch(m){s(m)}}h(d,"rejected");function f(u){u.done?n(u.value):r(u.value).then(a,d)}h(f,"step"),f((i=i.apply(o,e||[])).next())})},Jt,vt=class{constructor(e){}};h(vt,"FileSystem");var T=class extends vt{constructor(e){super(),this._ready=Promise.resolve(this)}get metadata(){return{name:this.constructor.name,readonly:!1,synchronous:!1,supportsProperties:!1,supportsLinks:!1,totalSpace:0,freeSpace:0}}whenReady(){return this._ready}openFile(e,t,i){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}createFile(e,t,i,r){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}open(e,t,i,r){return y(this,void 0,void 0,function*(){try{let n=yield this.stat(e,r);switch(t.pathExistsAction()){case v.THROW_EXCEPTION:throw c.EEXIST(e);case v.TRUNCATE_FILE:let s=yield this.openFile(e,t,r);if(!s)throw new Error("BFS has reached an impossible code path; please file a bug.");return yield s.truncate(0),yield s.sync(),s;case v.NOP:return this.openFile(e,t,r);default:throw new c(l.EINVAL,"Invalid FileFlag object.")}}catch(n){switch(t.pathNotExistsAction()){case v.CREATE_FILE:let s=yield this.stat(g(e),r);if(s&&!s.isDirectory())throw c.ENOTDIR(g(e));return this.createFile(e,t,i,r);case v.THROW_EXCEPTION:throw c.ENOENT(e);default:throw new c(l.EINVAL,"Invalid FileFlag object.")}}})}access(e,t,i){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}accessSync(e,t,i){throw new c(l.ENOTSUP)}rename(e,t,i){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}renameSync(e,t,i){throw new c(l.ENOTSUP)}stat(e,t){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}statSync(e,t){throw new c(l.ENOTSUP)}openFileSync(e,t,i){throw new c(l.ENOTSUP)}createFileSync(e,t,i,r){throw new c(l.ENOTSUP)}openSync(e,t,i,r){let n;try{n=this.statSync(e,r)}catch(s){switch(t.pathNotExistsAction()){case v.CREATE_FILE:if(!this.statSync(g(e),r).isDirectory())throw c.ENOTDIR(g(e));return this.createFileSync(e,t,i,r);case v.THROW_EXCEPTION:throw c.ENOENT(e);default:throw new c(l.EINVAL,"Invalid FileFlag object.")}}if(!n.hasAccess(i,r))throw c.EACCES(e);switch(t.pathExistsAction()){case v.THROW_EXCEPTION:throw c.EEXIST(e);case v.TRUNCATE_FILE:return this.unlinkSync(e,r),this.createFileSync(e,t,n.mode,r);case v.NOP:return this.openFileSync(e,t,r);default:throw new c(l.EINVAL,"Invalid FileFlag object.")}}unlink(e,t){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}unlinkSync(e,t){throw new c(l.ENOTSUP)}rmdir(e,t){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}rmdirSync(e,t){throw new c(l.ENOTSUP)}mkdir(e,t,i){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}mkdirSync(e,t,i){throw new c(l.ENOTSUP)}readdir(e,t){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}readdirSync(e,t){throw new c(l.ENOTSUP)}exists(e,t){return y(this,void 0,void 0,function*(){try{return yield this.stat(e,t),!0}catch(i){return!1}})}existsSync(e,t){try{return this.statSync(e,t),!0}catch(i){return!1}}realpath(e,t){return y(this,void 0,void 0,function*(){if(this.metadata.supportsLinks){let i=e.split(W);for(let r=0;r<i.length;r++){let n=i.slice(0,r+1);i[r]=C(...n)}return i.join(W)}else{if(!(yield this.exists(e,t)))throw c.ENOENT(e);return e}})}realpathSync(e,t){if(this.metadata.supportsLinks){let i=e.split(W);for(let r=0;r<i.length;r++){let n=i.slice(0,r+1);i[r]=C(...n)}return i.join(W)}else{if(this.existsSync(e,t))return e;throw c.ENOENT(e)}}truncate(e,t,i){return y(this,void 0,void 0,function*(){let r=yield this.open(e,_.getFileFlag("r+"),420,i);try{yield r.truncate(t)}finally{yield r.close()}})}truncateSync(e,t,i){let r=this.openSync(e,_.getFileFlag("r+"),420,i);try{r.truncateSync(t)}finally{r.closeSync()}}readFile(e,t,i,r){return y(this,void 0,void 0,function*(){let n=yield this.open(e,i,420,r);try{let s=yield n.stat(),a=new Uint8Array(s.size);return yield n.read(a,0,s.size,0),yield n.close(),t===null?a:z(a)}finally{yield n.close()}})}readFileSync(e,t,i,r){let n=this.openSync(e,i,420,r);try{let s=n.statSync(),a=new Uint8Array(s.size);return n.readSync(a,0,s.size,0),n.closeSync(),t===null?a:z(a)}finally{n.closeSync()}}writeFile(e,t,i,r,n,s){return y(this,void 0,void 0,function*(){let a=yield this.open(e,r,n,s);try{typeof t=="string"&&(t=b(t)),yield a.write(t,0,t.length,0)}finally{yield a.close()}})}writeFileSync(e,t,i,r,n,s){let a=this.openSync(e,r,n,s);try{typeof t=="string"&&(t=b(t)),a.writeSync(t,0,t.length,0)}finally{a.closeSync()}}appendFile(e,t,i,r,n,s){return y(this,void 0,void 0,function*(){let a=yield this.open(e,r,n,s);try{typeof t=="string"&&(t=b(t)),yield a.write(t,0,t.length,null)}finally{yield a.close()}})}appendFileSync(e,t,i,r,n,s){let a=this.openSync(e,r,n,s);try{typeof t=="string"&&(t=b(t)),a.writeSync(t,0,t.length,null)}finally{a.closeSync()}}chmod(e,t,i){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}chmodSync(e,t,i){throw new c(l.ENOTSUP)}chown(e,t,i,r){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}chownSync(e,t,i,r){throw new c(l.ENOTSUP)}utimes(e,t,i,r){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}utimesSync(e,t,i,r){throw new c(l.ENOTSUP)}link(e,t,i){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}linkSync(e,t,i){throw new c(l.ENOTSUP)}symlink(e,t,i,r){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}symlinkSync(e,t,i,r){throw new c(l.ENOTSUP)}readlink(e,t){return y(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}readlinkSync(e,t){throw new c(l.ENOTSUP)}};h(T,"BaseFileSystem");Jt=T;T.Name=Jt.name;var dt=class extends T{get metadata(){return Object.assign(Object.assign({},super.metadata),{synchronous:!0})}access(e,t,i){return y(this,void 0,void 0,function*(){return this.accessSync(e,t,i)})}rename(e,t,i){return y(this,void 0,void 0,function*(){return this.renameSync(e,t,i)})}stat(e,t){return y(this,void 0,void 0,function*(){return this.statSync(e,t)})}open(e,t,i,r){return y(this,void 0,void 0,function*(){return this.openSync(e,t,i,r)})}unlink(e,t){return y(this,void 0,void 0,function*(){return this.unlinkSync(e,t)})}rmdir(e,t){return y(this,void 0,void 0,function*(){return this.rmdirSync(e,t)})}mkdir(e,t,i){return y(this,void 0,void 0,function*(){return this.mkdirSync(e,t,i)})}readdir(e,t){return y(this,void 0,void 0,function*(){return this.readdirSync(e,t)})}chmod(e,t,i){return y(this,void 0,void 0,function*(){return this.chmodSync(e,t,i)})}chown(e,t,i,r){return y(this,void 0,void 0,function*(){return this.chownSync(e,t,i,r)})}utimes(e,t,i,r){return y(this,void 0,void 0,function*(){return this.utimesSync(e,t,i,r)})}link(e,t,i){return y(this,void 0,void 0,function*(){return this.linkSync(e,t,i)})}symlink(e,t,i,r){return y(this,void 0,void 0,function*(){return this.symlinkSync(e,t,i,r)})}readlink(e,t){return y(this,void 0,void 0,function*(){return this.readlinkSync(e,t)})}};h(dt,"SynchronousFileSystem");var D=class{static Deserialize(e){let t=new DataView("buffer"in e?e.buffer:e);return new D(z(t.buffer.slice(38)),t.getUint32(0,!0),t.getUint16(4,!0),t.getFloat64(6,!0),t.getFloat64(14,!0),t.getFloat64(22,!0),t.getUint32(30,!0),t.getUint32(34,!0))}constructor(e,t,i,r,n,s,a,d){this.id=e,this.size=t,this.mode=i,this.atime=r,this.mtime=n,this.ctime=s,this.uid=a,this.gid=d}toStats(){return new O((this.mode&61440)===E.DIRECTORY?E.DIRECTORY:E.FILE,this.size,this.mode,this.atime,this.mtime,this.ctime,this.uid,this.gid)}getSize(){return 38+this.id.length}serialize(e=new Uint8Array(this.getSize())){let t=new DataView("buffer"in e?e.buffer:e);t.setUint32(0,this.size,!0),t.setUint16(4,this.mode,!0),t.setFloat64(6,this.atime,!0),t.setFloat64(14,this.mtime,!0),t.setFloat64(22,this.ctime,!0),t.setUint32(30,this.uid,!0),t.setUint32(34,this.gid,!0);let i=new Uint8Array(t.buffer);return i.set(b(this.id),38),i}update(e){let t=!1;this.size!==e.size&&(this.size=e.size,t=!0),this.mode!==e.mode&&(this.mode=e.mode,t=!0);let i=e.atime.getTime();this.atime!==i&&(this.atime=i,t=!0);let r=e.mtime.getTime();this.mtime!==r&&(this.mtime=r,t=!0);let n=e.ctime.getTime();return this.ctime!==n&&(this.ctime=n,t=!0),this.uid!==e.uid&&(this.uid=e.uid,t=!0),this.uid!==e.uid&&(this.uid=e.uid,t=!0),t}isFile(){return(this.mode&61440)===E.FILE}isDirectory(){return(this.mode&61440)===E.DIRECTORY}};h(D,"Inode");var q=class{constructor(e){this.store=e,this.originalData={},this.modifiedKeys=[]}get(e){let t=this.store.get(e);return this.stashOldValue(e,t),t}put(e,t,i){return this.markModified(e),this.store.put(e,t,i)}del(e){this.markModified(e),this.store.del(e)}commit(){}abort(){for(let e of this.modifiedKeys){let t=this.originalData[e];t?this.store.put(e,t,!0):this.store.del(e)}}_has(e){return Object.prototype.hasOwnProperty.call(this.originalData,e)}stashOldValue(e,t){this._has(e)||(this.originalData[e]=t)}markModified(e){this.modifiedKeys.indexOf(e)===-1&&(this.modifiedKeys.push(e),this._has(e)||(this.originalData[e]=this.store.get(e)))}};h(q,"SimpleSyncRWTransaction");var ut=class extends L{constructor(e,t,i,r,n){super(e,t,i,r,n)}syncSync(){this.isDirty()&&(this._fs._syncSync(this.getPath(),this.getBuffer(),this.getStats()),this.resetDirty())}closeSync(){this.syncSync()}};h(ut,"SyncKeyValueFile");var X=class extends dt{static isAvailable(){return!0}constructor(e){super(),this.store=e.store,this.makeRootDirectory()}getName(){return this.store.name()}isReadOnly(){return!1}supportsSymlinks(){return!1}supportsProps(){return!0}supportsSynch(){return!0}empty(){this.store.clear(),this.makeRootDirectory()}accessSync(e,t,i){let r=this.store.beginTransaction("readonly");if(!this.findINode(r,e).toStats().hasAccess(t,i))throw c.EACCES(e)}renameSync(e,t,i){let r=this.store.beginTransaction("readwrite"),n=g(e),s=I(e),a=g(t),d=I(t),f=this.findINode(r,n),u=this.getDirListing(r,n,f);if(!f.toStats().hasAccess(2,i))throw c.EACCES(e);if(!u[s])throw c.ENOENT(e);let m=u[s];if(delete u[s],(a+"/").indexOf(e+"/")===0)throw new c(l.EBUSY,n);let p,w;if(a===n?(p=f,w=u):(p=this.findINode(r,a),w=this.getDirListing(r,a,p)),w[d]){let x=this.getINode(r,t,w[d]);if(x.isFile())try{r.del(x.id),r.del(w[d])}catch(B){throw r.abort(),B}else throw c.EPERM(t)}w[d]=m;try{r.put(f.id,b(JSON.stringify(u)),!0),r.put(p.id,b(JSON.stringify(w)),!0)}catch(x){throw r.abort(),x}r.commit()}statSync(e,t){let i=this.findINode(this.store.beginTransaction("readonly"),e).toStats();if(!i.hasAccess(4,t))throw c.EACCES(e);return i}createFileSync(e,t,i,r){let n=this.store.beginTransaction("readwrite"),s=new Uint8Array(0),a=this.commitNewFile(n,e,E.FILE,i,r,s);return new ut(this,e,t,a.toStats(),s)}openFileSync(e,t,i){let r=this.store.beginTransaction("readonly"),n=this.findINode(r,e),s=r.get(n.id);if(!n.toStats().hasAccess(t.getMode(),i))throw c.EACCES(e);if(s===void 0)throw c.ENOENT(e);return new ut(this,e,t,n.toStats(),s)}unlinkSync(e,t){this.removeEntry(e,!1,t)}rmdirSync(e,t){if(this.readdirSync(e,t).length>0)throw c.ENOTEMPTY(e);this.removeEntry(e,!0,t)}mkdirSync(e,t,i){let r=this.store.beginTransaction("readwrite"),n=b("{}");this.commitNewFile(r,e,E.DIRECTORY,t,i,n)}readdirSync(e,t){let i=this.store.beginTransaction("readonly"),r=this.findINode(i,e);if(!r.toStats().hasAccess(4,t))throw c.EACCES(e);return Object.keys(this.getDirListing(i,e,r))}chmodSync(e,t,i){this.openFileSync(e,_.getFileFlag("r+"),i).chmodSync(t)}chownSync(e,t,i,r){this.openFileSync(e,_.getFileFlag("r+"),r).chownSync(t,i)}_syncSync(e,t,i){let r=this.store.beginTransaction("readwrite"),n=this._findINode(r,g(e),I(e)),s=this.getINode(r,e,n),a=s.update(i);try{r.put(s.id,t,!0),a&&r.put(n,s.serialize(),!0)}catch(d){throw r.abort(),d}r.commit()}makeRootDirectory(){let e=this.store.beginTransaction("readwrite");if(e.get(A)===void 0){let t=new Date().getTime(),i=new D(nt(),4096,511|E.DIRECTORY,t,t,t,0,0);e.put(i.id,b("{}"),!1),e.put(A,i.serialize(),!1),e.commit()}}_findINode(e,t,i,r=new Set){let n=C(t,i);if(r.has(n))throw new c(l.EIO,"Infinite loop detected while finding inode",n);r.add(n);let s=h(a=>{let d=this.getDirListing(e,t,a);if(d[i])return d[i];throw c.ENOENT(Y(t,i))},"readDirectory");return t==="/"?i===""?A:s(this.getINode(e,t,A)):s(this.getINode(e,t+W+i,this._findINode(e,g(t),I(t),r)))}findINode(e,t){return this.getINode(e,t,this._findINode(e,g(t),I(t)))}getINode(e,t,i){let r=e.get(i);if(r===void 0)throw c.ENOENT(t);return D.Deserialize(r)}getDirListing(e,t,i){if(!i.isDirectory())throw c.ENOTDIR(t);let r=e.get(i.id);if(r===void 0)throw c.ENOENT(t);return JSON.parse(r.toString())}addNewNode(e,t){let r;for(;0<5;)try{return r=nt(),e.put(r,t,!1),r}catch(n){}throw new c(l.EIO,"Unable to commit data to key-value store.")}commitNewFile(e,t,i,r,n,s){let a=g(t),d=I(t),f=this.findINode(e,a),u=this.getDirListing(e,a,f),m=new Date().getTime();if(!f.toStats().hasAccess(4,n))throw c.EACCES(t);if(t==="/")throw c.EEXIST(t);if(u[d])throw c.EEXIST(t);let p;try{let w=this.addNewNode(e,s);p=new D(w,s.length,r|i,m,m,m,n.uid,n.gid);let x=this.addNewNode(e,p.serialize());u[d]=x,e.put(f.id,b(JSON.stringify(u)),!0)}catch(w){throw e.abort(),w}return e.commit(),p}removeEntry(e,t,i){let r=this.store.beginTransaction("readwrite"),n=g(e),s=this.findINode(r,n),a=this.getDirListing(r,n,s),d=I(e);if(!a[d])throw c.ENOENT(e);let f=a[d],u=this.getINode(r,e,f);if(!u.toStats().hasAccess(2,i))throw c.EACCES(e);if(delete a[d],!t&&u.isDirectory())throw c.EISDIR(e);if(t&&!u.isDirectory())throw c.ENOTDIR(e);try{r.del(u.id),r.del(f),r.put(s.id,b(JSON.stringify(a)),!0)}catch(m){throw r.abort(),m}r.commit()}};h(X,"SyncKeyValueFileSystem");function R(o,e){e=typeof o=="function"?o:e,Yt(this,o);let t=new this(typeof o=="function"?{}:o);if(typeof e!="function")return t.whenReady();t.whenReady().then(i=>e(null,i)).catch(i=>e(i))}h(R,"CreateBackend");var Gt,Ot=class{constructor(){this.store=new Map}name(){return M.Name}clear(){this.store.clear()}beginTransaction(e){return new q(this)}get(e){return this.store.get(e)}put(e,t,i){return!i&&this.store.has(e)?!1:(this.store.set(e,t),!0)}del(e){this.store.delete(e)}};h(Ot,"InMemoryStore");var M=class extends X{constructor(){super({store:new Ot})}};h(M,"InMemoryFileSystem");Gt=M;M.Name="InMemory";M.Create=R.bind(Gt);M.Options={};var ai=k.Root;var Ut=new Map;M.Create().then(o=>he("/",o));function _t(o){return Ut.get(o)}h(_t,"getMount");function he(o,e){if(o[0]!=="/"&&(o="/"+o),o=Y(o),Ut.has(o))throw new c(l.EINVAL,"Mount point "+o+" is already in use.");Ut.set(o,e)}h(he,"mount");var P=function(o,e,t,i){function r(n){return n instanceof t?n:new t(function(s){s(n)})}return h(r,"adopt"),new(t||(t=Promise))(function(n,s){function a(u){try{f(i.next(u))}catch(m){s(m)}}h(a,"fulfilled");function d(u){try{f(i.throw(u))}catch(m){s(m)}}h(d,"rejected");function f(u){u.done?n(u.value):r(u.value).then(a,d)}h(f,"step"),f((i=i.apply(o,e||[])).next())})},v;(function(o){o[o.NOP=0]="NOP",o[o.THROW_EXCEPTION=1]="THROW_EXCEPTION",o[o.TRUNCATE_FILE=2]="TRUNCATE_FILE",o[o.CREATE_FILE=3]="CREATE_FILE"})(v=v||(v={}));var _=class{static getFileFlag(e){return _.flagCache.has(e)||_.flagCache.set(e,new _(e)),_.flagCache.get(e)}constructor(e){if(this.flagStr=e,_.validFlagStrs.indexOf(e)<0)throw new c(l.EINVAL,"Invalid flag: "+e)}getFlagString(){return this.flagStr}getMode(){let e=0;return e<<=1,e+=+this.isReadable(),e<<=1,e+=+this.isWriteable(),e<<=1,e}isReadable(){return this.flagStr.indexOf("r")!==-1||this.flagStr.indexOf("+")!==-1}isWriteable(){return this.flagStr.indexOf("w")!==-1||this.flagStr.indexOf("a")!==-1||this.flagStr.indexOf("+")!==-1}isTruncating(){return this.flagStr.indexOf("w")!==-1}isAppendable(){return this.flagStr.indexOf("a")!==-1}isSynchronous(){return this.flagStr.indexOf("s")!==-1}isExclusive(){return this.flagStr.indexOf("x")!==-1}pathExistsAction(){return this.isExclusive()?v.THROW_EXCEPTION:this.isTruncating()?v.TRUNCATE_FILE:v.NOP}pathNotExistsAction(){return(this.isWriteable()||this.isAppendable())&&this.flagStr!=="r+"?v.CREATE_FILE:v.THROW_EXCEPTION}};h(_,"FileFlag");_.flagCache=new Map;_.validFlagStrs=["r","r+","rs","rs+","w","wx","w+","wx+","a","ax","a+","ax+"];var It=class{sync(){return P(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}syncSync(){throw new c(l.ENOTSUP)}datasync(){return P(this,void 0,void 0,function*(){return this.sync()})}datasyncSync(){return this.syncSync()}chown(e,t){return P(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}chownSync(e,t){throw new c(l.ENOTSUP)}chmod(e){return P(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}chmodSync(e){throw new c(l.ENOTSUP)}utimes(e,t){return P(this,void 0,void 0,function*(){throw new c(l.ENOTSUP)})}utimesSync(e,t){throw new c(l.ENOTSUP)}};h(It,"BaseFile");var L=class extends It{constructor(e,t,i,r,n){if(super(),this._pos=0,this._dirty=!1,this._fs=e,this._path=t,this._flag=i,this._stat=r,this._buffer=n||new Uint8Array(0),this._stat.size!==this._buffer.length&&this._flag.isReadable())throw new Error(`Invalid buffer: Uint8Array is ${this._buffer.length} long, yet Stats object specifies that file is ${this._stat.size} long.`)}getBuffer(){return this._buffer}getStats(){return this._stat}getFlag(){return this._flag}getPath(){return this._path}getPos(){return this._flag.isAppendable()?this._stat.size:this._pos}advancePos(e){return this._pos+=e}setPos(e){return this._pos=e}sync(){return P(this,void 0,void 0,function*(){this.syncSync()})}syncSync(){throw new c(l.ENOTSUP)}close(){return P(this,void 0,void 0,function*(){this.closeSync()})}closeSync(){throw new c(l.ENOTSUP)}stat(){return P(this,void 0,void 0,function*(){return O.clone(this._stat)})}statSync(){return O.clone(this._stat)}truncate(e){if(this.truncateSync(e),this._flag.isSynchronous()&&!_t("/").metadata.synchronous)return this.sync()}truncateSync(e){if(this._dirty=!0,!this._flag.isWriteable())throw new c(l.EPERM,"File not opened with a writeable mode.");if(this._stat.mtimeMs=Date.now(),e>this._buffer.length){let t=new Uint8Array(e-this._buffer.length);this.writeSync(t,0,t.length,this._buffer.length),this._flag.isSynchronous()&&_t("/").metadata.synchronous&&this.syncSync();return}this._stat.size=e,this._buffer=this._buffer.subarray(0,e),this._flag.isSynchronous()&&_t("/").metadata.synchronous&&this.syncSync()}write(e,t,i,r){return P(this,void 0,void 0,function*(){return this.writeSync(e,t,i,r)})}writeSync(e,t,i,r){if(this._dirty=!0,r==null&&(r=this.getPos()),!this._flag.isWriteable())throw new c(l.EPERM,"File not opened with a writeable mode.");let n=r+i;if(n>this._stat.size&&(this._stat.size=n,n>this._buffer.length)){let a=new Uint8Array(n);a.set(this._buffer),this._buffer=a}this._buffer.set(e.slice(t,t+i),r);let s=this._buffer.length;return this._stat.mtimeMs=Date.now(),this._flag.isSynchronous()?(this.syncSync(),s):(this.setPos(r+s),s)}read(e,t,i,r){return P(this,void 0,void 0,function*(){return{bytesRead:this.readSync(e,t,i,r),buffer:e}})}readSync(e,t,i,r){if(!this._flag.isReadable())throw new c(l.EPERM,"File not opened with a readable mode.");return r==null&&(r=this.getPos()),r+i>this._stat.size&&(i=this._stat.size-r),this._buffer.set(e.slice(t,t+i),r),this._stat.atimeMs=Date.now(),this._pos=r+i,this._buffer.length}chmod(e){return P(this,void 0,void 0,function*(){this.chmodSync(e)})}chmodSync(e){if(!this._fs.metadata.supportsProperties)throw new c(l.ENOTSUP);this._dirty=!0,this._stat.chmod(e),this.syncSync()}chown(e,t){return P(this,void 0,void 0,function*(){this.chownSync(e,t)})}chownSync(e,t){if(!this._fs.metadata.supportsProperties)throw new c(l.ENOTSUP);this._dirty=!0,this._stat.chown(e,t),this.syncSync()}isDirty(){return this._dirty}resetDirty(){this._dirty=!1}};h(L,"PreloadFile");var J=class extends L{constructor(e,t,i,r,n){super(e,t,i,r,n)}sync(){return P(this,void 0,void 0,function*(){})}syncSync(){}close(){return P(this,void 0,void 0,function*(){})}closeSync(){}};h(J,"NoSyncFile");var Ft=h((o="",e)=>{throw e.name==="NotFoundError"?c.ENOENT(o):e},"handleError"),ht=class extends L{constructor(e,t,i,r,n){super(e,t,i,r,n)}sync(){return S(this,null,function*(){this.isDirty()&&(yield this._fs._sync(this.getPath(),this.getBuffer(),this.getStats(),k.Root),this.resetDirty())})}close(){return S(this,null,function*(){yield this.sync()})}};h(ht,"FileSystemAccessFile");var Tt=class extends T{constructor({handle:t}){super();this._handles=new Map;this._handles.set("/",t)}static isAvailable(){return typeof FileSystemHandle=="function"}get metadata(){return it($({},super.metadata),{name:Tt.Name})}_sync(t,i,r,n){return S(this,null,function*(){let s=yield this.stat(t,n);r.mtime!==s.mtime&&(yield this.writeFile(t,i,null,_.getFileFlag("w"),s.mode,n))})}rename(t,i,r){return S(this,null,function*(){try{let n=yield this.getHandle(t);if(n instanceof FileSystemDirectoryHandle){let s=yield this.readdir(t,r);if(yield this.mkdir(i,"wx",r),s.length===0)yield this.unlink(t,r);else for(let a of s)yield this.rename(C(t,a),C(i,a),r),yield this.unlink(t,r)}if(n instanceof FileSystemFileHandle){let s=yield n.getFile(),a=yield this.getHandle(g(i));if(a instanceof FileSystemDirectoryHandle){let f=yield(yield a.getFileHandle(I(i),{create:!0})).createWritable(),u=yield s.arrayBuffer();yield f.write(u),f.close(),yield this.unlink(t,r)}}}catch(n){Ft(t,n)}})}writeFile(t,i,r,n,s,a,d){return S(this,null,function*(){let f=yield this.getHandle(g(t));if(f instanceof FileSystemDirectoryHandle){let m=yield(yield f.getFileHandle(I(t),{create:!0})).createWritable();yield m.write(i),yield m.close()}})}createFile(t,i,r,n){return S(this,null,function*(){return yield this.writeFile(t,new Uint8Array,null,i,r,n,!0),this.openFile(t,i,n)})}stat(t,i){return S(this,null,function*(){let r=yield this.getHandle(t);if(!r)throw c.FileError(l.EINVAL,t);if(r instanceof FileSystemDirectoryHandle)return new O(E.DIRECTORY,4096);if(r instanceof FileSystemFileHandle){let{lastModified:n,size:s}=yield r.getFile();return new O(E.FILE,s,void 0,void 0,n)}})}exists(t,i){return S(this,null,function*(){try{return yield this.getHandle(t),!0}catch(r){return!1}})}openFile(t,i,r){return S(this,null,function*(){let n=yield this.getHandle(t);if(n instanceof FileSystemFileHandle){let s=yield n.getFile(),a=yield s.arrayBuffer();return this.newFile(t,i,a,s.size,s.lastModified)}})}unlink(t,i){return S(this,null,function*(){let r=yield this.getHandle(g(t));if(r instanceof FileSystemDirectoryHandle)try{yield r.removeEntry(I(t),{recursive:!0})}catch(n){Ft(t,n)}})}rmdir(t,i){return S(this,null,function*(){return this.unlink(t,i)})}mkdir(t,i,r){return S(this,null,function*(){let n=i&&i.flag&&i.flag.includes("w")&&!i.flag.includes("x");if((yield this.getHandle(t))&&!n)throw c.EEXIST(t);let a=yield this.getHandle(g(t));a instanceof FileSystemDirectoryHandle&&(yield a.getDirectoryHandle(I(t),{create:!0}))})}readdir(t,i){return S(this,null,function*(){let r=yield this.getHandle(t);if(!(r instanceof FileSystemDirectoryHandle))throw c.ENOTDIR(t);let n=[];try{for(var s=$t(r.keys()),a,d,f;a=!(d=yield s.next()).done;a=!1){let u=d.value;n.push(C(t,u))}}catch(d){f=[d]}finally{try{a&&(d=s.return)&&(yield d.call(s))}finally{if(f)throw f[0]}}return n})}newFile(t,i,r,n,s){return new ht(this,t,i,new O(E.FILE,n||0,void 0,void 0,s||new Date().getTime()),new Uint8Array(r))}getHandle(t){return S(this,null,function*(){if(this._handles.has(t))return this._handles.get(t);let i="/",[,...r]=t.split("/"),n=h(d=>S(this,[d],function*([s,...a]){let f=C(i,s),u=h(p=>{if(i=f,this._handles.set(i,p),a.length===0)return this._handles.get(t);n(a)},"continueWalk"),m=this._handles.get(i);try{return yield u(yield m.getDirectoryHandle(s))}catch(p){if(p.name==="TypeMismatchError")try{return yield u(yield m.getFileHandle(s))}catch(w){Ft(f,w)}else{if(p.message==="Name is not allowed.")throw new c(l.ENOENT,p.message,f);Ft(f,p)}}}),"getHandleParts");yield n(r)})}},G=Tt;h(G,"FileSystemAccessFileSystem"),G.Name="FileSystemAccess",G.Create=R.bind(Tt),G.Options={};var Qt=typeof fetch!="undefined"&&fetch!==null;function Dt(o){throw new c(l.EIO,o.message)}h(Dt,"convertError");function Lt(o,e){return S(this,null,function*(){let t=yield fetch(o).catch(Dt);if(!t.ok)throw new c(l.EIO,`fetch error: response returned code ${t.status}`);switch(e){case"buffer":let i=yield t.arrayBuffer().catch(Dt);return new Uint8Array(i);case"json":return t.json().catch(Dt);default:throw new c(l.EINVAL,"Invalid download type: "+e)}})}h(Lt,"fetchFile");function Zt(o){return S(this,null,function*(){let e=yield fetch(o,{method:"HEAD"}).catch(Dt);if(!e.ok)throw new c(l.EIO,`fetch HEAD error: response returned code ${e.status}`);return parseInt(e.headers.get("Content-Length")||"-1",10)})}h(Zt,"fetchFileSize");var Q=class{static fromListing(e){let t=new Q,i=new H;t._index["/"]=i;let r=[["",e,i]];for(;r.length>0;){let n,s=r.pop(),a=s[0],d=s[1],f=s[2];for(let u in d)if(Object.prototype.hasOwnProperty.call(d,u)){let m=d[u],p=`${a}/${u}`;m?(t._index[p]=n=new H,r.push([p,m,n])):n=new Pt(new O(E.FILE,-1,365)),f&&(f._ls[u]=n)}}return t}constructor(){this._index={},this.addPath("/",new H)}fileIterator(e){for(let t in this._index)if(Object.prototype.hasOwnProperty.call(this._index,t)){let i=this._index[t],r=i.getListing();for(let n of r){let s=i.getItem(n);ft(s)&&e(s.getData())}}}addPath(e,t){if(!t)throw new Error("Inode must be specified");if(e[0]!=="/")throw new Error("Path must be absolute, got: "+e);if(Object.prototype.hasOwnProperty.call(this._index,e))return this._index[e]===t;let i=this._split_path(e),r=i[0],n=i[1],s=this._index[r];return s===void 0&&e!=="/"&&(s=new H,!this.addPath(r,s))||e!=="/"&&!s.addItem(n,t)?!1:(ot(t)&&(this._index[e]=t),!0)}addPathFast(e,t){let i=e.lastIndexOf("/"),r=i===0?"/":e.substring(0,i),n=e.substring(i+1),s=this._index[r];return s===void 0&&(s=new H,this.addPathFast(r,s)),s.addItem(n,t)?(t.isDir()&&(this._index[e]=t),!0):!1}removePath(e){let t=this._split_path(e),i=t[0],r=t[1],n=this._index[i];if(n===void 0)return null;let s=n.remItem(r);if(s===null)return null;if(ot(s)){let a=s.getListing();for(let d of a)this.removePath(e+"/"+d);e!=="/"&&delete this._index[e]}return s}ls(e){let t=this._index[e];return t===void 0?null:t.getListing()}getInode(e){let t=this._split_path(e),i=t[0],r=t[1],n=this._index[i];return n===void 0?null:i===e?n:n.getItem(r)}_split_path(e){let t=g(e),i=e.slice(t.length+(t==="/"?0:1));return[t,i]}};h(Q,"FileIndex");var Pt=class{constructor(e){this.data=e}isFile(){return!0}isDir(){return!1}getData(){return this.data}setData(e){this.data=e}toStats(){return new O(E.FILE,4096,438)}};h(Pt,"IndexFileInode");var H=class{constructor(e=null){this.data=e,this._ls={}}isFile(){return!1}isDir(){return!0}getData(){return this.data}getStats(){return new O(E.DIRECTORY,4096,365)}toStats(){return this.getStats()}getListing(){return Object.keys(this._ls)}getItem(e){let t=this._ls[e];return t||null}addItem(e,t){return e in this._ls?!1:(this._ls[e]=t,!0)}remItem(e){let t=this._ls[e];return t===void 0?null:(delete this._ls[e],t)}};h(H,"IndexDirInode");function ft(o){return!!o&&o.isFile()}h(ft,"isIndexFileInode");function ot(o){return!!o&&o.isDir()}h(ot,"isIndexDirInode");var Ct=class extends T{constructor({index:t,baseUrl:i=""}){super();t||(t="index.json");let r=typeof t=="string"?Lt(t,"json"):Promise.resolve(t);this._ready=r.then(n=>(this._index=Q.fromListing(n),this)),i.length>0&&i.charAt(i.length-1)!=="/"&&(i=i+"/"),this.prefixUrl=i}static isAvailable(){return Qt}get metadata(){return it($({},super.metadata),{name:Ct.Name,readonly:!0})}empty(){this._index.fileIterator(function(t){t.fileData=null})}preloadFile(t,i){let r=this._index.getInode(t);if(ft(r)){if(r===null)throw c.ENOENT(t);let n=r.getData();n.size=i.length,n.fileData=i}else throw c.EISDIR(t)}stat(t,i){return S(this,null,function*(){let r=this._index.getInode(t);if(r===null)throw c.ENOENT(t);if(!r.toStats().hasAccess(4,i))throw c.EACCES(t);let n;if(ft(r))n=r.getData(),n.size<0&&(n.size=yield this._requestFileSize(t));else if(ot(r))n=r.getStats();else throw c.FileError(l.EINVAL,t);return n})}open(t,i,r,n){return S(this,null,function*(){if(i.isWriteable())throw new c(l.EPERM,t);let s=this._index.getInode(t);if(s===null)throw c.ENOENT(t);if(!s.toStats().hasAccess(i.getMode(),n))throw c.EACCES(t);if(ft(s)||ot(s))switch(i.pathExistsAction()){case v.THROW_EXCEPTION:case v.TRUNCATE_FILE:throw c.EEXIST(t);case v.NOP:if(ot(s)){let f=s.getStats();return new J(this,t,i,f,f.fileData||void 0)}let a=s.getData();if(a.fileData)return new J(this,t,i,O.clone(a),a.fileData);let d=yield this._requestFile(t,"buffer");return a.size=d.length,a.fileData=d,new J(this,t,i,O.clone(a),d);default:throw new c(l.EINVAL,"Invalid FileMode object.")}else throw c.EPERM(t)})}readdir(t,i){return S(this,null,function*(){return this.readdirSync(t,i)})}readFile(t,i,r,n){return S(this,null,function*(){let s=yield this.open(t,r,420,n);try{let d=s.getBuffer();return i?z(d):d}finally{yield s.close()}})}_getHTTPPath(t){return t.charAt(0)==="/"&&(t=t.slice(1)),this.prefixUrl+t}_requestFile(t,i){return Lt(this._getHTTPPath(t),i)}_requestFileSize(t){return Zt(this._getHTTPPath(t))}},Z=Ct;h(Z,"HTTPRequest"),Z.Name="HTTPRequest",Z.Create=R.bind(Ct),Z.Options={index:{type:["string","object"],optional:!0,description:"URL to a file index as a JSON file or the file index object itself, generated with the make_http_index script. Defaults to `index.json`."},baseUrl:{type:"string",optional:!0,description:"Used as the URL prefix for fetched files. Default: Fetch files relative to the index."}};var N=function(o,e,t,i){function r(n){return n instanceof t?n:new t(function(s){s(n)})}return h(r,"adopt"),new(t||(t=Promise))(function(n,s){function a(u){try{f(i.next(u))}catch(m){s(m)}}h(a,"fulfilled");function d(u){try{f(i.throw(u))}catch(m){s(m)}}h(d,"rejected");function f(u){u.done?n(u.value):r(u.value).then(a,d)}h(f,"step"),f((i=i.apply(o,e||[])).next())})},mt=class{constructor(e,t){this.key=e,this.value=t,this.prev=null,this.next=null}};h(mt,"LRUNode");var Rt=class{constructor(e){this.limit=e,this.size=0,this.map={},this.head=null,this.tail=null}set(e,t){let i=new mt(e,t);this.map[e]?(this.map[e].value=i.value,this.remove(i.key)):this.size>=this.limit&&(delete this.map[this.tail.key],this.size--,this.tail=this.tail.prev,this.tail.next=null),this.setHead(i)}get(e){if(this.map[e]){let t=this.map[e].value,i=new mt(e,t);return this.remove(e),this.setHead(i),t}else return null}remove(e){let t=this.map[e];t&&(t.prev!==null?t.prev.next=t.next:this.head=t.next,t.next!==null?t.next.prev=t.prev:this.tail=t.prev,delete this.map[e],this.size--)}removeAll(){this.size=0,this.map={},this.head=null,this.tail=null}setHead(e){e.next=this.head,e.prev=null,this.head!==null&&(this.head.prev=e),this.head=e,this.tail===null&&(this.tail=e),this.size++,this.map[e.key]=e}};h(Rt,"LRUCache");var pt=class extends L{constructor(e,t,i,r,n){super(e,t,i,r,n)}sync(){return N(this,void 0,void 0,function*(){this.isDirty()&&(yield this._fs._sync(this.getPath(),this.getBuffer(),this.getStats()),this.resetDirty())})}close(){return N(this,void 0,void 0,function*(){this.sync()})}};h(pt,"AsyncKeyValueFile");var yt=class extends T{static isAvailable(){return!0}constructor(e){super(),this._cache=null,e>0&&(this._cache=new Rt(e))}init(e){return N(this,void 0,void 0,function*(){this.store=e,yield this.makeRootDirectory()})}getName(){return this.store.name()}isReadOnly(){return!1}supportsSymlinks(){return!1}supportsProps(){return!0}supportsSynch(){return!1}empty(){return N(this,void 0,void 0,function*(){this._cache&&this._cache.removeAll(),yield this.store.clear(),yield this.makeRootDirectory()})}access(e,t,i){return N(this,void 0,void 0,function*(){let r=this.store.beginTransaction("readonly"),n=yield this.findINode(r,e);if(!n)throw c.ENOENT(e);if(!n.toStats().hasAccess(t,i))throw c.EACCES(e)})}rename(e,t,i){return N(this,void 0,void 0,function*(){let r=this._cache;this._cache&&(this._cache=null,r.removeAll());try{let n=this.store.beginTransaction("readwrite"),s=g(e),a=I(e),d=g(t),f=I(t),u=yield this.findINode(n,s),m=yield this.getDirListing(n,s,u);if(!u.toStats().hasAccess(2,i))throw c.EACCES(e);if(!m[a])throw c.ENOENT(e);let p=m[a];if(delete m[a],(d+"/").indexOf(e+"/")===0)throw new c(l.EBUSY,s);let w,x;if(d===s?(w=u,x=m):(w=yield this.findINode(n,d),x=yield this.getDirListing(n,d,w)),x[f]){let B=yield this.getINode(n,t,x[f]);if(B.isFile())try{yield n.del(B.id),yield n.del(x[f])}catch(ct){throw yield n.abort(),ct}else throw c.EPERM(t)}x[f]=p;try{yield n.put(u.id,b(JSON.stringify(m)),!0),yield n.put(w.id,b(JSON.stringify(x)),!0)}catch(B){throw yield n.abort(),B}yield n.commit()}finally{r&&(this._cache=r)}})}stat(e,t){return N(this,void 0,void 0,function*(){let i=this.store.beginTransaction("readonly"),n=(yield this.findINode(i,e)).toStats();if(!n.hasAccess(4,t))throw c.EACCES(e);return n})}createFile(e,t,i,r){return N(this,void 0,void 0,function*(){let n=this.store.beginTransaction("readwrite"),s=new Uint8Array(0),a=yield this.commitNewFile(n,e,E.FILE,i,r,s);return new pt(this,e,t,a.toStats(),s)})}openFile(e,t,i){return N(this,void 0,void 0,function*(){let r=this.store.beginTransaction("readonly"),n=yield this.findINode(r,e),s=yield r.get(n.id);if(!n.toStats().hasAccess(t.getMode(),i))throw c.EACCES(e);if(s===void 0)throw c.ENOENT(e);return new pt(this,e,t,n.toStats(),s)})}unlink(e,t){return N(this,void 0,void 0,function*(){return this.removeEntry(e,!1,t)})}rmdir(e,t){return N(this,void 0,void 0,function*(){if((yield this.readdir(e,t)).length>0)throw c.ENOTEMPTY(e);yield this.removeEntry(e,!0,t)})}mkdir(e,t,i){return N(this,void 0,void 0,function*(){let r=this.store.beginTransaction("readwrite"),n=b("{}");yield this.commitNewFile(r,e,E.DIRECTORY,t,i,n)})}readdir(e,t){return N(this,void 0,void 0,function*(){let i=this.store.beginTransaction("readonly"),r=yield this.findINode(i,e);if(!r.toStats().hasAccess(4,t))throw c.EACCES(e);return Object.keys(yield this.getDirListing(i,e,r))})}chmod(e,t,i){return N(this,void 0,void 0,function*(){yield(yield this.openFile(e,_.getFileFlag("r+"),i)).chmod(t)})}chown(e,t,i,r){return N(this,void 0,void 0,function*(){yield(yield this.openFile(e,_.getFileFlag("r+"),r)).chown(t,i)})}_sync(e,t,i){return N(this,void 0,void 0,function*(){let r=this.store.beginTransaction("readwrite"),n=yield this._findINode(r,g(e),I(e)),s=yield this.getINode(r,e,n),a=s.update(i);try{yield r.put(s.id,t,!0),a&&(yield r.put(n,s.serialize(),!0))}catch(d){throw yield r.abort(),d}yield r.commit()})}makeRootDirectory(){return N(this,void 0,void 0,function*(){let e=this.store.beginTransaction("readwrite");if((yield e.get(A))===void 0){let t=new Date().getTime(),i=new D(nt(),4096,511|E.DIRECTORY,t,t,t,0,0);yield e.put(i.id,b("{}"),!1),yield e.put(A,i.serialize(),!1),yield e.commit()}})}_findINode(e,t,i,r=new Set){return N(this,void 0,void 0,function*(){let n=C(t,i);if(r.has(n))throw new c(l.EIO,"Infinite loop detected while finding inode",n);if(r.add(n),this._cache){let s=this._cache.get(n);if(s)return s}if(t==="/"){if(i==="")return this._cache&&this._cache.set(n,A),A;{let s=yield this.getINode(e,t,A),a=yield this.getDirListing(e,t,s);if(a[i]){let d=a[i];return this._cache&&this._cache.set(n,d),d}else throw c.ENOENT(Y(t,i))}}else{let s=yield this.findINode(e,t,r),a=yield this.getDirListing(e,t,s);if(a[i]){let d=a[i];return this._cache&&this._cache.set(n,d),d}else throw c.ENOENT(Y(t,i))}})}findINode(e,t,i=new Set){return N(this,void 0,void 0,function*(){let r=yield this._findINode(e,g(t),I(t),i);return this.getINode(e,t,r)})}getINode(e,t,i){return N(this,void 0,void 0,function*(){let r=yield e.get(i);if(!r)throw c.ENOENT(t);return D.Deserialize(r)})}getDirListing(e,t,i){return N(this,void 0,void 0,function*(){if(!i.isDirectory())throw c.ENOTDIR(t);let r=yield e.get(i.id);try{return JSON.parse(r.toString())}catch(n){throw c.ENOENT(t)}})}addNewNode(e,t){return N(this,void 0,void 0,function*(){let i=0,r=h(()=>N(this,void 0,void 0,function*(){if(++i===5)throw new c(l.EIO,"Unable to commit data to key-value store.");{let n=nt();return(yield e.put(n,t,!1))?n:r()}}),"reroll");return r()})}commitNewFile(e,t,i,r,n,s){return N(this,void 0,void 0,function*(){let a=g(t),d=I(t),f=yield this.findINode(e,a),u=yield this.getDirListing(e,a,f),m=new Date().getTime();if(!f.toStats().hasAccess(2,n))throw c.EACCES(t);if(t==="/")throw c.EEXIST(t);if(u[d])throw yield e.abort(),c.EEXIST(t);try{let p=yield this.addNewNode(e,s),w=new D(p,s.length,r|i,m,m,m,n.uid,n.gid),x=yield this.addNewNode(e,w.serialize());return u[d]=x,yield e.put(f.id,b(JSON.stringify(u)),!0),yield e.commit(),w}catch(p){throw e.abort(),p}})}removeEntry(e,t,i){return N(this,void 0,void 0,function*(){this._cache&&this._cache.remove(e);let r=this.store.beginTransaction("readwrite"),n=g(e),s=yield this.findINode(r,n),a=yield this.getDirListing(r,n,s),d=I(e);if(!a[d])throw c.ENOENT(e);let f=a[d],u=yield this.getINode(r,e,f);if(!u.toStats().hasAccess(2,i))throw c.EACCES(e);if(delete a[d],!t&&u.isDirectory())throw c.EISDIR(e);if(t&&!u.isDirectory())throw c.ENOTDIR(e);try{yield r.del(u.id),yield r.del(f),yield r.put(s.id,b(JSON.stringify(a)),!0)}catch(m){throw yield r.abort(),m}yield r.commit()})}};h(yt,"AsyncKeyValueFileSystem");function wt(o,e=o.toString()){switch(o.name){case"NotFoundError":return new c(l.ENOENT,e);case"QuotaExceededError":return new c(l.ENOSPC,e);default:return new c(l.EIO,e)}}h(wt,"convertError");function Et(o,e=l.EIO,t=null){return function(i){i.preventDefault(),o(new c(e,t!==null?t:void 0))}}h(Et,"onErrorHandler");var at=class{constructor(e,t){this.tx=e;this.store=t}get(e){return new Promise((t,i)=>{try{let r=this.store.get(e);r.onerror=Et(i),r.onsuccess=n=>{let s=n.target.result;t(s===void 0?s:Uint8Array.from(s))}}catch(r){i(wt(r))}})}};h(at,"IndexedDBROTransaction");var gt=class extends at{constructor(e,t){super(e,t)}put(e,t,i){return new Promise((r,n)=>{try{let s=i?this.store.put(t,e):this.store.add(t,e);s.onerror=Et(n),s.onsuccess=()=>{r(!0)}}catch(s){n(wt(s))}})}del(e){return new Promise((t,i)=>{try{let r=this.store.delete(e);r.onerror=Et(i),r.onsuccess=()=>{t()}}catch(r){i(wt(r))}})}commit(){return new Promise(e=>{setTimeout(e,0)})}abort(){return new Promise((e,t)=>{try{this.tx.abort(),e()}catch(i){t(wt(i))}})}};h(gt,"IndexedDBRWTransaction");var tt=class{constructor(e,t){this.db=e;this.storeName=t}static Create(e,t){return new Promise((i,r)=>{let n=t.open(e,1);n.onupgradeneeded=s=>{let a=s.target.result;a.objectStoreNames.contains(e)&&a.deleteObjectStore(e),a.createObjectStore(e)},n.onsuccess=s=>{i(new tt(s.target.result,e))},n.onerror=Et(r,l.EACCES)})}name(){return j.Name+" - "+this.storeName}clear(){return new Promise((e,t)=>{try{let i=this.db.transaction(this.storeName,"readwrite"),r=i.objectStore(this.storeName),n=r.clear();n.onsuccess=()=>{setTimeout(e,0)},n.onerror=Et(t)}catch(i){t(wt(i))}})}beginTransaction(e="readonly"){let t=this.db.transaction(this.storeName,e),i=t.objectStore(this.storeName);if(e==="readwrite")return new gt(t,i);if(e==="readonly")return new at(t,i);throw new c(l.EINVAL,"Invalid transaction type.")}};h(tt,"IndexedDBStore");var Mt=class extends yt{static isAvailable(e=globalThis.indexedDB){try{if(!(e instanceof IDBFactory)||!e.open("__zenfs_test__"))return!1}catch(t){return!1}}constructor({cacheSize:e=100,storeName:t="zenfs",idbFactory:i=globalThis.indexedDB}){super(e),this._ready=tt.Create(t,i).then(r=>(this.init(r),this))}},j=Mt;h(j,"IndexedDBFileSystem"),j.Name="IndexedDB",j.Create=R.bind(Mt),j.Options={storeName:{type:"string",optional:!0,description:"The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name."},cacheSize:{type:"number",optional:!0,description:"The size of the inode cache. Defaults to 100. A size of 0 or below disables caching."},idbFactory:{type:"object",optional:!0,description:"The IDBFactory to use. Defaults to globalThis.indexedDB."}};var St=class{constructor(e){this._storage=e}name(){return V.Name}clear(){this._storage.clear()}beginTransaction(e){return new q(this)}get(e){let t=this._storage.getItem(e);if(typeof t=="string")return b(t)}put(e,t,i){try{return!i&&this._storage.getItem(e)!==null?!1:(this._storage.setItem(e,t.toString()),!0)}catch(r){throw new c(l.ENOSPC,"Storage is full.")}}del(e){try{this._storage.removeItem(e)}catch(t){throw new c(l.EIO,"Unable to delete key "+e+": "+t)}}};h(St,"StorageStore");var zt=class extends X{static isAvailable(e=globalThis.localStorage){return e instanceof Storage}constructor({storage:e=globalThis.localStorage}){super({store:new St(e)})}},V=zt;h(V,"StorageFileSystem"),V.Name="Storage",V.Create=R.bind(zt),V.Options={storage:{type:"object",optional:!0,description:"The Storage to use. Defaults to globalThis.localStorage."}};function fe(o){return typeof o=="object"&&"isBFS"in o&&!!o.isBFS}h(fe,"isRPCMessage");var At=class extends T{constructor({worker:t}){super();this._currentID=0;this._requests=new Map;this._isInitialized=!1;this._worker=t,this._worker.onmessage=i=>{if(!fe(i.data))return;let{id:r,method:n,value:s}=i.data;if(n==="metadata"){this._metadata=s,this._isInitialized=!0;return}let{resolve:a,reject:d}=this._requests.get(r);if(this._requests.delete(r),s instanceof Error||s instanceof c){d(s);return}a(s)}}static isAvailable(){return typeof importScripts!="undefined"||typeof Worker!="undefined"}get metadata(){return it($($({},super.metadata),this._metadata),{name:At.Name,synchronous:!1})}_rpc(t,...i){return S(this,null,function*(){return new Promise((r,n)=>{let s=this._currentID++;this._requests.set(s,{resolve:r,reject:n}),this._worker.postMessage({isBFS:!0,id:s,method:t,args:i})})})}rename(t,i,r){return this._rpc("rename",t,i,r)}stat(t,i){return this._rpc("stat",t,i)}open(t,i,r,n){return this._rpc("open",t,i,r,n)}unlink(t,i){return this._rpc("unlink",t,i)}rmdir(t,i){return this._rpc("rmdir",t,i)}mkdir(t,i,r){return this._rpc("mkdir",t,i,r)}readdir(t,i){return this._rpc("readdir",t,i)}exists(t,i){return this._rpc("exists",t,i)}realpath(t,i){return this._rpc("realpath",t,i)}truncate(t,i,r){return this._rpc("truncate",t,i,r)}readFile(t,i,r,n){return this._rpc("readFile",t,i,r,n)}writeFile(t,i,r,n,s,a){return this._rpc("writeFile",t,i,r,n,s,a)}appendFile(t,i,r,n,s,a){return this._rpc("appendFile",t,i,r,n,s,a)}chmod(t,i,r){return this._rpc("chmod",t,i,r)}chown(t,i,r,n){return this._rpc("chown",t,i,r,n)}utimes(t,i,r,n){return this._rpc("utimes",t,i,r,n)}link(t,i,r){return this._rpc("link",t,i,r)}symlink(t,i,r,n){return this._rpc("symlink",t,i,r,n)}readlink(t,i){return this._rpc("readlink",t,i)}syncClose(t,i){return this._rpc("syncClose",t,i)}},et=At;h(et,"WorkerFS"),et.Name="WorkerFS",et.Create=R.bind(At),et.Options={worker:{type:"object",description:"The target worker that you want to connect to, or the current worker if in a worker context.",validator(t){if(typeof(t==null?void 0:t.postMessage)!="function")throw new c(l.EINVAL,"option must be a Web Worker instance.")}}};return ae(me);})();
|
|
1
|
+
var ZenFS_DOM=(()=>{var yt=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var u=(o,t)=>yt(o,"name",{value:t,configurable:!0});var re=(o,t)=>{for(var e in t)yt(o,e,{get:t[e],enumerable:!0})},se=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ee(t))!ie.call(o,r)&&r!==e&&yt(o,r,{get:()=>t[r],enumerable:!(i=te(t,r))||i.enumerable});return o};var ne=o=>se(yt({},"__esModule",{value:!0}),o);var de={};re(de,{FileSystemAccessFile:()=>ot,FileSystemAccessFileSystem:()=>Y,HTTPRequest:()=>X,IndexedDBFileSystem:()=>L,IndexedDBROTransaction:()=>it,IndexedDBRWTransaction:()=>dt,IndexedDBStore:()=>K,StorageFileSystem:()=>B,StorageStore:()=>mt,WorkerFS:()=>J});var oe="/",z="/";function G(o,t){if(typeof o!="string")throw new TypeError(`"${t}" is not a string`)}u(G,"validateString");function jt(o,t){let e="",i=0,r=-1,s=0,n="\0";for(let c=0;c<=o.length;++c){if(c<o.length)n=o[c];else{if(n=="/")break;n="/"}if(n=="/"){if(!(r===c-1||s===1))if(s===2){if(e.length<2||i!==2||e.at(-1)!=="."||e.at(-2)!=="."){if(e.length>2){let h=e.lastIndexOf("/");h===-1?(e="",i=0):(e=e.slice(0,h),i=e.length-1-e.lastIndexOf("/")),r=c,s=0;continue}else if(e.length!==0){e="",i=0,r=c,s=0;continue}}t&&(e+=e.length>0?"/..":"..",i=2)}else e.length>0?e+="/"+o.slice(r+1,c):e=o.slice(r+1,c),i=c-r-1;r=c,s=0}else n==="."&&s!==-1?++s:s=-1}return e}u(jt,"normalizeString");function H(...o){let t="",e=!1;for(let i=o.length-1;i>=-1&&!e;i--){let r=i>=0?o[i]:oe;G(r,`paths[${i}]`),r.length!==0&&(t=`${r}/${t}`,e=r[0]==="/")}return t=jt(t,!e),e?`/${t}`:t.length>0?t:"."}u(H,"resolve");function ae(o){if(G(o,"path"),o.length===0)return".";let t=o[0]==="/",e=o.at(-1)==="/";return o=jt(o,!t),o.length===0?t?"/":e?"./":".":(e&&(o+="/"),t?`/${o}`:o)}u(ae,"normalize");function F(...o){if(o.length===0)return".";let t;for(let e=0;e<o.length;++e){let i=o[e];G(i,"path"),i.length>0&&(t===void 0?t=i:t+=`/${i}`)}return t===void 0?".":ae(t)}u(F,"join");function y(o){if(G(o,"path"),o.length===0)return".";let t=o[0]==="/",e=-1,i=!0;for(let r=o.length-1;r>=1;--r)if(o[r]==="/"){if(!i){e=r;break}}else i=!1;return e===-1?t?"/":".":t&&e===1?"//":o.slice(0,e)}u(y,"dirname");function _(o,t){t!==void 0&&G(t,"ext"),G(o,"path");let e=0,i=-1,r=!0;if(t!==void 0&&t.length>0&&t.length<=o.length){if(t===o)return"";let s=t.length-1,n=-1;for(let c=o.length-1;c>=0;--c)if(o[c]==="/"){if(!r){e=c+1;break}}else n===-1&&(r=!1,n=c+1),s>=0&&(o[c]===t[s]?--s===-1&&(i=c):(s=-1,i=n));return e===i?i=n:i===-1&&(i=o.length),o.slice(e,i)}for(let s=o.length-1;s>=0;--s)if(o[s]==="/"){if(!r){e=s+1;break}}else i===-1&&(r=!1,i=s+1);return i===-1?"":o.slice(e,i)}u(_,"basename");function gt(o,t,e,i,r){return Math.min(o+1,t+1,e+1,i===r?t:t+1)}u(gt,"_min");function ce(o,t){if(o===t)return 0;o.length>t.length&&([o,t]=[t,o]);let e=o.length,i=t.length;for(;e>0&&o.charCodeAt(e-1)===t.charCodeAt(i-1);)e--,i--;let r=0;for(;r<e&&o.charCodeAt(r)===t.charCodeAt(r);)r++;if(e-=r,i-=r,e===0||i===1)return i;let s=new Array(e<<1);for(let p=0;p<e;)s[e+p]=o.charCodeAt(r+p),s[p]=++p;let n,c,h,d,f;for(n=0;n+3<i;){let p=t.charCodeAt(r+(c=n)),w=t.charCodeAt(r+(h=n+1)),S=t.charCodeAt(r+(d=n+2)),U=t.charCodeAt(r+(f=n+3)),rt=n+=4;for(let pt=0;pt<e;){let wt=s[e+pt],Ht=s[pt];c=gt(Ht,c,h,p,wt),h=gt(c,h,d,w,wt),d=gt(h,d,f,S,wt),rt=gt(d,f,rt,U,wt),s[pt++]=rt,f=d,d=h,h=c,c=Ht}}let m=0;for(;n<i;){let p=t.charCodeAt(r+(c=n));m=++n;for(let w=0;w<e;w++){let S=s[w];s[w]=m=S<c||m<c?S>m?m+1:S+1:p===s[e+w]?c:c+1,c=S}}return m}u(ce,"levenshtein");async function Vt(o,t){let e=o.Options,i=o.Name,r=0,s=!1,n=!1;for(let c in e)if(Object.prototype.hasOwnProperty.call(e,c)){let h=e[c],d=t&&t[c];if(d==null){if(!h.optional){let f=Object.keys(t).filter(m=>!(m in e)).map(m=>({str:m,distance:ce(c,m)})).filter(m=>m.distance<5).sort((m,p)=>m.distance-p.distance);if(s)return;throw s=!0,new a(l.EINVAL,`[${i}] Required option '${c}' not provided.${f.length>0?` You provided unrecognized option '${f[0].str}'; perhaps you meant to type '${c}'.`:""}
|
|
2
|
+
Option description: ${h.description}`)}}else{let f=!1;if(Array.isArray(h.type)?f=h.type.indexOf(typeof d)!==-1:f=typeof d===h.type,f){if(h.validator){r++;try{await h.validator(d)}catch(m){if(!s){if(m)throw s=!0,m;if(r--,r===0&&n)return}}}}else{if(s)return;throw s=!0,new a(l.EINVAL,`[${i}] Value provided for option ${c} is not the proper type. Expected ${Array.isArray(h.type)?`one of {${h.type.join(", ")}}`:h.type}, but received ${typeof d}
|
|
3
|
+
Option description: ${h.description}`)}}}n=!0}u(Vt,"checkOptions");var we=typeof globalThis.setImmediate=="function"?globalThis.setImmediate:o=>setTimeout(o,0),P="/",kt=new Map,le=new globalThis.TextEncoder;function E(o,t="utf8"){return le.encode(o)}u(E,"encode");function C(o,t="utf8"){if(!kt.has(t)){let e=new globalThis.TextDecoder(t);kt.set(t,e.decode.bind(e))}return kt.get(t)(o)}u(C,"decode");function Q(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){let t=Math.random()*16|0;return(o==="x"?t:t&3|8).toString(16)})}u(Q,"randomUUID");var l;(function(o){o[o.EPERM=1]="EPERM",o[o.ENOENT=2]="ENOENT",o[o.EIO=5]="EIO",o[o.EBADF=9]="EBADF",o[o.EACCES=13]="EACCES",o[o.EBUSY=16]="EBUSY",o[o.EEXIST=17]="EEXIST",o[o.ENOTDIR=20]="ENOTDIR",o[o.EISDIR=21]="EISDIR",o[o.EINVAL=22]="EINVAL",o[o.EFBIG=27]="EFBIG",o[o.ENOSPC=28]="ENOSPC",o[o.EROFS=30]="EROFS",o[o.ENOTEMPTY=39]="ENOTEMPTY",o[o.ENOTSUP=95]="ENOTSUP"})(l=l||(l={}));var $t={[l.EPERM]:"Operation not permitted.",[l.ENOENT]:"No such file or directory.",[l.EIO]:"Input/output error.",[l.EBADF]:"Bad file descriptor.",[l.EACCES]:"Permission denied.",[l.EBUSY]:"Resource busy or locked.",[l.EEXIST]:"File exists.",[l.ENOTDIR]:"File is not a directory.",[l.EISDIR]:"File is a directory.",[l.EINVAL]:"Invalid argument.",[l.EFBIG]:"File is too big.",[l.ENOSPC]:"No space left on disk.",[l.EROFS]:"Cannot modify a read-only file system.",[l.ENOTEMPTY]:"Directory is not empty.",[l.ENOTSUP]:"Operation is not supported."},a=class extends Error{static fromJSON(t){let e=new a(t.errno,t.message,t.path);return e.code=t.code,e.stack=t.stack,e}static Derserialize(t,e=0){let i=new DataView("buffer"in t?t.buffer:t),r=C(i.buffer.slice(e+4,e+4+i.getUint32(e,!0)));return a.fromJSON(JSON.parse(r))}static FileError(t,e){return new a(t,$t[t],e)}static EACCES(t){return this.FileError(l.EACCES,t)}static ENOENT(t){return this.FileError(l.ENOENT,t)}static EEXIST(t){return this.FileError(l.EEXIST,t)}static EISDIR(t){return this.FileError(l.EISDIR,t)}static ENOTDIR(t){return this.FileError(l.ENOTDIR,t)}static EPERM(t){return this.FileError(l.EPERM,t)}static ENOTEMPTY(t){return this.FileError(l.ENOTEMPTY,t)}constructor(t,e=$t[t],i){super(e),this.syscall="",this.errno=t,this.code=l[t],this.path=i,this.message=`Error: ${this.code}: ${e}${this.path?`, '${this.path}'`:""}`}toString(){return this.message}toJSON(){return{errno:this.errno,code:this.code,path:this.path,stack:this.stack,message:this.message}}serialize(t=new Uint8Array(this.bufferSize()),e=0){let i=new DataView("buffer"in t?t.buffer:t),r=new Uint8Array(i.buffer),s=E(JSON.stringify(this.toJSON()));return r.set(s),i.setUint32(e,s.byteLength,!0),r}bufferSize(){return 4+JSON.stringify(this.toJSON()).length}};u(a,"ApiError");var D=class{constructor(t,e,i,r,s,n){this.uid=t,this.gid=e,this.suid=i,this.sgid=r,this.euid=s,this.egid=n}};u(D,"Cred");D.Root=new D(0,0,0,0,0,0);var g;(function(o){o[o.FILE=32768]="FILE",o[o.DIRECTORY=16384]="DIRECTORY",o[o.SYMLINK=40960]="SYMLINK"})(g=g||(g={}));var Et=class{static Deserialize(t){throw new ReferenceError("Called static abstract method: StatsCommon.Deserialize()")}get _typename(){return this._isBigint?"bigint":"number"}get _typename_inverse(){return this._isBigint?"number":"bigint"}_convert(t){return this._isBigint?BigInt(t):Number(t)}get atime(){return new Date(Number(this.atimeMs))}get mtime(){return new Date(Number(this.mtimeMs))}get ctime(){return new Date(Number(this.ctimeMs))}get birthtime(){return new Date(Number(this.birthtimeMs))}constructor(t=g.FILE,e=-1,i,r,s,n,c,h,d){this.dev=this._convert(0),this.ino=this._convert(0),this.rdev=this._convert(0),this.nlink=this._convert(1),this.blksize=this._convert(4096),this.uid=this._convert(0),this.gid=this._convert(0),this.fileData=null;let f=Date.now(),m=u((p,w)=>typeof p==this._typename?p:this._convert(typeof p==this._typename_inverse?p:w),"resolveT");if(this.atimeMs=m(r,f),this.mtimeMs=m(s,f),this.ctimeMs=m(n,f),this.birthtimeMs=m(d,f),this.uid=m(c,0),this.gid=m(h,0),this.size=this._convert(e),i)this.mode=this._convert(i);else switch(t){case g.FILE:this.mode=this._convert(420);break;case g.DIRECTORY:default:this.mode=this._convert(511)}this.blocks=this._convert(Math.ceil(Number(e)/512)),this.mode&61440||(this.mode=this.mode|this._convert(t))}isFile(){return(this.mode&61440)===32768}isDirectory(){return(this.mode&61440)===16384}isSymbolicLink(){return(this.mode&61440)===40960}hasAccess(t,e){if(e.euid===0||e.egid===0)return!0;let i=this.mode&-61441,r=15,s=15,n=15;if(e.euid==this.uid){let d=(3840&i)>>8;r=(t^d)&t}if(e.egid==this.gid){let d=(240&i)>>4;s=(t^d)&t}let c=15&i;return n=(t^c)&t,!(r&s&n)}getCred(t=Number(this.uid),e=Number(this.gid)){return new D(t,e,Number(this.uid),Number(this.gid),t,e)}chmod(t){this.mode=this._convert(this.mode&61440|t)}chown(t,e){t=Number(t),e=Number(e),!isNaN(t)&&0<=t&&t<2**32&&(this.uid=this._convert(t)),!isNaN(e)&&0<=e&&e<2**32&&(this.gid=this._convert(e))}isSocket(){return!1}isBlockDevice(){return!1}isCharacterDevice(){return!1}isFIFO(){return!1}};u(Et,"StatsCommon");var x=class extends Et{constructor(){super(...arguments),this._isBigint=!1}static clone(t){return new x(t.mode&61440,t.size,t.mode&-61441,t.atimeMs,t.mtimeMs,t.ctimeMs,t.uid,t.gid,t.birthtimeMs)}static Deserialize(t){let e=new DataView("buffer"in t?t.buffer:t),i=e.getUint32(0,!0),r=e.getUint32(4,!0),s=e.getFloat64(8,!0),n=e.getFloat64(16,!0),c=e.getFloat64(24,!0),h=e.getUint32(32,!0),d=e.getUint32(36,!0);return new x(r&61440,i,r&-61441,s,n,c,h,d)}serialize(){let t=new Uint8Array(32),e=new DataView(t.buffer);return e.setUint32(0,this.size,!0),e.setUint32(4,this.mode,!0),e.setFloat64(8,this.atime.getTime(),!0),e.setFloat64(16,this.mtime.getTime(),!0),e.setFloat64(24,this.ctime.getTime(),!0),e.setUint32(32,this.uid,!0),e.setUint32(36,this.gid,!0),t}};u(x,"Stats");var Xt,St=class{constructor(t){}};u(St,"FileSystem");var O=class extends St{constructor(t){super(),this._ready=Promise.resolve(this)}get metadata(){return{name:this.constructor.name,readonly:!1,synchronous:!1,supportsProperties:!1,supportsLinks:!1,totalSpace:0,freeSpace:0}}whenReady(){return this._ready}async openFile(t,e,i){throw new a(l.ENOTSUP)}async createFile(t,e,i,r){throw new a(l.ENOTSUP)}async open(t,e,i,r){try{let s=await this.stat(t,r);switch(e.pathExistsAction()){case b.THROW_EXCEPTION:throw a.EEXIST(t);case b.TRUNCATE_FILE:let n=await this.openFile(t,e,r);if(!n)throw new Error("BFS has reached an impossible code path; please file a bug.");return await n.truncate(0),await n.sync(),n;case b.NOP:return this.openFile(t,e,r);default:throw new a(l.EINVAL,"Invalid FileFlag object.")}}catch{switch(e.pathNotExistsAction()){case b.CREATE_FILE:let n=await this.stat(y(t),r);if(n&&!n.isDirectory())throw a.ENOTDIR(y(t));return this.createFile(t,e,i,r);case b.THROW_EXCEPTION:throw a.ENOENT(t);default:throw new a(l.EINVAL,"Invalid FileFlag object.")}}}async access(t,e,i){throw new a(l.ENOTSUP)}accessSync(t,e,i){throw new a(l.ENOTSUP)}async rename(t,e,i){throw new a(l.ENOTSUP)}renameSync(t,e,i){throw new a(l.ENOTSUP)}async stat(t,e){throw new a(l.ENOTSUP)}statSync(t,e){throw new a(l.ENOTSUP)}openFileSync(t,e,i){throw new a(l.ENOTSUP)}createFileSync(t,e,i,r){throw new a(l.ENOTSUP)}openSync(t,e,i,r){let s;try{s=this.statSync(t,r)}catch{switch(e.pathNotExistsAction()){case b.CREATE_FILE:if(!this.statSync(y(t),r).isDirectory())throw a.ENOTDIR(y(t));return this.createFileSync(t,e,i,r);case b.THROW_EXCEPTION:throw a.ENOENT(t);default:throw new a(l.EINVAL,"Invalid FileFlag object.")}}if(!s.hasAccess(i,r))throw a.EACCES(t);switch(e.pathExistsAction()){case b.THROW_EXCEPTION:throw a.EEXIST(t);case b.TRUNCATE_FILE:return this.unlinkSync(t,r),this.createFileSync(t,e,s.mode,r);case b.NOP:return this.openFileSync(t,e,r);default:throw new a(l.EINVAL,"Invalid FileFlag object.")}}async unlink(t,e){throw new a(l.ENOTSUP)}unlinkSync(t,e){throw new a(l.ENOTSUP)}async rmdir(t,e){throw new a(l.ENOTSUP)}rmdirSync(t,e){throw new a(l.ENOTSUP)}async mkdir(t,e,i){throw new a(l.ENOTSUP)}mkdirSync(t,e,i){throw new a(l.ENOTSUP)}async readdir(t,e){throw new a(l.ENOTSUP)}readdirSync(t,e){throw new a(l.ENOTSUP)}async exists(t,e){try{return await this.stat(t,e),!0}catch{return!1}}existsSync(t,e){try{return this.statSync(t,e),!0}catch{return!1}}async realpath(t,e){if(this.metadata.supportsLinks){let i=t.split(z);for(let r=0;r<i.length;r++){let s=i.slice(0,r+1);i[r]=F(...s)}return i.join(z)}else{if(!await this.exists(t,e))throw a.ENOENT(t);return t}}realpathSync(t,e){if(this.metadata.supportsLinks){let i=t.split(z);for(let r=0;r<i.length;r++){let s=i.slice(0,r+1);i[r]=F(...s)}return i.join(z)}else{if(this.existsSync(t,e))return t;throw a.ENOENT(t)}}async truncate(t,e,i){let r=await this.open(t,N.getFileFlag("r+"),420,i);try{await r.truncate(e)}finally{await r.close()}}truncateSync(t,e,i){let r=this.openSync(t,N.getFileFlag("r+"),420,i);try{r.truncateSync(e)}finally{r.closeSync()}}async readFile(t,e,i){let r=await this.open(t,e,420,i);try{let s=await r.stat(),n=new Uint8Array(s.size);return await r.read(n,0,s.size,0),await r.close(),n}finally{await r.close()}}readFileSync(t,e,i){let r=this.openSync(t,e,420,i);try{let s=r.statSync(),n=new Uint8Array(s.size);return r.readSync(n,0,s.size,0),r.closeSync(),n}finally{r.closeSync()}}async writeFile(t,e,i,r,s){let n=await this.open(t,i,r,s);try{typeof e=="string"&&(e=E(e)),await n.write(e,0,e.length,0)}finally{await n.close()}}writeFileSync(t,e,i,r,s){let n=this.openSync(t,i,r,s);try{typeof e=="string"&&(e=E(e)),n.writeSync(e,0,e.length,0)}finally{n.closeSync()}}async appendFile(t,e,i,r,s){let n=await this.open(t,i,r,s);try{typeof e=="string"&&(e=E(e)),await n.write(e,0,e.length,null)}finally{await n.close()}}appendFileSync(t,e,i,r,s){let n=this.openSync(t,i,r,s);try{typeof e=="string"&&(e=E(e)),n.writeSync(e,0,e.length,null)}finally{n.closeSync()}}async chmod(t,e,i){throw new a(l.ENOTSUP)}chmodSync(t,e,i){throw new a(l.ENOTSUP)}async chown(t,e,i,r){throw new a(l.ENOTSUP)}chownSync(t,e,i,r){throw new a(l.ENOTSUP)}async utimes(t,e,i,r){throw new a(l.ENOTSUP)}utimesSync(t,e,i,r){throw new a(l.ENOTSUP)}async link(t,e,i){throw new a(l.ENOTSUP)}linkSync(t,e,i){throw new a(l.ENOTSUP)}async symlink(t,e,i,r){throw new a(l.ENOTSUP)}symlinkSync(t,e,i,r){throw new a(l.ENOTSUP)}async readlink(t,e){throw new a(l.ENOTSUP)}readlinkSync(t,e){throw new a(l.ENOTSUP)}};u(O,"BaseFileSystem");Xt=O;O.Name=Xt.name;var st=class extends O{get metadata(){return{...super.metadata,synchronous:!0}}async access(t,e,i){return this.accessSync(t,e,i)}async rename(t,e,i){return this.renameSync(t,e,i)}async stat(t,e){return this.statSync(t,e)}async open(t,e,i,r){return this.openSync(t,e,i,r)}async unlink(t,e){return this.unlinkSync(t,e)}async rmdir(t,e){return this.rmdirSync(t,e)}async mkdir(t,e,i){return this.mkdirSync(t,e,i)}async readdir(t,e){return this.readdirSync(t,e)}async chmod(t,e,i){return this.chmodSync(t,e,i)}async chown(t,e,i,r){return this.chownSync(t,e,i,r)}async utimes(t,e,i,r){return this.utimesSync(t,e,i,r)}async link(t,e,i){return this.linkSync(t,e,i)}async symlink(t,e,i,r){return this.symlinkSync(t,e,i,r)}async readlink(t,e){return this.readlinkSync(t,e)}};u(st,"SynchronousFileSystem");var I=class{static Deserialize(t){let e=new DataView("buffer"in t?t.buffer:t);return new I(C(e.buffer.slice(38)),e.getUint32(0,!0),e.getUint16(4,!0),e.getFloat64(6,!0),e.getFloat64(14,!0),e.getFloat64(22,!0),e.getUint32(30,!0),e.getUint32(34,!0))}constructor(t,e,i,r,s,n,c,h){this.id=t,this.size=e,this.mode=i,this.atime=r,this.mtime=s,this.ctime=n,this.uid=c,this.gid=h}toStats(){return new x((this.mode&61440)===g.DIRECTORY?g.DIRECTORY:g.FILE,this.size,this.mode,this.atime,this.mtime,this.ctime,this.uid,this.gid)}getSize(){return 38+this.id.length}serialize(t=new Uint8Array(this.getSize())){let e=new DataView("buffer"in t?t.buffer:t);e.setUint32(0,this.size,!0),e.setUint16(4,this.mode,!0),e.setFloat64(6,this.atime,!0),e.setFloat64(14,this.mtime,!0),e.setFloat64(22,this.ctime,!0),e.setUint32(30,this.uid,!0),e.setUint32(34,this.gid,!0);let i=new Uint8Array(e.buffer);return i.set(E(this.id),38),i}update(t){let e=!1;this.size!==t.size&&(this.size=t.size,e=!0),this.mode!==t.mode&&(this.mode=t.mode,e=!0);let i=t.atime.getTime();this.atime!==i&&(this.atime=i,e=!0);let r=t.mtime.getTime();this.mtime!==r&&(this.mtime=r,e=!0);let s=t.ctime.getTime();return this.ctime!==s&&(this.ctime=s,e=!0),this.uid!==t.uid&&(this.uid=t.uid,e=!0),this.uid!==t.uid&&(this.uid=t.uid,e=!0),e}isFile(){return(this.mode&61440)===g.FILE}isDirectory(){return(this.mode&61440)===g.DIRECTORY}};u(I,"Inode");var j=class{constructor(t){this.store=t,this.originalData={},this.modifiedKeys=[]}get(t){let e=this.store.get(t);return this.stashOldValue(t,e),e}put(t,e,i){return this.markModified(t),this.store.put(t,e,i)}del(t){this.markModified(t),this.store.del(t)}commit(){}abort(){for(let t of this.modifiedKeys){let e=this.originalData[t];e?this.store.put(t,e,!0):this.store.del(t)}}_has(t){return Object.prototype.hasOwnProperty.call(this.originalData,t)}stashOldValue(t,e){this._has(t)||(this.originalData[t]=e)}markModified(t){this.modifiedKeys.indexOf(t)===-1&&(this.modifiedKeys.push(t),this._has(t)||(this.originalData[t]=this.store.get(t)))}};u(j,"SimpleSyncRWTransaction");var nt=class extends A{constructor(t,e,i,r,s){super(t,e,i,r,s)}syncSync(){this.isDirty()&&(this._fs._syncSync(this.getPath(),this.getBuffer(),this.getStats()),this.resetDirty())}closeSync(){this.syncSync()}};u(nt,"SyncKeyValueFile");var V=class extends st{static isAvailable(){return!0}constructor(t){super(),this.store=t.store,this.makeRootDirectory()}getName(){return this.store.name()}isReadOnly(){return!1}supportsSymlinks(){return!1}supportsProps(){return!0}supportsSynch(){return!0}empty(){this.store.clear(),this.makeRootDirectory()}accessSync(t,e,i){let r=this.store.beginTransaction("readonly");if(!this.findINode(r,t).toStats().hasAccess(e,i))throw a.EACCES(t)}renameSync(t,e,i){let r=this.store.beginTransaction("readwrite"),s=y(t),n=_(t),c=y(e),h=_(e),d=this.findINode(r,s),f=this.getDirListing(r,s,d);if(!d.toStats().hasAccess(2,i))throw a.EACCES(t);if(!f[n])throw a.ENOENT(t);let m=f[n];if(delete f[n],(c+"/").indexOf(t+"/")===0)throw new a(l.EBUSY,s);let p,w;if(c===s?(p=d,w=f):(p=this.findINode(r,c),w=this.getDirListing(r,c,p)),w[h]){let S=this.getINode(r,e,w[h]);if(S.isFile())try{r.del(S.id),r.del(w[h])}catch(U){throw r.abort(),U}else throw a.EPERM(e)}w[h]=m;try{r.put(d.id,E(JSON.stringify(f)),!0),r.put(p.id,E(JSON.stringify(w)),!0)}catch(S){throw r.abort(),S}r.commit()}statSync(t,e){let i=this.findINode(this.store.beginTransaction("readonly"),t).toStats();if(!i.hasAccess(4,e))throw a.EACCES(t);return i}createFileSync(t,e,i,r){let s=this.store.beginTransaction("readwrite"),n=new Uint8Array(0),c=this.commitNewFile(s,t,g.FILE,i,r,n);return new nt(this,t,e,c.toStats(),n)}openFileSync(t,e,i){let r=this.store.beginTransaction("readonly"),s=this.findINode(r,t),n=r.get(s.id);if(!s.toStats().hasAccess(e.getMode(),i))throw a.EACCES(t);if(n===void 0)throw a.ENOENT(t);return new nt(this,t,e,s.toStats(),n)}unlinkSync(t,e){this.removeEntry(t,!1,e)}rmdirSync(t,e){if(this.readdirSync(t,e).length>0)throw a.ENOTEMPTY(t);this.removeEntry(t,!0,e)}mkdirSync(t,e,i){let r=this.store.beginTransaction("readwrite"),s=E("{}");this.commitNewFile(r,t,g.DIRECTORY,e,i,s)}readdirSync(t,e){let i=this.store.beginTransaction("readonly"),r=this.findINode(i,t);if(!r.toStats().hasAccess(4,e))throw a.EACCES(t);return Object.keys(this.getDirListing(i,t,r))}chmodSync(t,e,i){this.openFileSync(t,N.getFileFlag("r+"),i).chmodSync(e)}chownSync(t,e,i,r){this.openFileSync(t,N.getFileFlag("r+"),r).chownSync(e,i)}_syncSync(t,e,i){let r=this.store.beginTransaction("readwrite"),s=this._findINode(r,y(t),_(t)),n=this.getINode(r,t,s),c=n.update(i);try{r.put(n.id,e,!0),c&&r.put(s,n.serialize(),!0)}catch(h){throw r.abort(),h}r.commit()}makeRootDirectory(){let t=this.store.beginTransaction("readwrite");if(t.get(P)===void 0){let e=new Date().getTime(),i=new I(Q(),4096,511|g.DIRECTORY,e,e,e,0,0);t.put(i.id,E("{}"),!1),t.put(P,i.serialize(),!1),t.commit()}}_findINode(t,e,i,r=new Set){let s=F(e,i);if(r.has(s))throw new a(l.EIO,"Infinite loop detected while finding inode",s);r.add(s);let n=u(c=>{let h=this.getDirListing(t,e,c);if(h[i])return h[i];throw a.ENOENT(H(e,i))},"readDirectory");return e==="/"?i===""?P:n(this.getINode(t,e,P)):n(this.getINode(t,e+z+i,this._findINode(t,y(e),_(e),r)))}findINode(t,e){return this.getINode(t,e,this._findINode(t,y(e),_(e)))}getINode(t,e,i){let r=t.get(i);if(r===void 0)throw a.ENOENT(e);return I.Deserialize(r)}getDirListing(t,e,i){if(!i.isDirectory())throw a.ENOTDIR(e);let r=t.get(i.id);if(r===void 0)throw a.ENOENT(e);return JSON.parse(C(r))}addNewNode(t,e){let r;for(;0<5;)try{return r=Q(),t.put(r,e,!1),r}catch{}throw new a(l.EIO,"Unable to commit data to key-value store.")}commitNewFile(t,e,i,r,s,n){let c=y(e),h=_(e),d=this.findINode(t,c),f=this.getDirListing(t,c,d),m=new Date().getTime();if(!d.toStats().hasAccess(4,s))throw a.EACCES(e);if(e==="/")throw a.EEXIST(e);if(f[h])throw a.EEXIST(e);let p;try{let w=this.addNewNode(t,n);p=new I(w,n.length,r|i,m,m,m,s.uid,s.gid);let S=this.addNewNode(t,p.serialize());f[h]=S,t.put(d.id,E(JSON.stringify(f)),!0)}catch(w){throw t.abort(),w}return t.commit(),p}removeEntry(t,e,i){let r=this.store.beginTransaction("readwrite"),s=y(t),n=this.findINode(r,s),c=this.getDirListing(r,s,n),h=_(t);if(!c[h])throw a.ENOENT(t);let d=c[h],f=this.getINode(r,t,d);if(!f.toStats().hasAccess(2,i))throw a.EACCES(t);if(delete c[h],!e&&f.isDirectory())throw a.EISDIR(t);if(e&&!f.isDirectory())throw a.ENOTDIR(t);try{r.del(f.id),r.del(d),r.put(n.id,E(JSON.stringify(c)),!0)}catch(m){throw r.abort(),m}r.commit()}};u(V,"SyncKeyValueFileSystem");function T(o,t){t=typeof o=="function"?o:t,Vt(this,o);let e=new this(typeof o=="function"?{}:o);if(typeof t!="function")return e.whenReady();e.whenReady().then(i=>t(null,i)).catch(i=>t(i))}u(T,"CreateBackend");var Kt,bt=class{constructor(){this.store=new Map}name(){return v.Name}clear(){this.store.clear()}beginTransaction(t){return new j(this)}get(t){return this.store.get(t)}put(t,e,i){return!i&&this.store.has(t)?!1:(this.store.set(t,e),!0)}del(t){this.store.delete(t)}};u(bt,"InMemoryStore");var v=class extends V{constructor(){super({store:new bt})}};u(v,"InMemoryFileSystem");Kt=v;v.Name="InMemory";v.Create=T.bind(Kt);v.Options={};var ni=D.Root;var Mt=new Map;v.Create().then(o=>he("/",o));function Nt(o){return Mt.get(o)}u(Nt,"getMount");function he(o,t){if(o[0]!=="/"&&(o="/"+o),o=H(o),Mt.has(o))throw new a(l.EINVAL,"Mount point "+o+" is already in use.");Mt.set(o,t)}u(he,"mount");var b;(function(o){o[o.NOP=0]="NOP",o[o.THROW_EXCEPTION=1]="THROW_EXCEPTION",o[o.TRUNCATE_FILE=2]="TRUNCATE_FILE",o[o.CREATE_FILE=3]="CREATE_FILE"})(b=b||(b={}));var N=class{static getFileFlag(t){return N.flagCache.has(t)||N.flagCache.set(t,new N(t)),N.flagCache.get(t)}constructor(t){if(typeof t=="number"&&(t=N.StringFromNumber(t)),N.validFlagStrs.indexOf(t)<0)throw new a(l.EINVAL,"Invalid flag string: "+t);this.flagStr=t}static StringFromNumber(t){switch(t){case 0:return"r";case 1052672:return"rs";case 2:return"r+";case 1052674:return"rs+";case 577:return"w";case 705:return"wx";case 578:return"w+";case 706:return"wx+";case 1089:return"a";case 1217:return"ax";case 1090:return"a+";case 1218:return"ax+";default:throw new a(l.EINVAL,"Invalid flag number: "+t)}}getFlagString(){return this.flagStr}getMode(){let t=0;return t<<=1,t+=+this.isReadable(),t<<=1,t+=+this.isWriteable(),t<<=1,t}isReadable(){return this.flagStr.indexOf("r")!==-1||this.flagStr.indexOf("+")!==-1}isWriteable(){return this.flagStr.indexOf("w")!==-1||this.flagStr.indexOf("a")!==-1||this.flagStr.indexOf("+")!==-1}isTruncating(){return this.flagStr.indexOf("w")!==-1}isAppendable(){return this.flagStr.indexOf("a")!==-1}isSynchronous(){return this.flagStr.indexOf("s")!==-1}isExclusive(){return this.flagStr.indexOf("x")!==-1}pathExistsAction(){return this.isExclusive()?b.THROW_EXCEPTION:this.isTruncating()?b.TRUNCATE_FILE:b.NOP}pathNotExistsAction(){return(this.isWriteable()||this.isAppendable())&&this.flagStr!=="r+"?b.CREATE_FILE:b.THROW_EXCEPTION}};u(N,"FileFlag");N.flagCache=new Map;N.validFlagStrs=["r","r+","rs","rs+","w","wx","w+","wx+","a","ax","a+","ax+"];var Ft=class{async sync(){throw new a(l.ENOTSUP)}syncSync(){throw new a(l.ENOTSUP)}async datasync(){return this.sync()}datasyncSync(){return this.syncSync()}async chown(t,e){throw new a(l.ENOTSUP)}chownSync(t,e){throw new a(l.ENOTSUP)}async chmod(t){throw new a(l.ENOTSUP)}chmodSync(t){throw new a(l.ENOTSUP)}async utimes(t,e){throw new a(l.ENOTSUP)}utimesSync(t,e){throw new a(l.ENOTSUP)}};u(Ft,"BaseFile");var A=class extends Ft{constructor(t,e,i,r,s){if(super(),this._pos=0,this._dirty=!1,this._fs=t,this._path=e,this._flag=i,this._stat=r,this._buffer=s||new Uint8Array(0),this._stat.size!==this._buffer.length&&this._flag.isReadable())throw new Error(`Invalid buffer: Uint8Array is ${this._buffer.length} long, yet Stats object specifies that file is ${this._stat.size} long.`)}getBuffer(){return this._buffer}getStats(){return this._stat}getFlag(){return this._flag}getPath(){return this._path}getPos(){return this._flag.isAppendable()?this._stat.size:this._pos}advancePos(t){return this._pos+=t}setPos(t){return this._pos=t}async sync(){this.syncSync()}syncSync(){throw new a(l.ENOTSUP)}async close(){this.closeSync()}closeSync(){throw new a(l.ENOTSUP)}async stat(){return x.clone(this._stat)}statSync(){return x.clone(this._stat)}truncate(t){if(this.truncateSync(t),this._flag.isSynchronous()&&!Nt("/").metadata.synchronous)return this.sync()}truncateSync(t){if(this._dirty=!0,!this._flag.isWriteable())throw new a(l.EPERM,"File not opened with a writeable mode.");if(this._stat.mtimeMs=Date.now(),t>this._buffer.length){let e=new Uint8Array(t-this._buffer.length);this.writeSync(e,0,e.length,this._buffer.length),this._flag.isSynchronous()&&Nt("/").metadata.synchronous&&this.syncSync();return}this._stat.size=t,this._buffer=this._buffer.subarray(0,t),this._flag.isSynchronous()&&Nt("/").metadata.synchronous&&this.syncSync()}async write(t,e,i,r){return this.writeSync(t,e,i,r)}writeSync(t,e,i,r){if(this._dirty=!0,r==null&&(r=this.getPos()),!this._flag.isWriteable())throw new a(l.EPERM,"File not opened with a writeable mode.");let s=r+i;if(s>this._stat.size&&(this._stat.size=s,s>this._buffer.length)){let c=new Uint8Array(s);c.set(this._buffer),this._buffer=c}this._buffer.set(t.slice(e,e+i),r);let n=this._buffer.length;return this._stat.mtimeMs=Date.now(),this._flag.isSynchronous()?(this.syncSync(),n):(this.setPos(r+n),n)}async read(t,e,i,r){return{bytesRead:this.readSync(t,e,i,r),buffer:t}}readSync(t,e,i,r){if(!this._flag.isReadable())throw new a(l.EPERM,"File not opened with a readable mode.");return r==null&&(r=this.getPos()),r+i>this._stat.size&&(i=this._stat.size-r),this._buffer.set(t.slice(e,e+i),r),this._stat.atimeMs=Date.now(),this._pos=r+i,this._buffer.length}async chmod(t){this.chmodSync(t)}chmodSync(t){if(!this._fs.metadata.supportsProperties)throw new a(l.ENOTSUP);this._dirty=!0,this._stat.chmod(t),this.syncSync()}async chown(t,e){this.chownSync(t,e)}chownSync(t,e){if(!this._fs.metadata.supportsProperties)throw new a(l.ENOTSUP);this._dirty=!0,this._stat.chown(t,e),this.syncSync()}isDirty(){return this._dirty}resetDirty(){this._dirty=!1}};u(A,"PreloadFile");var W=class extends A{constructor(t,e,i,r,s){super(t,e,i,r,s)}async sync(){}syncSync(){}async close(){}closeSync(){}};u(W,"NoSyncFile");var Tt=u((o="",t)=>{throw t.name==="NotFoundError"?a.ENOENT(o):t},"handleError"),ot=class extends A{constructor(t,e,i,r,s){super(t,e,i,r,s)}async sync(){this.isDirty()&&(await this._fs._sync(this.getPath(),this.getBuffer(),this.getStats(),D.Root),this.resetDirty())}async close(){await this.sync()}};u(ot,"FileSystemAccessFile");var Pt=class extends O{constructor({handle:e}){super();this._handles=new Map;this._handles.set("/",e)}static isAvailable(){return typeof FileSystemHandle=="function"}get metadata(){return{...super.metadata,name:Pt.Name}}async _sync(e,i,r,s){let n=await this.stat(e,s);r.mtime!==n.mtime&&await this.writeFile(e,i,N.getFileFlag("w"),n.mode,s)}async rename(e,i,r){try{let s=await this.getHandle(e);if(s instanceof FileSystemDirectoryHandle){let n=await this.readdir(e,r);if(await this.mkdir(i,"wx",r),n.length===0)await this.unlink(e,r);else for(let c of n)await this.rename(F(e,c),F(i,c),r),await this.unlink(e,r)}if(s instanceof FileSystemFileHandle){let n=await s.getFile(),c=await this.getHandle(y(i));if(c instanceof FileSystemDirectoryHandle){let d=await(await c.getFileHandle(_(i),{create:!0})).createWritable(),f=await n.arrayBuffer();await d.write(f),d.close(),await this.unlink(e,r)}}}catch(s){Tt(e,s)}}async writeFile(e,i,r,s,n,c){let h=await this.getHandle(y(e));if(h instanceof FileSystemDirectoryHandle){let f=await(await h.getFileHandle(_(e),{create:!0})).createWritable();await f.write(i),await f.close()}}async createFile(e,i,r,s){return await this.writeFile(e,new Uint8Array,i,r,s,!0),this.openFile(e,i,s)}async stat(e,i){let r=await this.getHandle(e);if(!r)throw a.FileError(l.EINVAL,e);if(r instanceof FileSystemDirectoryHandle)return new x(g.DIRECTORY,4096);if(r instanceof FileSystemFileHandle){let{lastModified:s,size:n}=await r.getFile();return new x(g.FILE,n,void 0,void 0,s)}}async exists(e,i){try{return await this.getHandle(e),!0}catch{return!1}}async openFile(e,i,r){let s=await this.getHandle(e);if(s instanceof FileSystemFileHandle){let n=await s.getFile(),c=await n.arrayBuffer();return this.newFile(e,i,c,n.size,n.lastModified)}}async unlink(e,i){let r=await this.getHandle(y(e));if(r instanceof FileSystemDirectoryHandle)try{await r.removeEntry(_(e),{recursive:!0})}catch(s){Tt(e,s)}}async rmdir(e,i){return this.unlink(e,i)}async mkdir(e,i,r){let s=i&&i.flag&&i.flag.includes("w")&&!i.flag.includes("x");if(await this.getHandle(e)&&!s)throw a.EEXIST(e);let c=await this.getHandle(y(e));c instanceof FileSystemDirectoryHandle&&await c.getDirectoryHandle(_(e),{create:!0})}async readdir(e,i){let r=await this.getHandle(e);if(!(r instanceof FileSystemDirectoryHandle))throw a.ENOTDIR(e);let s=[];for await(let n of r.keys())s.push(F(e,n));return s}newFile(e,i,r,s,n){return new ot(this,e,i,new x(g.FILE,s||0,void 0,void 0,n||new Date().getTime()),new Uint8Array(r))}async getHandle(e){if(this._handles.has(e))return this._handles.get(e);let i="/",[,...r]=e.split("/"),s=u(async([n,...c])=>{let h=F(i,n),d=u(m=>{if(i=h,this._handles.set(i,m),c.length===0)return this._handles.get(e);s(c)},"continueWalk"),f=this._handles.get(i);try{return await d(await f.getDirectoryHandle(n))}catch(m){if(m.name==="TypeMismatchError")try{return await d(await f.getFileHandle(n))}catch(p){Tt(h,p)}else{if(m.message==="Name is not allowed.")throw new a(l.ENOENT,m.message,h);Tt(h,m)}}},"getHandleParts");await s(r)}},Y=Pt;u(Y,"FileSystemAccessFileSystem"),Y.Name="FileSystemAccess",Y.Create=T.bind(Pt),Y.Options={};var Qt=typeof fetch<"u"&&fetch!==null;function Dt(o){throw new a(l.EIO,o.message)}u(Dt,"convertError");async function Lt(o,t){let e=await fetch(o).catch(Dt);if(!e.ok)throw new a(l.EIO,`fetch error: response returned code ${e.status}`);switch(t){case"buffer":let i=await e.arrayBuffer().catch(Dt);return new Uint8Array(i);case"json":return e.json().catch(Dt);default:throw new a(l.EINVAL,"Invalid download type: "+t)}}u(Lt,"fetchFile");async function Zt(o){let t=await fetch(o,{method:"HEAD"}).catch(Dt);if(!t.ok)throw new a(l.EIO,`fetch HEAD error: response returned code ${t.status}`);return parseInt(t.headers.get("Content-Length")||"-1",10)}u(Zt,"fetchFileSize");var q=class{static fromListing(t){let e=new q,i=new M;e._index["/"]=i;let r=[["",t,i]];for(;r.length>0;){let s,n=r.pop(),c=n[0],h=n[1],d=n[2];for(let f in h)if(Object.prototype.hasOwnProperty.call(h,f)){let m=h[f],p=`${c}/${f}`;m?(e._index[p]=s=new M,r.push([p,m,s])):s=new Ct(new x(g.FILE,-1,365)),d&&(d._ls[f]=s)}}return e}constructor(){this._index={},this.addPath("/",new M)}fileIterator(t){for(let e in this._index)if(Object.prototype.hasOwnProperty.call(this._index,e)){let i=this._index[e],r=i.getListing();for(let s of r){let n=i.getItem(s);at(n)&&t(n.getData())}}}addPath(t,e){if(!e)throw new Error("Inode must be specified");if(t[0]!=="/")throw new Error("Path must be absolute, got: "+t);if(Object.prototype.hasOwnProperty.call(this._index,t))return this._index[t]===e;let i=this._split_path(t),r=i[0],s=i[1],n=this._index[r];return n===void 0&&t!=="/"&&(n=new M,!this.addPath(r,n))||t!=="/"&&!n.addItem(s,e)?!1:(et(e)&&(this._index[t]=e),!0)}addPathFast(t,e){let i=t.lastIndexOf("/"),r=i===0?"/":t.substring(0,i),s=t.substring(i+1),n=this._index[r];return n===void 0&&(n=new M,this.addPathFast(r,n)),n.addItem(s,e)?(e.isDir()&&(this._index[t]=e),!0):!1}removePath(t){let e=this._split_path(t),i=e[0],r=e[1],s=this._index[i];if(s===void 0)return null;let n=s.remItem(r);if(n===null)return null;if(et(n)){let c=n.getListing();for(let h of c)this.removePath(t+"/"+h);t!=="/"&&delete this._index[t]}return n}ls(t){let e=this._index[t];return e===void 0?null:e.getListing()}getInode(t){let e=this._split_path(t),i=e[0],r=e[1],s=this._index[i];return s===void 0?null:i===t?s:s.getItem(r)}_split_path(t){let e=y(t),i=t.slice(e.length+(e==="/"?0:1));return[e,i]}};u(q,"FileIndex");var Ct=class{constructor(t){this.data=t}isFile(){return!0}isDir(){return!1}getData(){return this.data}setData(t){this.data=t}toStats(){return new x(g.FILE,4096,438)}};u(Ct,"IndexFileInode");var M=class{constructor(t=null){this.data=t,this._ls={}}isFile(){return!1}isDir(){return!0}getData(){return this.data}getStats(){return new x(g.DIRECTORY,4096,365)}toStats(){return this.getStats()}getListing(){return Object.keys(this._ls)}getItem(t){let e=this._ls[t];return e||null}addItem(t,e){return t in this._ls?!1:(this._ls[t]=e,!0)}remItem(t){let e=this._ls[t];return e===void 0?null:(delete this._ls[t],e)}};u(M,"IndexDirInode");function at(o){return!!o&&o.isFile()}u(at,"isIndexFileInode");function et(o){return!!o&&o.isDir()}u(et,"isIndexDirInode");var Rt=class extends O{constructor({index:e,baseUrl:i=""}){super();e||(e="index.json");let r=typeof e=="string"?Lt(e,"json"):Promise.resolve(e);this._ready=r.then(s=>(this._index=q.fromListing(s),this)),i.length>0&&i.charAt(i.length-1)!=="/"&&(i=i+"/"),this.prefixUrl=i}static isAvailable(){return Qt}get metadata(){return{...super.metadata,name:Rt.Name,readonly:!0}}empty(){this._index.fileIterator(function(e){e.fileData=null})}preloadFile(e,i){let r=this._index.getInode(e);if(at(r)){if(r===null)throw a.ENOENT(e);let s=r.getData();s.size=i.length,s.fileData=i}else throw a.EISDIR(e)}async stat(e,i){let r=this._index.getInode(e);if(r===null)throw a.ENOENT(e);if(!r.toStats().hasAccess(4,i))throw a.EACCES(e);let s;if(at(r))s=r.getData(),s.size<0&&(s.size=await this._requestFileSize(e));else if(et(r))s=r.getStats();else throw a.FileError(l.EINVAL,e);return s}async open(e,i,r,s){if(i.isWriteable())throw new a(l.EPERM,e);let n=this._index.getInode(e);if(n===null)throw a.ENOENT(e);if(!n.toStats().hasAccess(i.getMode(),s))throw a.EACCES(e);if(at(n)||et(n))switch(i.pathExistsAction()){case b.THROW_EXCEPTION:case b.TRUNCATE_FILE:throw a.EEXIST(e);case b.NOP:if(et(n)){let d=n.getStats();return new W(this,e,i,d,d.fileData||void 0)}let c=n.getData();if(c.fileData)return new W(this,e,i,x.clone(c),c.fileData);let h=await this._requestFile(e,"buffer");return c.size=h.length,c.fileData=h,new W(this,e,i,x.clone(c),h);default:throw new a(l.EINVAL,"Invalid FileMode object.")}else throw a.EPERM(e)}async readdir(e,i){return this.readdirSync(e,i)}async readFile(e,i,r){let s=await this.open(e,i,420,r);try{return s.getBuffer()}finally{await s.close()}}_getHTTPPath(e){return e.charAt(0)==="/"&&(e=e.slice(1)),this.prefixUrl+e}_requestFile(e,i){return Lt(this._getHTTPPath(e),i)}_requestFileSize(e){return Zt(this._getHTTPPath(e))}},X=Rt;u(X,"HTTPRequest"),X.Name="HTTPRequest",X.Create=T.bind(Rt),X.Options={index:{type:["string","object"],optional:!0,description:"URL to a file index as a JSON file or the file index object itself, generated with the make_http_index script. Defaults to `index.json`."},baseUrl:{type:"string",optional:!0,description:"Used as the URL prefix for fetched files. Default: Fetch files relative to the index."}};var ct=class{constructor(t,e){this.key=t,this.value=e,this.prev=null,this.next=null}};u(ct,"LRUNode");var At=class{constructor(t){this.limit=t,this.size=0,this.map={},this.head=null,this.tail=null}set(t,e){let i=new ct(t,e);this.map[t]?(this.map[t].value=i.value,this.remove(i.key)):this.size>=this.limit&&(delete this.map[this.tail.key],this.size--,this.tail=this.tail.prev,this.tail.next=null),this.setHead(i)}get(t){if(this.map[t]){let e=this.map[t].value,i=new ct(t,e);return this.remove(t),this.setHead(i),e}else return null}remove(t){let e=this.map[t];e&&(e.prev!==null?e.prev.next=e.next:this.head=e.next,e.next!==null?e.next.prev=e.prev:this.tail=e.prev,delete this.map[t],this.size--)}removeAll(){this.size=0,this.map={},this.head=null,this.tail=null}setHead(t){t.next=this.head,t.prev=null,this.head!==null&&(this.head.prev=t),this.head=t,this.tail===null&&(this.tail=t),this.size++,this.map[t.key]=t}};u(At,"LRUCache");var lt=class extends A{constructor(t,e,i,r,s){super(t,e,i,r,s)}async sync(){this.isDirty()&&(await this._fs._sync(this.getPath(),this.getBuffer(),this.getStats()),this.resetDirty())}async close(){this.sync()}};u(lt,"AsyncKeyValueFile");var ht=class extends O{static isAvailable(){return!0}constructor(t){super(),this._cache=null,t>0&&(this._cache=new At(t))}async init(t){this.store=t,await this.makeRootDirectory()}getName(){return this.store.name()}isReadOnly(){return!1}supportsSymlinks(){return!1}supportsProps(){return!0}supportsSynch(){return!1}async empty(){this._cache&&this._cache.removeAll(),await this.store.clear(),await this.makeRootDirectory()}async access(t,e,i){let r=this.store.beginTransaction("readonly"),s=await this.findINode(r,t);if(!s)throw a.ENOENT(t);if(!s.toStats().hasAccess(e,i))throw a.EACCES(t)}async rename(t,e,i){let r=this._cache;this._cache&&(this._cache=null,r.removeAll());try{let s=this.store.beginTransaction("readwrite"),n=y(t),c=_(t),h=y(e),d=_(e),f=await this.findINode(s,n),m=await this.getDirListing(s,n,f);if(!f.toStats().hasAccess(2,i))throw a.EACCES(t);if(!m[c])throw a.ENOENT(t);let p=m[c];if(delete m[c],(h+"/").indexOf(t+"/")===0)throw new a(l.EBUSY,n);let w,S;if(h===n?(w=f,S=m):(w=await this.findINode(s,h),S=await this.getDirListing(s,h,w)),S[d]){let U=await this.getINode(s,e,S[d]);if(U.isFile())try{await s.del(U.id),await s.del(S[d])}catch(rt){throw await s.abort(),rt}else throw a.EPERM(e)}S[d]=p;try{await s.put(f.id,E(JSON.stringify(m)),!0),await s.put(w.id,E(JSON.stringify(S)),!0)}catch(U){throw await s.abort(),U}await s.commit()}finally{r&&(this._cache=r)}}async stat(t,e){let i=this.store.beginTransaction("readonly"),s=(await this.findINode(i,t)).toStats();if(!s.hasAccess(4,e))throw a.EACCES(t);return s}async createFile(t,e,i,r){let s=this.store.beginTransaction("readwrite"),n=new Uint8Array(0),c=await this.commitNewFile(s,t,g.FILE,i,r,n);return new lt(this,t,e,c.toStats(),n)}async openFile(t,e,i){let r=this.store.beginTransaction("readonly"),s=await this.findINode(r,t),n=await r.get(s.id);if(!s.toStats().hasAccess(e.getMode(),i))throw a.EACCES(t);if(n===void 0)throw a.ENOENT(t);return new lt(this,t,e,s.toStats(),n)}async unlink(t,e){return this.removeEntry(t,!1,e)}async rmdir(t,e){if((await this.readdir(t,e)).length>0)throw a.ENOTEMPTY(t);await this.removeEntry(t,!0,e)}async mkdir(t,e,i){let r=this.store.beginTransaction("readwrite"),s=E("{}");await this.commitNewFile(r,t,g.DIRECTORY,e,i,s)}async readdir(t,e){let i=this.store.beginTransaction("readonly"),r=await this.findINode(i,t);if(!r.toStats().hasAccess(4,e))throw a.EACCES(t);return Object.keys(await this.getDirListing(i,t,r))}async chmod(t,e,i){await(await this.openFile(t,N.getFileFlag("r+"),i)).chmod(e)}async chown(t,e,i,r){await(await this.openFile(t,N.getFileFlag("r+"),r)).chown(e,i)}async _sync(t,e,i){let r=this.store.beginTransaction("readwrite"),s=await this._findINode(r,y(t),_(t)),n=await this.getINode(r,t,s),c=n.update(i);try{await r.put(n.id,e,!0),c&&await r.put(s,n.serialize(),!0)}catch(h){throw await r.abort(),h}await r.commit()}async makeRootDirectory(){let t=this.store.beginTransaction("readwrite");if(await t.get(P)===void 0){let e=new Date().getTime(),i=new I(Q(),4096,511|g.DIRECTORY,e,e,e,0,0);await t.put(i.id,E("{}"),!1),await t.put(P,i.serialize(),!1),await t.commit()}}async _findINode(t,e,i,r=new Set){let s=F(e,i);if(r.has(s))throw new a(l.EIO,"Infinite loop detected while finding inode",s);if(r.add(s),this._cache){let n=this._cache.get(s);if(n)return n}if(e==="/"){if(i==="")return this._cache&&this._cache.set(s,P),P;{let n=await this.getINode(t,e,P),c=await this.getDirListing(t,e,n);if(c[i]){let h=c[i];return this._cache&&this._cache.set(s,h),h}else throw a.ENOENT(H(e,i))}}else{let n=await this.findINode(t,e,r),c=await this.getDirListing(t,e,n);if(c[i]){let h=c[i];return this._cache&&this._cache.set(s,h),h}else throw a.ENOENT(H(e,i))}}async findINode(t,e,i=new Set){let r=await this._findINode(t,y(e),_(e),i);return this.getINode(t,e,r)}async getINode(t,e,i){let r=await t.get(i);if(!r)throw a.ENOENT(e);return I.Deserialize(r)}async getDirListing(t,e,i){if(!i.isDirectory())throw a.ENOTDIR(e);let r=await t.get(i.id);try{return JSON.parse(C(r))}catch{throw a.ENOENT(e)}}async addNewNode(t,e){let i=0,r=u(async()=>{if(++i===5)throw new a(l.EIO,"Unable to commit data to key-value store.");{let s=Q();return await t.put(s,e,!1)?s:r()}},"reroll");return r()}async commitNewFile(t,e,i,r,s,n){let c=y(e),h=_(e),d=await this.findINode(t,c),f=await this.getDirListing(t,c,d),m=new Date().getTime();if(!d.toStats().hasAccess(2,s))throw a.EACCES(e);if(e==="/")throw a.EEXIST(e);if(f[h])throw await t.abort(),a.EEXIST(e);try{let p=await this.addNewNode(t,n),w=new I(p,n.length,r|i,m,m,m,s.uid,s.gid),S=await this.addNewNode(t,w.serialize());return f[h]=S,await t.put(d.id,E(JSON.stringify(f)),!0),await t.commit(),w}catch(p){throw t.abort(),p}}async removeEntry(t,e,i){this._cache&&this._cache.remove(t);let r=this.store.beginTransaction("readwrite"),s=y(t),n=await this.findINode(r,s),c=await this.getDirListing(r,s,n),h=_(t);if(!c[h])throw a.ENOENT(t);let d=c[h],f=await this.getINode(r,t,d);if(!f.toStats().hasAccess(2,i))throw a.EACCES(t);if(delete c[h],!e&&f.isDirectory())throw a.EISDIR(t);if(e&&!f.isDirectory())throw a.ENOTDIR(t);try{await r.del(f.id),await r.del(d),await r.put(n.id,E(JSON.stringify(c)),!0)}catch(m){throw await r.abort(),m}await r.commit()}};u(ht,"AsyncKeyValueFileSystem");function ut(o,t=o.toString()){switch(o.name){case"NotFoundError":return new a(l.ENOENT,t);case"QuotaExceededError":return new a(l.ENOSPC,t);default:return new a(l.EIO,t)}}u(ut,"convertError");function ft(o,t=l.EIO,e=null){return function(i){i.preventDefault(),o(new a(t,e!==null?e:void 0))}}u(ft,"onErrorHandler");var it=class{constructor(t,e){this.tx=t;this.store=e}get(t){return new Promise((e,i)=>{try{let r=this.store.get(t);r.onerror=ft(i),r.onsuccess=s=>{let n=s.target.result;e(n===void 0?n:Uint8Array.from(n))}}catch(r){i(ut(r))}})}};u(it,"IndexedDBROTransaction");var dt=class extends it{constructor(t,e){super(t,e)}put(t,e,i){return new Promise((r,s)=>{try{let n=i?this.store.put(e,t):this.store.add(e,t);n.onerror=ft(s),n.onsuccess=()=>{r(!0)}}catch(n){s(ut(n))}})}del(t){return new Promise((e,i)=>{try{let r=this.store.delete(t);r.onerror=ft(i),r.onsuccess=()=>{e()}}catch(r){i(ut(r))}})}commit(){return new Promise(t=>{setTimeout(t,0)})}abort(){return new Promise((t,e)=>{try{this.tx.abort(),t()}catch(i){e(ut(i))}})}};u(dt,"IndexedDBRWTransaction");var K=class{constructor(t,e){this.db=t;this.storeName=e}static Create(t,e){return new Promise((i,r)=>{let s=e.open(t,1);s.onupgradeneeded=n=>{let c=n.target.result;c.objectStoreNames.contains(t)&&c.deleteObjectStore(t),c.createObjectStore(t)},s.onsuccess=n=>{i(new K(n.target.result,t))},s.onerror=ft(r,l.EACCES)})}name(){return L.Name+" - "+this.storeName}clear(){return new Promise((t,e)=>{try{let i=this.db.transaction(this.storeName,"readwrite"),r=i.objectStore(this.storeName),s=r.clear();s.onsuccess=()=>{setTimeout(t,0)},s.onerror=ft(e)}catch(i){e(ut(i))}})}beginTransaction(t="readonly"){let e=this.db.transaction(this.storeName,t),i=e.objectStore(this.storeName);if(t==="readwrite")return new dt(e,i);if(t==="readonly")return new it(e,i);throw new a(l.EINVAL,"Invalid transaction type.")}};u(K,"IndexedDBStore");var Bt=class extends ht{static isAvailable(t=globalThis.indexedDB){try{if(!(t instanceof IDBFactory)||!t.open("__zenfs_test__"))return!1}catch{return!1}}constructor({cacheSize:t=100,storeName:e="zenfs",idbFactory:i=globalThis.indexedDB}){super(t),this._ready=K.Create(e,i).then(r=>(this.init(r),this))}},L=Bt;u(L,"IndexedDBFileSystem"),L.Name="IndexedDB",L.Create=T.bind(Bt),L.Options={storeName:{type:"string",optional:!0,description:"The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name."},cacheSize:{type:"number",optional:!0,description:"The size of the inode cache. Defaults to 100. A size of 0 or below disables caching."},idbFactory:{type:"object",optional:!0,description:"The IDBFactory to use. Defaults to globalThis.indexedDB."}};var mt=class{constructor(t){this._storage=t}name(){return B.Name}clear(){this._storage.clear()}beginTransaction(t){return new j(this)}get(t){let e=this._storage.getItem(t);if(typeof e=="string")return E(e)}put(t,e,i){try{return!i&&this._storage.getItem(t)!==null?!1:(this._storage.setItem(t,C(e)),!0)}catch{throw new a(l.ENOSPC,"Storage is full.")}}del(t){try{this._storage.removeItem(t)}catch(e){throw new a(l.EIO,"Unable to delete key "+t+": "+e)}}};u(mt,"StorageStore");var zt=class extends V{static isAvailable(t=globalThis.localStorage){return t instanceof Storage}constructor({storage:t=globalThis.localStorage}){super({store:new mt(t)})}},B=zt;u(B,"StorageFileSystem"),B.Name="Storage",B.Create=T.bind(zt),B.Options={storage:{type:"object",optional:!0,description:"The Storage to use. Defaults to globalThis.localStorage."}};function ue(o){return typeof o=="object"&&"isBFS"in o&&!!o.isBFS}u(ue,"isRPCMessage");var vt=class extends O{constructor({worker:e}){super();this._currentID=0;this._requests=new Map;this._isInitialized=!1;this._worker=e,this._worker.onmessage=i=>{if(!ue(i.data))return;let{id:r,method:s,value:n}=i.data;if(s==="metadata"){this._metadata=n,this._isInitialized=!0;return}let{resolve:c,reject:h}=this._requests.get(r);if(this._requests.delete(r),n instanceof Error||n instanceof a){h(n);return}c(n)}}static isAvailable(){return typeof importScripts<"u"||typeof Worker<"u"}get metadata(){return{...super.metadata,...this._metadata,name:vt.Name,synchronous:!1}}async _rpc(e,...i){return new Promise((r,s)=>{let n=this._currentID++;this._requests.set(n,{resolve:r,reject:s}),this._worker.postMessage({isBFS:!0,id:n,method:e,args:i})})}rename(e,i,r){return this._rpc("rename",e,i,r)}stat(e,i){return this._rpc("stat",e,i)}open(e,i,r,s){return this._rpc("open",e,i,r,s)}unlink(e,i){return this._rpc("unlink",e,i)}rmdir(e,i){return this._rpc("rmdir",e,i)}mkdir(e,i,r){return this._rpc("mkdir",e,i,r)}readdir(e,i){return this._rpc("readdir",e,i)}exists(e,i){return this._rpc("exists",e,i)}realpath(e,i){return this._rpc("realpath",e,i)}truncate(e,i,r){return this._rpc("truncate",e,i,r)}readFile(e,i,r){return this._rpc("readFile",e,i,r)}writeFile(e,i,r,s,n){return this._rpc("writeFile",e,i,r,s,n)}appendFile(e,i,r,s,n){return this._rpc("appendFile",e,i,r,s,n)}chmod(e,i,r){return this._rpc("chmod",e,i,r)}chown(e,i,r,s){return this._rpc("chown",e,i,r,s)}utimes(e,i,r,s){return this._rpc("utimes",e,i,r,s)}link(e,i,r){return this._rpc("link",e,i,r)}symlink(e,i,r,s){return this._rpc("symlink",e,i,r,s)}readlink(e,i){return this._rpc("readlink",e,i)}syncClose(e,i){return this._rpc("syncClose",e,i)}},J=vt;u(J,"WorkerFS"),J.Name="WorkerFS",J.Create=T.bind(vt),J.Options={worker:{type:"object",description:"The target worker that you want to connect to, or the current worker if in a worker context.",validator(e){if(typeof e?.postMessage!="function")throw new a(l.EINVAL,"option must be a Web Worker instance.")}}};return ne(de);})();
|
|
4
4
|
//# sourceMappingURL=browser.min.js.map
|