@zenfs/dom 0.2.6 → 0.2.7

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.
@@ -49,7 +49,7 @@ export declare const IndexedDB: {
49
49
  readonly required: false;
50
50
  readonly description: "The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name.";
51
51
  };
52
- readonly cacheSize: {
52
+ readonly lruCacheSize: {
53
53
  readonly type: "number";
54
54
  readonly required: false;
55
55
  readonly description: "The size of the inode cache. Defaults to 100. A size of 0 or below disables caching.";
package/dist/IndexedDB.js CHANGED
@@ -82,7 +82,7 @@ export const IndexedDB = {
82
82
  required: false,
83
83
  description: 'The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name.',
84
84
  },
85
- cacheSize: {
85
+ lruCacheSize: {
86
86
  type: 'number',
87
87
  required: false,
88
88
  description: 'The size of the inode cache. Defaults to 100. A size of 0 or below disables caching.',
package/dist/Storage.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ApiError, ErrorCode, SimpleSyncTransaction, SyncStoreFS, decode, encode } from '@zenfs/core';
1
+ import { ErrnoError, Errno, SimpleSyncTransaction, SyncStoreFS, decode, encode } from '@zenfs/core';
2
2
  /**
3
3
  * A synchronous key-value store backed by Storage.
4
4
  */
@@ -33,7 +33,7 @@ export class WebStorageStore {
33
33
  return true;
34
34
  }
35
35
  catch (e) {
36
- throw new ApiError(ErrorCode.ENOSPC, 'Storage is full.');
36
+ throw new ErrnoError(Errno.ENOSPC, 'Storage is full.');
37
37
  }
38
38
  }
39
39
  remove(key) {
@@ -41,7 +41,7 @@ export class WebStorageStore {
41
41
  this._storage.removeItem(key.toString());
42
42
  }
43
43
  catch (e) {
44
- throw new ApiError(ErrorCode.EIO, 'Unable to delete key ' + key + ': ' + e);
44
+ throw new ErrnoError(Errno.EIO, 'Unable to delete key ' + key + ': ' + e);
45
45
  }
46
46
  }
47
47
  }
package/dist/access.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ApiError, Async, ErrorCode, FileSystem, FileType, InMemory, PreloadFile, Stats } from '@zenfs/core';
1
+ import { ErrnoError, Async, Errno, FileSystem, FileType, InMemory, PreloadFile, Stats } from '@zenfs/core';
2
2
  import { basename, dirname, join } from '@zenfs/core/emulation/path.js';
3
3
  import { convertException } from './utils.js';
4
4
  export class WebAccessFS extends Async(FileSystem) {
@@ -70,7 +70,7 @@ export class WebAccessFS extends Async(FileSystem) {
70
70
  async stat(path) {
71
71
  const handle = await this.getHandle(path);
72
72
  if (!handle) {
73
- throw ApiError.With('ENOENT', path, 'stat');
73
+ throw ErrnoError.With('ENOENT', path, 'stat');
74
74
  }
75
75
  if (handle instanceof FileSystemDirectoryHandle) {
76
76
  return new Stats({ mode: 0o777 | FileType.DIRECTORY, size: 4096 });
@@ -79,12 +79,12 @@ export class WebAccessFS extends Async(FileSystem) {
79
79
  const { lastModified, size } = await handle.getFile();
80
80
  return new Stats({ mode: 0o777 | FileType.FILE, size, mtimeMs: lastModified });
81
81
  }
82
- throw new ApiError(ErrorCode.EBADE, 'Handle is not a directory or file', path, 'stat');
82
+ throw new ErrnoError(Errno.EBADE, 'Handle is not a directory or file', path, 'stat');
83
83
  }
84
84
  async openFile(path, flag) {
85
85
  const handle = await this.getHandle(path);
86
86
  if (!(handle instanceof FileSystemFileHandle)) {
87
- throw ApiError.With('EISDIR', path, 'openFile');
87
+ throw ErrnoError.With('EISDIR', path, 'openFile');
88
88
  }
89
89
  try {
90
90
  const file = await handle.getFile();
@@ -108,7 +108,7 @@ export class WebAccessFS extends Async(FileSystem) {
108
108
  }
109
109
  }
110
110
  async link(srcpath) {
111
- throw ApiError.With('ENOSYS', srcpath, 'WebAccessFS.link');
111
+ throw ErrnoError.With('ENOSYS', srcpath, 'WebAccessFS.link');
112
112
  }
113
113
  async rmdir(path) {
114
114
  return this.unlink(path);
@@ -116,18 +116,18 @@ export class WebAccessFS extends Async(FileSystem) {
116
116
  async mkdir(path) {
117
117
  const existingHandle = await this.getHandle(path);
118
118
  if (existingHandle) {
119
- throw ApiError.With('EEXIST', path, 'mkdir');
119
+ throw ErrnoError.With('EEXIST', path, 'mkdir');
120
120
  }
121
121
  const handle = await this.getHandle(dirname(path));
122
122
  if (!(handle instanceof FileSystemDirectoryHandle)) {
123
- throw ApiError.With('ENOTDIR', path, 'mkdir');
123
+ throw ErrnoError.With('ENOTDIR', path, 'mkdir');
124
124
  }
125
125
  await handle.getDirectoryHandle(basename(path), { create: true });
126
126
  }
127
127
  async readdir(path) {
128
128
  const handle = await this.getHandle(path);
129
129
  if (!(handle instanceof FileSystemDirectoryHandle)) {
130
- throw ApiError.With('ENOTDIR', path, 'readdir');
130
+ throw ErrnoError.With('ENOTDIR', path, 'readdir');
131
131
  }
132
132
  const _keys = [];
133
133
  for await (const key of handle.keys()) {
@@ -143,7 +143,7 @@ export class WebAccessFS extends Async(FileSystem) {
143
143
  for (const part of path.split('/').slice(1)) {
144
144
  const handle = this._handles.get(walked);
145
145
  if (!(handle instanceof FileSystemDirectoryHandle)) {
146
- throw ApiError.With('ENOTDIR', walked, 'getHandle');
146
+ throw ErrnoError.With('ENOTDIR', walked, 'getHandle');
147
147
  }
148
148
  walked = join(walked, part);
149
149
  try {
@@ -162,7 +162,7 @@ export class WebAccessFS extends Async(FileSystem) {
162
162
  }
163
163
  }
164
164
  if (ex.name === 'TypeError') {
165
- throw new ApiError(ErrorCode.ENOENT, ex.message, walked, 'getHandle');
165
+ throw new ErrnoError(Errno.ENOENT, ex.message, walked, 'getHandle');
166
166
  }
167
167
  convertException(ex, walked, 'getHandle');
168
168
  }
@@ -1,2 +1,2 @@
1
- "use strict";var ZenFS_DOM=(()=>{var F=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var c=(r,e)=>F(r,"name",{value:e,configurable:!0});var R=(r,e)=>{for(var t in e)F(r,t,{get:e[t],enumerable:!0})},U=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z(e))!W.call(r,i)&&i!==t&&F(r,i,{get:()=>e[i],enumerable:!(n=P(e,i))||n.enumerable});return r};var $=r=>U(F({},"__esModule",{value:!0}),r);var V={};R(V,{IndexedDB:()=>M,IndexedDBStore:()=>u,IndexedDBTransaction:()=>E,WebAccess:()=>Y,WebAccessFS:()=>b,WebStorage:()=>_,WebStorageStore:()=>w});var Z=ZenFS,{ActionType:Q,ApiError:l,Async:v,AsyncIndexFS:G,AsyncStoreFS:k,BigIntStats:J,BigIntStatsFs:K,Dir:ee,Dirent:te,ErrorCode:d,File:re,FileIndex:ne,FileSystem:T,FileType:x,InMemory:A,InMemoryStore:ie,IndexDirInode:oe,IndexFS:se,IndexFileInode:ae,IndexInode:ce,Inode:le,LockedFS:de,Mutex:fe,NoSyncFile:ue,Overlay:me,OverlayFS:ye,PreloadFile:H,ReadStream:Se,Readonly:ge,SimpleSyncTransaction:O,Stats:I,StatsCommon:pe,StatsFs:he,Sync:be,SyncIndexFS:Ee,SyncStoreFS:N,UnlockedOverlayFS:we,WriteStream:Fe,_toUnixTimestamp:xe,access:Ie,accessSync:De,appendFile:ve,appendFileSync:ke,checkOptions:Te,chmod:Ae,chmodSync:He,chown:Oe,chownSync:Ne,close:Be,closeSync:Ce,configure:Me,constants:_e,copyFile:Pe,copyFileSync:ze,cp:We,cpSync:Re,createBackend:Ue,createReadStream:$e,createWriteStream:je,decode:B,decodeDirListing:Le,encode:C,encodeDirListing:qe,errorMessages:Ye,exists:Ve,existsSync:Xe,fchmod:Ze,fchmodSync:Qe,fchown:Ge,fchownSync:Je,fdatasync:Ke,fdatasyncSync:et,flagToMode:tt,flagToNumber:rt,flagToString:nt,fs:it,fstat:ot,fstatSync:st,fsync:at,fsyncSync:ct,ftruncate:lt,ftruncateSync:dt,futimes:ft,futimesSync:ut,isAppendable:mt,isBackend:yt,isBackendConfig:St,isExclusive:gt,isReadable:pt,isSynchronous:ht,isTruncating:bt,isWriteable:Et,lchmod:wt,lchmodSync:Ft,lchown:xt,lchownSync:It,levenshtein:Dt,link:vt,linkSync:kt,lopenSync:Tt,lstat:At,lstatSync:Ht,lutimes:Ot,lutimesSync:Nt,mkdir:Bt,mkdirSync:Ct,mkdirpSync:Mt,mkdtemp:_t,mkdtempSync:Pt,mount:zt,mountMapping:Wt,mounts:Rt,nop:Ut,normalizeMode:$t,normalizeOptions:jt,normalizePath:Lt,normalizeTime:qt,open:Yt,openAsBlob:Vt,openSync:Xt,opendir:Zt,opendirSync:Qt,parseFlag:Gt,pathExistsAction:Jt,pathNotExistsAction:Kt,promises:er,randomIno:tr,read:rr,readFile:nr,readFileSync:ir,readSync:or,readdir:sr,readdirSync:ar,readlink:cr,readlinkSync:lr,readv:dr,readvSync:fr,realpath:ur,realpathSync:mr,rename:yr,renameSync:Sr,resolveMountConfig:gr,rm:pr,rmSync:hr,rmdir:br,rmdirSync:Er,rootCred:wr,rootIno:Fr,setImmediate:xr,size_max:Ir,stat:Dr,statSync:vr,statfs:kr,statfsSync:Tr,symlink:Ar,symlinkSync:Hr,truncate:Or,truncateSync:Nr,umount:Br,unlink:Cr,unlinkSync:Mr,unwatchFile:_r,utimes:Pr,utimesSync:zr,watch:Wr,watchFile:Rr,write:Ur,writeFile:$r,writeFileSync:jr,writeSync:Lr,writev:qr,writevSync:Yr}=ZenFS;function S(r,e){if(typeof r!="string")throw new TypeError(`"${e}" is not a string`)}c(S,"validateString");function j(r,e){let t="",n=0,i=-1,o=0,a="\0";for(let s=0;s<=r.length;++s){if(s<r.length)a=r[s];else{if(a=="/")break;a="/"}if(a=="/"){if(!(i===s-1||o===1))if(o===2){if(t.length<2||n!==2||t.at(-1)!=="."||t.at(-2)!=="."){if(t.length>2){let y=t.lastIndexOf("/");y===-1?(t="",n=0):(t=t.slice(0,y),n=t.length-1-t.lastIndexOf("/")),i=s,o=0;continue}else if(t.length!==0){t="",n=0,i=s,o=0;continue}}e&&(t+=t.length>0?"/..":"..",n=2)}else t.length>0?t+="/"+r.slice(i+1,s):t=r.slice(i+1,s),n=s-i-1;i=s,o=0}else a==="."&&o!==-1?++o:o=-1}return t}c(j,"normalizeString");function L(r){if(S(r,"path"),r.length===0)return".";let e=r[0]==="/",t=r.at(-1)==="/";return r=j(r,!e),r.length===0?e?"/":t?"./":".":(t&&(r+="/"),e?`/${r}`:r)}c(L,"normalize");function g(...r){if(r.length===0)return".";let e;for(let t=0;t<r.length;++t){let n=r[t];S(n,"path"),n.length>0&&(e===void 0?e=n:e+=`/${n}`)}return e===void 0?".":L(e)}c(g,"join");function p(r){if(S(r,"path"),r.length===0)return".";let e=r[0]==="/",t=-1,n=!0;for(let i=r.length-1;i>=1;--i)if(r[i]==="/"){if(!n){t=i;break}}else n=!1;return t===-1?e?"/":".":e&&t===1?"//":r.slice(0,t)}c(p,"dirname");function h(r,e){e!==void 0&&S(e,"ext"),S(r,"path");let t=0,n=-1,i=!0;if(e!==void 0&&e.length>0&&e.length<=r.length){if(e===r)return"";let o=e.length-1,a=-1;for(let s=r.length-1;s>=0;--s)if(r[s]==="/"){if(!i){t=s+1;break}}else a===-1&&(i=!1,a=s+1),o>=0&&(r[s]===e[o]?--o===-1&&(n=s):(o=-1,n=a));return t===n?n=a:n===-1&&(n=r.length),r.slice(t,n)}for(let o=r.length-1;o>=0;--o)if(r[o]==="/"){if(!i){t=o+1;break}}else n===-1&&(i=!1,n=o+1);return n===-1?"":r.slice(t,n)}c(h,"basename");function q(r){switch(r.name){case"IndexSizeError":case"HierarchyRequestError":case"InvalidCharacterError":case"InvalidStateError":case"SyntaxError":case"NamespaceError":case"TypeMismatchError":case"ConstraintError":case"VersionError":case"URLMismatchError":case"InvalidNodeTypeError":return"EINVAL";case"WrongDocumentError":return"EXDEV";case"NoModificationAllowedError":case"InvalidModificationError":case"InvalidAccessError":case"SecurityError":case"NotAllowedError":return"EACCES";case"NotFoundError":return"ENOENT";case"NotSupportedError":return"ENOTSUP";case"InUseAttributeError":return"EBUSY";case"NetworkError":return"ENETDOWN";case"AbortError":return"EINTR";case"QuotaExceededError":return"ENOSPC";case"TimeoutError":return"ETIMEDOUT";case"ReadOnlyError":return"EROFS";case"DataCloneError":case"EncodingError":case"NotReadableError":case"DataError":case"TransactionInactiveError":case"OperationError":case"UnknownError":default:return"EIO"}}c(q,"errnoForDOMException");function f(r,e,t){if(r instanceof l)return r;let n=r instanceof DOMException?d[q(r)]:d.EIO,i=new l(n,r.message,e,t);return i.stack=r.stack,i.cause=r.cause,i}c(f,"convertException");var b=class extends v(T){_handles=new Map;_sync;constructor({handle:e}){super(),this._handles.set("/",e),this._sync=A.create({name:"accessfs-cache"})}metadata(){return{...super.metadata(),name:"WebAccess"}}async sync(e,t,n){let i=await this.stat(e);n.mtime!==i.mtime&&await this.writeFile(e,t)}async rename(e,t){try{let n=await this.getHandle(e);if(n instanceof FileSystemDirectoryHandle){let y=await this.readdir(e);if(await this.mkdir(t),y.length==0)await this.unlink(e);else for(let D of y)await this.rename(g(e,D),g(t,D)),await this.unlink(e)}if(!(n instanceof FileSystemFileHandle))return;let i=await n.getFile(),o=await this.getHandle(p(t));if(!(o instanceof FileSystemDirectoryHandle))return;let s=await(await o.getFileHandle(h(t),{create:!0})).createWritable();await s.write(await i.arrayBuffer()),s.close(),await this.unlink(e)}catch(n){throw f(n,e,"rename")}}async writeFile(e,t){let n=await this.getHandle(p(e));if(!(n instanceof FileSystemDirectoryHandle))return;let o=await(await n.getFileHandle(h(e),{create:!0})).createWritable();await o.write(t),await o.close()}async createFile(e,t){return await this.writeFile(e,new Uint8Array),this.openFile(e,t)}async stat(e){let t=await this.getHandle(e);if(!t)throw l.With("ENOENT",e,"stat");if(t instanceof FileSystemDirectoryHandle)return new I({mode:511|x.DIRECTORY,size:4096});if(t instanceof FileSystemFileHandle){let{lastModified:n,size:i}=await t.getFile();return new I({mode:511|x.FILE,size:i,mtimeMs:n})}throw new l(d.EBADE,"Handle is not a directory or file",e,"stat")}async openFile(e,t){let n=await this.getHandle(e);if(!(n instanceof FileSystemFileHandle))throw l.With("EISDIR",e,"openFile");try{let i=await n.getFile(),o=new Uint8Array(await i.arrayBuffer()),a=new I({mode:511|x.FILE,size:i.size,mtimeMs:i.lastModified});return new H(this,e,t,a,o)}catch(i){throw f(i,e,"openFile")}}async unlink(e){let t=await this.getHandle(p(e));if(t instanceof FileSystemDirectoryHandle)try{await t.removeEntry(h(e),{recursive:!0})}catch(n){throw f(n,e,"unlink")}}async link(e){throw l.With("ENOSYS",e,"WebAccessFS.link")}async rmdir(e){return this.unlink(e)}async mkdir(e){if(await this.getHandle(e))throw l.With("EEXIST",e,"mkdir");let n=await this.getHandle(p(e));if(!(n instanceof FileSystemDirectoryHandle))throw l.With("ENOTDIR",e,"mkdir");await n.getDirectoryHandle(h(e),{create:!0})}async readdir(e){let t=await this.getHandle(e);if(!(t instanceof FileSystemDirectoryHandle))throw l.With("ENOTDIR",e,"readdir");let n=[];for await(let i of t.keys())n.push(g(e,i));return n}async getHandle(e){if(this._handles.has(e))return this._handles.get(e);let t="/";for(let n of e.split("/").slice(1)){let i=this._handles.get(t);if(!(i instanceof FileSystemDirectoryHandle))throw l.With("ENOTDIR",t,"getHandle");t=g(t,n);try{let o=await i.getDirectoryHandle(n);this._handles.set(t,o)}catch(o){let a=o;if(a.name=="TypeMismatchError")try{let s=await i.getFileHandle(n);this._handles.set(t,s)}catch(s){f(s,t,"getHandle")}if(a.name==="TypeError")throw new l(d.ENOENT,a.message,t,"getHandle");f(a,t,"getHandle")}}return this._handles.get(e)}};c(b,"WebAccessFS");var Y={name:"WebAccess",options:{handle:{type:"object",required:!0,description:"The directory handle to use for the root"}},isAvailable(){return typeof FileSystemHandle=="function"},create(r){return new b(r)}};function m(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=n=>{n.preventDefault(),t(f(r.error))}})}c(m,"wrap");var E=class{constructor(e,t){this.tx=e;this.store=t}get(e){return m(this.store.get(e.toString()))}async put(e,t,n){return await m(this.store[n?"put":"add"](t,e.toString())),!0}remove(e){return m(this.store.delete(e.toString()))}async commit(){}async abort(){try{this.tx.abort()}catch(e){throw f(e)}}};c(E,"IndexedDBTransaction");var u=class{constructor(e,t){this.db=e;this.storeName=t}static async create(e,t=globalThis.indexedDB){let n=t.open(e,1);n.onupgradeneeded=()=>{let o=n.result;o.objectStoreNames.contains(e)&&o.deleteObjectStore(e),o.createObjectStore(e)};let i=await m(n);return new u(i,e)}get name(){return M.name+":"+this.storeName}clear(){return m(this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).clear())}beginTransaction(){let e=this.db.transaction(this.storeName,"readwrite");return new E(e,e.objectStore(this.storeName))}};c(u,"IndexedDBStore");var M={name:"IndexedDB",options:{storeName:{type:"string",required:!1,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",required:!1,description:"The size of the inode cache. Defaults to 100. A size of 0 or below disables caching."},idbFactory:{type:"object",required:!1,description:"The IDBFactory to use. Defaults to globalThis.indexedDB."}},async isAvailable(r=globalThis.indexedDB){try{if(!(r instanceof IDBFactory))return!1;let e=r.open("__zenfs_test");return await m(e),r.deleteDatabase("__zenfs_test"),!0}catch{return r.deleteDatabase("__zenfs_test"),!1}},create(r){let e=u.create(r.storeName||"zenfs",r.idbFactory);return new k({...r,store:e})}};var w=class{constructor(e){this._storage=e}get name(){return _.name}clear(){this._storage.clear()}beginTransaction(){return new O(this)}get(e){let t=this._storage.getItem(e.toString());if(typeof t=="string")return C(t)}put(e,t,n){try{return!n&&this._storage.getItem(e.toString())!==null?!1:(this._storage.setItem(e.toString(),B(t)),!0)}catch{throw new l(d.ENOSPC,"Storage is full.")}}remove(e){try{this._storage.removeItem(e.toString())}catch(t){throw new l(d.EIO,"Unable to delete key "+e+": "+t)}}};c(w,"WebStorageStore");var _={name:"WebStorage",options:{storage:{type:"object",required:!1,description:"The Storage to use. Defaults to globalThis.localStorage."}},isAvailable(r=globalThis.localStorage){return r instanceof globalThis.Storage},create({storage:r=globalThis.localStorage}){return new N({store:new w(r)})}};return $(V);})();
1
+ "use strict";var ZenFS_DOM=(()=>{var w=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var c=(r,e)=>w(r,"name",{value:e,configurable:!0});var z=(r,e)=>{for(var t in e)w(r,t,{get:e[t],enumerable:!0})},R=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of M(e))!C.call(r,i)&&i!==t&&w(r,i,{get:()=>e[i],enumerable:!(n=_(e,i))||n.enumerable});return r};var U=r=>R(w({},"__esModule",{value:!0}),r);var Y={};z(Y,{IndexedDB:()=>W,IndexedDBStore:()=>u,IndexedDBTransaction:()=>b,WebAccess:()=>q,WebAccessFS:()=>h,WebStorage:()=>P,WebStorageStore:()=>E});var X=ZenFS,{ActionType:Z,Async:D,AsyncIndexFS:Q,AsyncStoreFS:v,BigIntStats:G,BigIntStatsFs:J,Dir:K,Dirent:ee,Errno:d,ErrnoError:l,Fetch:te,FetchFS:re,File:ne,FileIndex:ie,FileSystem:k,FileType:F,InMemory:T,InMemoryStore:oe,IndexDirInode:se,IndexFS:ae,IndexFileInode:ce,IndexInode:le,Inode:de,LockedFS:fe,Mutex:ue,NoSyncFile:me,Overlay:ye,OverlayFS:Se,Port:ge,PortFS:pe,PortFile:he,PortStore:be,PortStoreBackend:Ee,PortTransaction:we,PreloadFile:A,ReadStream:Fe,Readonly:xe,SimpleSyncTransaction:O,Stats:x,StatsCommon:Ie,StatsFs:De,Sync:ve,SyncIndexFS:ke,SyncStoreFS:H,UnlockedOverlayFS:Te,WriteStream:Ae,_toUnixTimestamp:Oe,access:He,accessSync:Be,appendFile:Ne,appendFileSync:We,attachFS:Pe,attachStore:_e,checkOptions:Me,chmod:Ce,chmodSync:ze,chown:Re,chownSync:Ue,close:$e,closeSync:je,configure:Le,constants:qe,copyFile:Ye,copyFileSync:Ve,cp:Xe,cpSync:Ze,createBackend:Qe,createReadStream:Ge,createWriteStream:Je,decode:B,decodeDirListing:Ke,detachFS:et,detachStore:tt,encode:N,encodeDirListing:rt,errorMessages:nt,exists:it,existsSync:ot,fchmod:st,fchmodSync:at,fchown:ct,fchownSync:lt,fdatasync:dt,fdatasyncSync:ft,flagToMode:ut,flagToNumber:mt,flagToString:yt,fs:St,fstat:gt,fstatSync:pt,fsync:ht,fsyncSync:bt,ftruncate:Et,ftruncateSync:wt,futimes:Ft,futimesSync:xt,isAppendable:It,isBackend:Dt,isBackendConfig:vt,isExclusive:kt,isReadable:Tt,isSynchronous:At,isTruncating:Ot,isWriteable:Ht,lchmod:Bt,lchmodSync:Nt,lchown:Wt,lchownSync:Pt,levenshtein:_t,link:Mt,linkSync:Ct,lopenSync:zt,lstat:Rt,lstatSync:Ut,lutimes:$t,lutimesSync:jt,mkdir:Lt,mkdirSync:qt,mkdirpSync:Yt,mkdtemp:Vt,mkdtempSync:Xt,mount:Zt,mountObject:Qt,mounts:Gt,nop:Jt,normalizeMode:Kt,normalizeOptions:er,normalizePath:tr,normalizeTime:rr,open:nr,openAsBlob:ir,openSync:or,opendir:sr,opendirSync:ar,parseFlag:cr,pathExistsAction:lr,pathNotExistsAction:dr,promises:fr,randomIno:ur,read:mr,readFile:yr,readFileSync:Sr,readSync:gr,readdir:pr,readdirSync:hr,readlink:br,readlinkSync:Er,readv:wr,readvSync:Fr,realpath:xr,realpathSync:Ir,rename:Dr,renameSync:vr,resolveMountConfig:kr,rm:Tr,rmSync:Ar,rmdir:Or,rmdirSync:Hr,rootCred:Br,rootIno:Nr,setImmediate:Wr,size_max:Pr,stat:_r,statSync:Mr,statfs:Cr,statfsSync:zr,symlink:Rr,symlinkSync:Ur,truncate:$r,truncateSync:jr,umount:Lr,unlink:qr,unlinkSync:Yr,unwatchFile:Vr,utimes:Xr,utimesSync:Zr,watch:Qr,watchFile:Gr,write:Jr,writeFile:Kr,writeFileSync:en,writeSync:tn,writev:rn,writevSync:nn}=ZenFS;function $(r,e){let t="",n=0,i=-1,o=0,a="\0";for(let s=0;s<=r.length;++s){if(s<r.length)a=r[s];else{if(a=="/")break;a="/"}if(a=="/"){if(!(i===s-1||o===1))if(o===2){if(t.length<2||n!==2||t.at(-1)!=="."||t.at(-2)!=="."){if(t.length>2){let y=t.lastIndexOf("/");y===-1?(t="",n=0):(t=t.slice(0,y),n=t.length-1-t.lastIndexOf("/")),i=s,o=0;continue}else if(t.length!==0){t="",n=0,i=s,o=0;continue}}e&&(t+=t.length>0?"/..":"..",n=2)}else t.length>0?t+="/"+r.slice(i+1,s):t=r.slice(i+1,s),n=s-i-1;i=s,o=0}else a==="."&&o!==-1?++o:o=-1}return t}c($,"normalizeString");function j(r){if(!r.length)return".";let e=r.startsWith("/"),t=r.endsWith("/");return r=$(r,!e),r.length?(t&&(r+="/"),e?`/${r}`:r):e?"/":t?"./":"."}c(j,"normalize");function S(...r){if(!r.length)return".";let e=r.join("/");return e?.length?j(e):"."}c(S,"join");function g(r){if(r.length===0)return".";let e=r[0]==="/",t=-1,n=!0;for(let i=r.length-1;i>=1;--i)if(r[i]==="/"){if(!n){t=i;break}}else n=!1;return t===-1?e?"/":".":e&&t===1?"//":r.slice(0,t)}c(g,"dirname");function p(r,e){let t=0,n=-1,i=!0;if(e!==void 0&&e.length>0&&e.length<=r.length){if(e===r)return"";let o=e.length-1,a=-1;for(let s=r.length-1;s>=0;--s)if(r[s]==="/"){if(!i){t=s+1;break}}else a===-1&&(i=!1,a=s+1),o>=0&&(r[s]===e[o]?--o===-1&&(n=s):(o=-1,n=a));return t===n?n=a:n===-1&&(n=r.length),r.slice(t,n)}for(let o=r.length-1;o>=0;--o)if(r[o]==="/"){if(!i){t=o+1;break}}else n===-1&&(i=!1,n=o+1);return n===-1?"":r.slice(t,n)}c(p,"basename");function L(r){switch(r.name){case"IndexSizeError":case"HierarchyRequestError":case"InvalidCharacterError":case"InvalidStateError":case"SyntaxError":case"NamespaceError":case"TypeMismatchError":case"ConstraintError":case"VersionError":case"URLMismatchError":case"InvalidNodeTypeError":return"EINVAL";case"WrongDocumentError":return"EXDEV";case"NoModificationAllowedError":case"InvalidModificationError":case"InvalidAccessError":case"SecurityError":case"NotAllowedError":return"EACCES";case"NotFoundError":return"ENOENT";case"NotSupportedError":return"ENOTSUP";case"InUseAttributeError":return"EBUSY";case"NetworkError":return"ENETDOWN";case"AbortError":return"EINTR";case"QuotaExceededError":return"ENOSPC";case"TimeoutError":return"ETIMEDOUT";case"ReadOnlyError":return"EROFS";case"DataCloneError":case"EncodingError":case"NotReadableError":case"DataError":case"TransactionInactiveError":case"OperationError":case"UnknownError":default:return"EIO"}}c(L,"errnoForDOMException");function f(r,e,t){if(r instanceof l)return r;let n=r instanceof DOMException?d[L(r)]:d.EIO,i=new l(n,r.message,e,t);return i.stack=r.stack,i.cause=r.cause,i}c(f,"convertException");var h=class extends D(k){_handles=new Map;_sync;constructor({handle:e}){super(),this._handles.set("/",e),this._sync=T.create({name:"accessfs-cache"})}metadata(){return{...super.metadata(),name:"WebAccess"}}async sync(e,t,n){let i=await this.stat(e);n.mtime!==i.mtime&&await this.writeFile(e,t)}async rename(e,t){try{let n=await this.getHandle(e);if(n instanceof FileSystemDirectoryHandle){let y=await this.readdir(e);if(await this.mkdir(t),y.length==0)await this.unlink(e);else for(let I of y)await this.rename(S(e,I),S(t,I)),await this.unlink(e)}if(!(n instanceof FileSystemFileHandle))return;let i=await n.getFile(),o=await this.getHandle(g(t));if(!(o instanceof FileSystemDirectoryHandle))return;let s=await(await o.getFileHandle(p(t),{create:!0})).createWritable();await s.write(await i.arrayBuffer()),s.close(),await this.unlink(e)}catch(n){throw f(n,e,"rename")}}async writeFile(e,t){let n=await this.getHandle(g(e));if(!(n instanceof FileSystemDirectoryHandle))return;let o=await(await n.getFileHandle(p(e),{create:!0})).createWritable();await o.write(t),await o.close()}async createFile(e,t){return await this.writeFile(e,new Uint8Array),this.openFile(e,t)}async stat(e){let t=await this.getHandle(e);if(!t)throw l.With("ENOENT",e,"stat");if(t instanceof FileSystemDirectoryHandle)return new x({mode:511|F.DIRECTORY,size:4096});if(t instanceof FileSystemFileHandle){let{lastModified:n,size:i}=await t.getFile();return new x({mode:511|F.FILE,size:i,mtimeMs:n})}throw new l(d.EBADE,"Handle is not a directory or file",e,"stat")}async openFile(e,t){let n=await this.getHandle(e);if(!(n instanceof FileSystemFileHandle))throw l.With("EISDIR",e,"openFile");try{let i=await n.getFile(),o=new Uint8Array(await i.arrayBuffer()),a=new x({mode:511|F.FILE,size:i.size,mtimeMs:i.lastModified});return new A(this,e,t,a,o)}catch(i){throw f(i,e,"openFile")}}async unlink(e){let t=await this.getHandle(g(e));if(t instanceof FileSystemDirectoryHandle)try{await t.removeEntry(p(e),{recursive:!0})}catch(n){throw f(n,e,"unlink")}}async link(e){throw l.With("ENOSYS",e,"WebAccessFS.link")}async rmdir(e){return this.unlink(e)}async mkdir(e){if(await this.getHandle(e))throw l.With("EEXIST",e,"mkdir");let n=await this.getHandle(g(e));if(!(n instanceof FileSystemDirectoryHandle))throw l.With("ENOTDIR",e,"mkdir");await n.getDirectoryHandle(p(e),{create:!0})}async readdir(e){let t=await this.getHandle(e);if(!(t instanceof FileSystemDirectoryHandle))throw l.With("ENOTDIR",e,"readdir");let n=[];for await(let i of t.keys())n.push(S(e,i));return n}async getHandle(e){if(this._handles.has(e))return this._handles.get(e);let t="/";for(let n of e.split("/").slice(1)){let i=this._handles.get(t);if(!(i instanceof FileSystemDirectoryHandle))throw l.With("ENOTDIR",t,"getHandle");t=S(t,n);try{let o=await i.getDirectoryHandle(n);this._handles.set(t,o)}catch(o){let a=o;if(a.name=="TypeMismatchError")try{let s=await i.getFileHandle(n);this._handles.set(t,s)}catch(s){f(s,t,"getHandle")}if(a.name==="TypeError")throw new l(d.ENOENT,a.message,t,"getHandle");f(a,t,"getHandle")}}return this._handles.get(e)}};c(h,"WebAccessFS");var q={name:"WebAccess",options:{handle:{type:"object",required:!0,description:"The directory handle to use for the root"}},isAvailable(){return typeof FileSystemHandle=="function"},create(r){return new h(r)}};function m(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=n=>{n.preventDefault(),t(f(r.error))}})}c(m,"wrap");var b=class{constructor(e,t){this.tx=e;this.store=t}get(e){return m(this.store.get(e.toString()))}async put(e,t,n){return await m(this.store[n?"put":"add"](t,e.toString())),!0}remove(e){return m(this.store.delete(e.toString()))}async commit(){}async abort(){try{this.tx.abort()}catch(e){throw f(e)}}};c(b,"IndexedDBTransaction");var u=class{constructor(e,t){this.db=e;this.storeName=t}static async create(e,t=globalThis.indexedDB){let n=t.open(e,1);n.onupgradeneeded=()=>{let o=n.result;o.objectStoreNames.contains(e)&&o.deleteObjectStore(e),o.createObjectStore(e)};let i=await m(n);return new u(i,e)}get name(){return W.name+":"+this.storeName}clear(){return m(this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).clear())}beginTransaction(){let e=this.db.transaction(this.storeName,"readwrite");return new b(e,e.objectStore(this.storeName))}};c(u,"IndexedDBStore");var W={name:"IndexedDB",options:{storeName:{type:"string",required:!1,description:"The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name."},lruCacheSize:{type:"number",required:!1,description:"The size of the inode cache. Defaults to 100. A size of 0 or below disables caching."},idbFactory:{type:"object",required:!1,description:"The IDBFactory to use. Defaults to globalThis.indexedDB."}},async isAvailable(r=globalThis.indexedDB){try{if(!(r instanceof IDBFactory))return!1;let e=r.open("__zenfs_test");return await m(e),r.deleteDatabase("__zenfs_test"),!0}catch{return r.deleteDatabase("__zenfs_test"),!1}},create(r){let e=u.create(r.storeName||"zenfs",r.idbFactory);return new v({...r,store:e})}};var E=class{constructor(e){this._storage=e}get name(){return P.name}clear(){this._storage.clear()}beginTransaction(){return new O(this)}get(e){let t=this._storage.getItem(e.toString());if(typeof t=="string")return N(t)}put(e,t,n){try{return!n&&this._storage.getItem(e.toString())!==null?!1:(this._storage.setItem(e.toString(),B(t)),!0)}catch{throw new l(d.ENOSPC,"Storage is full.")}}remove(e){try{this._storage.removeItem(e.toString())}catch(t){throw new l(d.EIO,"Unable to delete key "+e+": "+t)}}};c(E,"WebStorageStore");var P={name:"WebStorage",options:{storage:{type:"object",required:!1,description:"The Storage to use. Defaults to globalThis.localStorage."}},isAvailable(r=globalThis.localStorage){return r instanceof globalThis.Storage},create({storage:r=globalThis.localStorage}){return new H({store:new E(r)})}};return U(Y);})();
2
2
  //# sourceMappingURL=browser.min.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "global-externals:@zenfs/core", "../node_modules/@zenfs/core/dist/emulation/path.js", "../src/utils.ts", "../src/access.ts", "../src/IndexedDB.ts", "../src/Storage.ts"],
4
- "sourcesContent": ["export * from './access.js';\nexport * from './IndexedDB.js';\nexport * from './Storage.js';\n", "export default ZenFS;\nconst { ActionType, ApiError, Async, AsyncIndexFS, AsyncStoreFS, BigIntStats, BigIntStatsFs, Dir, Dirent, ErrorCode, File, FileIndex, FileSystem, FileType, InMemory, InMemoryStore, IndexDirInode, IndexFS, IndexFileInode, IndexInode, Inode, LockedFS, Mutex, NoSyncFile, Overlay, OverlayFS, PreloadFile, ReadStream, Readonly, SimpleSyncTransaction, Stats, StatsCommon, StatsFs, Sync, SyncIndexFS, SyncStoreFS, UnlockedOverlayFS, WriteStream, _toUnixTimestamp, access, accessSync, appendFile, appendFileSync, checkOptions, chmod, chmodSync, chown, chownSync, close, closeSync, configure, constants, copyFile, copyFileSync, cp, cpSync, createBackend, createReadStream, createWriteStream, decode, decodeDirListing, encode, encodeDirListing, errorMessages, exists, existsSync, fchmod, fchmodSync, fchown, fchownSync, fdatasync, fdatasyncSync, flagToMode, flagToNumber, flagToString, fs, fstat, fstatSync, fsync, fsyncSync, ftruncate, ftruncateSync, futimes, futimesSync, isAppendable, isBackend, isBackendConfig, isExclusive, isReadable, isSynchronous, isTruncating, isWriteable, lchmod, lchmodSync, lchown, lchownSync, levenshtein, link, linkSync, lopenSync, lstat, lstatSync, lutimes, lutimesSync, mkdir, mkdirSync, mkdirpSync, mkdtemp, mkdtempSync, mount, mountMapping, mounts, nop, normalizeMode, normalizeOptions, normalizePath, normalizeTime, open, openAsBlob, openSync, opendir, opendirSync, parseFlag, pathExistsAction, pathNotExistsAction, promises, randomIno, read, readFile, readFileSync, readSync, readdir, readdirSync, readlink, readlinkSync, readv, readvSync, realpath, realpathSync, rename, renameSync, resolveMountConfig, rm, rmSync, rmdir, rmdirSync, rootCred, rootIno, setImmediate, size_max, stat, statSync, statfs, statfsSync, symlink, symlinkSync, truncate, truncateSync, umount, unlink, unlinkSync, unwatchFile, utimes, utimesSync, watch, watchFile, write, writeFile, writeFileSync, writeSync, writev, writevSync } = ZenFS;\nexport { ActionType, ApiError, Async, AsyncIndexFS, AsyncStoreFS, BigIntStats, BigIntStatsFs, Dir, Dirent, ErrorCode, File, FileIndex, FileSystem, FileType, InMemory, InMemoryStore, IndexDirInode, IndexFS, IndexFileInode, IndexInode, Inode, LockedFS, Mutex, NoSyncFile, Overlay, OverlayFS, PreloadFile, ReadStream, Readonly, SimpleSyncTransaction, Stats, StatsCommon, StatsFs, Sync, SyncIndexFS, SyncStoreFS, UnlockedOverlayFS, WriteStream, _toUnixTimestamp, access, accessSync, appendFile, appendFileSync, checkOptions, chmod, chmodSync, chown, chownSync, close, closeSync, configure, constants, copyFile, copyFileSync, cp, cpSync, createBackend, createReadStream, createWriteStream, decode, decodeDirListing, encode, encodeDirListing, errorMessages, exists, existsSync, fchmod, fchmodSync, fchown, fchownSync, fdatasync, fdatasyncSync, flagToMode, flagToNumber, flagToString, fs, fstat, fstatSync, fsync, fsyncSync, ftruncate, ftruncateSync, futimes, futimesSync, isAppendable, isBackend, isBackendConfig, isExclusive, isReadable, isSynchronous, isTruncating, isWriteable, lchmod, lchmodSync, lchown, lchownSync, levenshtein, link, linkSync, lopenSync, lstat, lstatSync, lutimes, lutimesSync, mkdir, mkdirSync, mkdirpSync, mkdtemp, mkdtempSync, mount, mountMapping, mounts, nop, normalizeMode, normalizeOptions, normalizePath, normalizeTime, open, openAsBlob, openSync, opendir, opendirSync, parseFlag, pathExistsAction, pathNotExistsAction, promises, randomIno, read, readFile, readFileSync, readSync, readdir, readdirSync, readlink, readlinkSync, readv, readvSync, realpath, realpathSync, rename, renameSync, resolveMountConfig, rm, rmSync, rmdir, rmdirSync, rootCred, rootIno, setImmediate, size_max, stat, statSync, statfs, statfsSync, symlink, symlinkSync, truncate, truncateSync, umount, unlink, unlinkSync, unwatchFile, utimes, utimesSync, watch, watchFile, write, writeFile, writeFileSync, writeSync, writev, writevSync };", "/*\nCopyright Joyent, Inc. and other Node contributors.\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to permit\npersons to whom the Software is furnished to do so, subject to the\nfollowing conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\nNO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\nDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\nUSE OR OTHER DEALINGS IN THE SOFTWARE.\n*/\nexport let cwd = '/';\nexport function cd(path) {\n cwd = resolve(cwd, path);\n}\nexport const sep = '/';\nfunction validateString(str, name) {\n if (typeof str != 'string') {\n throw new TypeError(`\"${name}\" is not a string`);\n }\n}\nfunction validateObject(str, name) {\n if (typeof str != 'object') {\n throw new TypeError(`\"${name}\" is not an object`);\n }\n}\n// Resolves . and .. elements in a path with directory names\nexport function normalizeString(path, allowAboveRoot) {\n let res = '';\n let lastSegmentLength = 0;\n let lastSlash = -1;\n let dots = 0;\n let char = '\\x00';\n for (let i = 0; i <= path.length; ++i) {\n if (i < path.length) {\n char = path[i];\n }\n else if (char == '/') {\n break;\n }\n else {\n char = '/';\n }\n if (char == '/') {\n if (lastSlash === i - 1 || dots === 1) {\n // NOOP\n }\n else if (dots === 2) {\n if (res.length < 2 || lastSegmentLength !== 2 || res.at(-1) !== '.' || res.at(-2) !== '.') {\n if (res.length > 2) {\n const lastSlashIndex = res.lastIndexOf('/');\n if (lastSlashIndex === -1) {\n res = '';\n lastSegmentLength = 0;\n }\n else {\n res = res.slice(0, lastSlashIndex);\n lastSegmentLength = res.length - 1 - res.lastIndexOf('/');\n }\n lastSlash = i;\n dots = 0;\n continue;\n }\n else if (res.length !== 0) {\n res = '';\n lastSegmentLength = 0;\n lastSlash = i;\n dots = 0;\n continue;\n }\n }\n if (allowAboveRoot) {\n res += res.length > 0 ? '/..' : '..';\n lastSegmentLength = 2;\n }\n }\n else {\n if (res.length > 0)\n res += '/' + path.slice(lastSlash + 1, i);\n else\n res = path.slice(lastSlash + 1, i);\n lastSegmentLength = i - lastSlash - 1;\n }\n lastSlash = i;\n dots = 0;\n }\n else if (char === '.' && dots !== -1) {\n ++dots;\n }\n else {\n dots = -1;\n }\n }\n return res;\n}\nexport function formatExt(ext) {\n return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';\n}\nexport function resolve(...args) {\n let resolved = '';\n let absolute = false;\n for (let i = args.length - 1; i >= -1 && !absolute; i--) {\n const path = i >= 0 ? args[i] : cwd;\n validateString(path, `paths[${i}]`);\n // Skip empty entries\n if (!path.length) {\n continue;\n }\n resolved = `${path}/${resolved}`;\n absolute = path[0] == '/';\n }\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when cwd fails)\n // Normalize the path\n resolved = normalizeString(resolved, !absolute);\n if (absolute) {\n return `/${resolved}`;\n }\n return resolved.length > 0 ? resolved : '/';\n}\nexport function normalize(path) {\n validateString(path, 'path');\n if (path.length === 0)\n return '.';\n const isAbsolute = path[0] === '/';\n const trailingSeparator = path.at(-1) === '/';\n // Normalize the path\n path = normalizeString(path, !isAbsolute);\n if (path.length === 0) {\n if (isAbsolute)\n return '/';\n return trailingSeparator ? './' : '.';\n }\n if (trailingSeparator)\n path += '/';\n return isAbsolute ? `/${path}` : path;\n}\nexport function isAbsolute(path) {\n validateString(path, 'path');\n return path.length > 0 && path[0] === '/';\n}\nexport function join(...args) {\n if (args.length === 0)\n return '.';\n let joined;\n for (let i = 0; i < args.length; ++i) {\n const arg = args[i];\n validateString(arg, 'path');\n if (arg.length > 0) {\n if (joined === undefined)\n joined = arg;\n else\n joined += `/${arg}`;\n }\n }\n if (joined === undefined)\n return '.';\n return normalize(joined);\n}\nexport function relative(from, to) {\n validateString(from, 'from');\n validateString(to, 'to');\n if (from === to)\n return '';\n // Trim leading forward slashes.\n from = resolve(from);\n to = resolve(to);\n if (from === to)\n return '';\n const fromStart = 1;\n const fromEnd = from.length;\n const fromLen = fromEnd - fromStart;\n const toStart = 1;\n const toLen = to.length - toStart;\n // Compare paths to find the longest common path from root\n const length = fromLen < toLen ? fromLen : toLen;\n let lastCommonSep = -1;\n let i = 0;\n for (; i < length; i++) {\n const fromCode = from[fromStart + i];\n if (fromCode !== to[toStart + i])\n break;\n else if (fromCode === '/')\n lastCommonSep = i;\n }\n if (i === length) {\n if (toLen > length) {\n if (to[toStart + i] === '/') {\n // We get here if `from` is the exact base path for `to`.\n // For example: from='/foo/bar'; to='/foo/bar/baz'\n return to.slice(toStart + i + 1);\n }\n if (i === 0) {\n // We get here if `from` is the root\n // For example: from='/'; to='/foo'\n return to.slice(toStart + i);\n }\n }\n else if (fromLen > length) {\n if (from[fromStart + i] === '/') {\n // We get here if `to` is the exact base path for `from`.\n // For example: from='/foo/bar/baz'; to='/foo/bar'\n lastCommonSep = i;\n }\n else if (i === 0) {\n // We get here if `to` is the root.\n // For example: from='/foo/bar'; to='/'\n lastCommonSep = 0;\n }\n }\n }\n let out = '';\n // Generate the relative path based on the path difference between `to`\n // and `from`.\n for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {\n if (i === fromEnd || from[i] === '/') {\n out += out.length === 0 ? '..' : '/..';\n }\n }\n // Lastly, append the rest of the destination (`to`) path that comes after\n // the common path parts.\n return `${out}${to.slice(toStart + lastCommonSep)}`;\n}\nexport function dirname(path) {\n validateString(path, 'path');\n if (path.length === 0)\n return '.';\n const hasRoot = path[0] === '/';\n let end = -1;\n let matchedSlash = true;\n for (let i = path.length - 1; i >= 1; --i) {\n if (path[i] === '/') {\n if (!matchedSlash) {\n end = i;\n break;\n }\n }\n else {\n // We saw the first non-path separator\n matchedSlash = false;\n }\n }\n if (end === -1)\n return hasRoot ? '/' : '.';\n if (hasRoot && end === 1)\n return '//';\n return path.slice(0, end);\n}\nexport function basename(path, suffix) {\n if (suffix !== undefined)\n validateString(suffix, 'ext');\n validateString(path, 'path');\n let start = 0;\n let end = -1;\n let matchedSlash = true;\n if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {\n if (suffix === path)\n return '';\n let extIdx = suffix.length - 1;\n let firstNonSlashEnd = -1;\n for (let i = path.length - 1; i >= 0; --i) {\n if (path[i] === '/') {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n }\n else {\n if (firstNonSlashEnd === -1) {\n // We saw the first non-path separator, remember this index in case\n // we need it if the extension ends up not matching\n matchedSlash = false;\n firstNonSlashEnd = i + 1;\n }\n if (extIdx >= 0) {\n // Try to match the explicit extension\n if (path[i] === suffix[extIdx]) {\n if (--extIdx === -1) {\n // We matched the extension, so mark this as the end of our path\n // component\n end = i;\n }\n }\n else {\n // Extension does not match, so our result is the entire path\n // component\n extIdx = -1;\n end = firstNonSlashEnd;\n }\n }\n }\n }\n if (start === end)\n end = firstNonSlashEnd;\n else if (end === -1)\n end = path.length;\n return path.slice(start, end);\n }\n for (let i = path.length - 1; i >= 0; --i) {\n if (path[i] === '/') {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n }\n else if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // path component\n matchedSlash = false;\n end = i + 1;\n }\n }\n if (end === -1)\n return '';\n return path.slice(start, end);\n}\nexport function extname(path) {\n validateString(path, 'path');\n let startDot = -1;\n let startPart = 0;\n let end = -1;\n let matchedSlash = true;\n // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n let preDotState = 0;\n for (let i = path.length - 1; i >= 0; --i) {\n if (path[i] === '/') {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n continue;\n }\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n if (path[i] === '.') {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1)\n startDot = i;\n else if (preDotState !== 1)\n preDotState = 1;\n }\n else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n if (startDot === -1 ||\n end === -1 ||\n // We saw a non-dot character immediately before the dot\n preDotState === 0 ||\n // The (right-most) trimmed path component is exactly '..'\n (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {\n return '';\n }\n return path.slice(startDot, end);\n}\nexport function format(pathObject) {\n validateObject(pathObject, 'pathObject');\n const dir = pathObject.dir || pathObject.root;\n const base = pathObject.base || `${pathObject.name || ''}${formatExt(pathObject.ext)}`;\n if (!dir) {\n return base;\n }\n return dir === pathObject.root ? `${dir}${base}` : `${dir}/${base}`;\n}\nexport function parse(path) {\n validateString(path, 'path');\n const isAbsolute = path[0] === '/';\n const ret = { root: isAbsolute ? '/' : '', dir: '', base: '', ext: '', name: '' };\n if (path.length === 0)\n return ret;\n const start = isAbsolute ? 1 : 0;\n let startDot = -1;\n let startPart = 0;\n let end = -1;\n let matchedSlash = true;\n let i = path.length - 1;\n // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n let preDotState = 0;\n // Get non-dir info\n for (; i >= start; --i) {\n if (path[i] === '/') {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n continue;\n }\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n if (path[i] === '.') {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1)\n startDot = i;\n else if (preDotState !== 1)\n preDotState = 1;\n }\n else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n if (end !== -1) {\n const start = startPart === 0 && isAbsolute ? 1 : startPart;\n if (startDot === -1 ||\n // We saw a non-dot character immediately before the dot\n preDotState === 0 ||\n // The (right-most) trimmed path component is exactly '..'\n (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {\n ret.base = ret.name = path.slice(start, end);\n }\n else {\n ret.name = path.slice(start, startDot);\n ret.base = path.slice(start, end);\n ret.ext = path.slice(startDot, end);\n }\n }\n if (startPart > 0)\n ret.dir = path.slice(0, startPart - 1);\n else if (isAbsolute)\n ret.dir = '/';\n return ret;\n}\n", "import { ApiError, ErrorCode } from '@zenfs/core';\n\n/**\n * Converts a DOMException into an ErrorCode\n * @see https://developer.mozilla.org/Web/API/DOMException\n */\nfunction errnoForDOMException(ex: DOMException): keyof typeof ErrorCode {\n\tswitch (ex.name) {\n\t\tcase 'IndexSizeError':\n\t\tcase 'HierarchyRequestError':\n\t\tcase 'InvalidCharacterError':\n\t\tcase 'InvalidStateError':\n\t\tcase 'SyntaxError':\n\t\tcase 'NamespaceError':\n\t\tcase 'TypeMismatchError':\n\t\tcase 'ConstraintError':\n\t\tcase 'VersionError':\n\t\tcase 'URLMismatchError':\n\t\tcase 'InvalidNodeTypeError':\n\t\t\treturn 'EINVAL';\n\t\tcase 'WrongDocumentError':\n\t\t\treturn 'EXDEV';\n\t\tcase 'NoModificationAllowedError':\n\t\tcase 'InvalidModificationError':\n\t\tcase 'InvalidAccessError':\n\t\tcase 'SecurityError':\n\t\tcase 'NotAllowedError':\n\t\t\treturn 'EACCES';\n\t\tcase 'NotFoundError':\n\t\t\treturn 'ENOENT';\n\t\tcase 'NotSupportedError':\n\t\t\treturn 'ENOTSUP';\n\t\tcase 'InUseAttributeError':\n\t\t\treturn 'EBUSY';\n\t\tcase 'NetworkError':\n\t\t\treturn 'ENETDOWN';\n\t\tcase 'AbortError':\n\t\t\treturn 'EINTR';\n\t\tcase 'QuotaExceededError':\n\t\t\treturn 'ENOSPC';\n\t\tcase 'TimeoutError':\n\t\t\treturn 'ETIMEDOUT';\n\t\tcase 'ReadOnlyError':\n\t\t\treturn 'EROFS';\n\t\tcase 'DataCloneError':\n\t\tcase 'EncodingError':\n\t\tcase 'NotReadableError':\n\t\tcase 'DataError':\n\t\tcase 'TransactionInactiveError':\n\t\tcase 'OperationError':\n\t\tcase 'UnknownError':\n\t\tdefault:\n\t\t\treturn 'EIO';\n\t}\n}\n\n/**\n * @internal\n */\nexport type ConvertException = ApiError | DOMException | Error;\n\n/**\n * Handles converting errors, then rethrowing them\n * @internal\n */\nexport function convertException(ex: ConvertException, path?: string, syscall?: string): ApiError {\n\tif (ex instanceof ApiError) {\n\t\treturn ex;\n\t}\n\n\tconst code = ex instanceof DOMException ? ErrorCode[errnoForDOMException(ex)] : ErrorCode.EIO;\n\tconst error = new ApiError(code, ex.message, path, syscall);\n\terror.stack = ex.stack!;\n\terror.cause = ex.cause;\n\treturn error;\n}\n", "import type { Backend, FileSystemMetadata } from '@zenfs/core';\nimport { ApiError, Async, ErrorCode, FileSystem, FileType, InMemory, PreloadFile, Stats } from '@zenfs/core';\nimport { basename, dirname, join } from '@zenfs/core/emulation/path.js';\nimport { convertException, type ConvertException } from './utils.js';\n\ndeclare global {\n\tinterface FileSystemDirectoryHandle {\n\t\t[Symbol.iterator](): IterableIterator<[string, FileSystemHandle]>;\n\t\tentries(): IterableIterator<[string, FileSystemHandle]>;\n\t\tkeys(): IterableIterator<string>;\n\t\tvalues(): IterableIterator<FileSystemHandle>;\n\t}\n}\n\nexport interface WebAccessOptions {\n\thandle: FileSystemDirectoryHandle;\n}\n\nexport class WebAccessFS extends Async(FileSystem) {\n\tprivate _handles: Map<string, FileSystemHandle> = new Map();\n\n\t/**\n\t * @hidden\n\t */\n\t_sync: FileSystem;\n\n\tpublic constructor({ handle }: WebAccessOptions) {\n\t\tsuper();\n\t\tthis._handles.set('/', handle);\n\t\tthis._sync = InMemory.create({ name: 'accessfs-cache' });\n\t}\n\n\tpublic metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\t...super.metadata(),\n\t\t\tname: 'WebAccess',\n\t\t};\n\t}\n\n\tpublic async sync(p: string, data: Uint8Array, stats: Stats): Promise<void> {\n\t\tconst currentStats = await this.stat(p);\n\t\tif (stats.mtime !== currentStats!.mtime) {\n\t\t\tawait this.writeFile(p, data);\n\t\t}\n\t}\n\n\tpublic async rename(oldPath: string, newPath: string): Promise<void> {\n\t\ttry {\n\t\t\tconst handle = await this.getHandle(oldPath);\n\t\t\tif (handle instanceof FileSystemDirectoryHandle) {\n\t\t\t\tconst files = await this.readdir(oldPath);\n\n\t\t\t\tawait this.mkdir(newPath);\n\t\t\t\tif (files.length == 0) {\n\t\t\t\t\tawait this.unlink(oldPath);\n\t\t\t\t} else {\n\t\t\t\t\tfor (const file of files) {\n\t\t\t\t\t\tawait this.rename(join(oldPath, file), join(newPath, file));\n\t\t\t\t\t\tawait this.unlink(oldPath);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!(handle instanceof FileSystemFileHandle)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst oldFile = await handle.getFile(),\n\t\t\t\tdestFolder = await this.getHandle(dirname(newPath));\n\t\t\tif (!(destFolder instanceof FileSystemDirectoryHandle)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst newFile = await destFolder.getFileHandle(basename(newPath), { create: true });\n\t\t\tconst writable = await newFile.createWritable();\n\t\t\tawait writable.write(await oldFile.arrayBuffer());\n\n\t\t\twritable.close();\n\t\t\tawait this.unlink(oldPath);\n\t\t} catch (ex) {\n\t\t\tthrow convertException(ex as ConvertException, oldPath, 'rename');\n\t\t}\n\t}\n\n\tpublic async writeFile(fname: string, data: Uint8Array): Promise<void> {\n\t\tconst handle = await this.getHandle(dirname(fname));\n\t\tif (!(handle instanceof FileSystemDirectoryHandle)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst file = await handle.getFileHandle(basename(fname), { create: true });\n\t\tconst writable = await file.createWritable();\n\t\tawait writable.write(data);\n\t\tawait writable.close();\n\t}\n\n\tpublic async createFile(path: string, flag: string): Promise<PreloadFile<this>> {\n\t\tawait this.writeFile(path, new Uint8Array());\n\t\treturn this.openFile(path, flag);\n\t}\n\n\tpublic async stat(path: string): Promise<Stats> {\n\t\tconst handle = await this.getHandle(path);\n\t\tif (!handle) {\n\t\t\tthrow ApiError.With('ENOENT', path, 'stat');\n\t\t}\n\t\tif (handle instanceof FileSystemDirectoryHandle) {\n\t\t\treturn new Stats({ mode: 0o777 | FileType.DIRECTORY, size: 4096 });\n\t\t}\n\t\tif (handle instanceof FileSystemFileHandle) {\n\t\t\tconst { lastModified, size } = await handle.getFile();\n\t\t\treturn new Stats({ mode: 0o777 | FileType.FILE, size, mtimeMs: lastModified });\n\t\t}\n\t\tthrow new ApiError(ErrorCode.EBADE, 'Handle is not a directory or file', path, 'stat');\n\t}\n\n\tpublic async openFile(path: string, flag: string): Promise<PreloadFile<this>> {\n\t\tconst handle = await this.getHandle(path);\n\t\tif (!(handle instanceof FileSystemFileHandle)) {\n\t\t\tthrow ApiError.With('EISDIR', path, 'openFile');\n\t\t}\n\t\ttry {\n\t\t\tconst file = await handle.getFile();\n\t\t\tconst data = new Uint8Array(await file.arrayBuffer());\n\t\t\tconst stats = new Stats({ mode: 0o777 | FileType.FILE, size: file.size, mtimeMs: file.lastModified });\n\t\t\treturn new PreloadFile(this, path, flag, stats, data);\n\t\t} catch (ex) {\n\t\t\tthrow convertException(ex as ConvertException, path, 'openFile');\n\t\t}\n\t}\n\n\tpublic async unlink(path: string): Promise<void> {\n\t\tconst handle = await this.getHandle(dirname(path));\n\t\tif (handle instanceof FileSystemDirectoryHandle) {\n\t\t\ttry {\n\t\t\t\tawait handle.removeEntry(basename(path), { recursive: true });\n\t\t\t} catch (ex) {\n\t\t\t\tthrow convertException(ex as ConvertException, path, 'unlink');\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async link(srcpath: string): Promise<void> {\n\t\tthrow ApiError.With('ENOSYS', srcpath, 'WebAccessFS.link');\n\t}\n\n\tpublic async rmdir(path: string): Promise<void> {\n\t\treturn this.unlink(path);\n\t}\n\n\tpublic async mkdir(path: string): Promise<void> {\n\t\tconst existingHandle = await this.getHandle(path);\n\t\tif (existingHandle) {\n\t\t\tthrow ApiError.With('EEXIST', path, 'mkdir');\n\t\t}\n\n\t\tconst handle = await this.getHandle(dirname(path));\n\t\tif (!(handle instanceof FileSystemDirectoryHandle)) {\n\t\t\tthrow ApiError.With('ENOTDIR', path, 'mkdir');\n\t\t}\n\t\tawait handle.getDirectoryHandle(basename(path), { create: true });\n\t}\n\n\tpublic async readdir(path: string): Promise<string[]> {\n\t\tconst handle = await this.getHandle(path);\n\t\tif (!(handle instanceof FileSystemDirectoryHandle)) {\n\t\t\tthrow ApiError.With('ENOTDIR', path, 'readdir');\n\t\t}\n\t\tconst _keys: string[] = [];\n\t\tfor await (const key of handle.keys()) {\n\t\t\t_keys.push(join(path, key));\n\t\t}\n\t\treturn _keys;\n\t}\n\n\tprotected async getHandle(path: string): Promise<FileSystemHandle> {\n\t\tif (this._handles.has(path)) {\n\t\t\treturn this._handles.get(path)!;\n\t\t}\n\n\t\tlet walked = '/';\n\n\t\tfor (const part of path.split('/').slice(1)) {\n\t\t\tconst handle = this._handles.get(walked);\n\t\t\tif (!(handle instanceof FileSystemDirectoryHandle)) {\n\t\t\t\tthrow ApiError.With('ENOTDIR', walked, 'getHandle');\n\t\t\t}\n\t\t\twalked = join(walked, part);\n\n\t\t\ttry {\n\t\t\t\tconst dirHandle = await handle.getDirectoryHandle(part);\n\t\t\t\tthis._handles.set(walked, dirHandle);\n\t\t\t} catch (_ex) {\n\t\t\t\tconst ex = _ex as DOMException;\n\t\t\t\tif (ex.name == 'TypeMismatchError') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst fileHandle = await handle.getFileHandle(part);\n\t\t\t\t\t\tthis._handles.set(walked, fileHandle);\n\t\t\t\t\t} catch (ex) {\n\t\t\t\t\t\tconvertException(ex as ConvertException, walked, 'getHandle');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (ex.name === 'TypeError') {\n\t\t\t\t\tthrow new ApiError(ErrorCode.ENOENT, ex.message, walked, 'getHandle');\n\t\t\t\t}\n\n\t\t\t\tconvertException(ex, walked, 'getHandle');\n\t\t\t}\n\t\t}\n\n\t\treturn this._handles.get(path)!;\n\t}\n}\n\nexport const WebAccess = {\n\tname: 'WebAccess',\n\n\toptions: {\n\t\thandle: {\n\t\t\ttype: 'object',\n\t\t\trequired: true,\n\t\t\tdescription: 'The directory handle to use for the root',\n\t\t},\n\t},\n\n\tisAvailable(): boolean {\n\t\treturn typeof FileSystemHandle == 'function';\n\t},\n\n\tcreate(options: WebAccessOptions) {\n\t\treturn new WebAccessFS(options);\n\t},\n} as const satisfies Backend;\n", "import type { AsyncStore, AsyncStoreOptions, AsyncTransaction, Backend, Ino } from '@zenfs/core';\nimport { AsyncStoreFS } from '@zenfs/core';\nimport { convertException, type ConvertException } from './utils.js';\n\nfunction wrap<T>(request: IDBRequest<T>): Promise<T> {\n\treturn new Promise((resolve, reject) => {\n\t\trequest.onsuccess = () => resolve(request.result);\n\t\trequest.onerror = e => {\n\t\t\te.preventDefault();\n\t\t\treject(convertException(request.error!));\n\t\t};\n\t});\n}\n\n/**\n * @hidden\n */\nexport class IndexedDBTransaction implements AsyncTransaction {\n\tconstructor(\n\t\tpublic tx: IDBTransaction,\n\t\tpublic store: IDBObjectStore\n\t) {}\n\n\tpublic get(key: Ino): Promise<Uint8Array> {\n\t\treturn wrap<Uint8Array>(this.store.get(key.toString()));\n\t}\n\n\t/**\n\t * @todo return false when add has a key conflict (no error)\n\t */\n\tpublic async put(key: Ino, data: Uint8Array, overwrite: boolean): Promise<boolean> {\n\t\tawait wrap(this.store[overwrite ? 'put' : 'add'](data, key.toString()));\n\t\treturn true;\n\t}\n\n\tpublic remove(key: Ino): Promise<void> {\n\t\treturn wrap(this.store.delete(key.toString()));\n\t}\n\n\tpublic async commit(): Promise<void> {\n\t\treturn;\n\t}\n\n\tpublic async abort(): Promise<void> {\n\t\ttry {\n\t\t\tthis.tx.abort();\n\t\t} catch (e) {\n\t\t\tthrow convertException(e as ConvertException);\n\t\t}\n\t}\n}\n\nexport class IndexedDBStore implements AsyncStore {\n\tpublic static async create(storeName: string, indexedDB: IDBFactory = globalThis.indexedDB): Promise<IndexedDBStore> {\n\t\tconst req: IDBOpenDBRequest = indexedDB.open(storeName, 1);\n\n\t\treq.onupgradeneeded = () => {\n\t\t\tconst db: IDBDatabase = req.result;\n\t\t\t// This should never happen; we're at version 1. Why does another database exist?\n\t\t\tif (db.objectStoreNames.contains(storeName)) {\n\t\t\t\tdb.deleteObjectStore(storeName);\n\t\t\t}\n\t\t\tdb.createObjectStore(storeName);\n\t\t};\n\n\t\tconst result = await wrap(req);\n\t\treturn new IndexedDBStore(result, storeName);\n\t}\n\n\tconstructor(\n\t\tprotected db: IDBDatabase,\n\t\tprotected storeName: string\n\t) {}\n\n\tpublic get name(): string {\n\t\treturn IndexedDB.name + ':' + this.storeName;\n\t}\n\n\tpublic clear(): Promise<void> {\n\t\treturn wrap(this.db.transaction(this.storeName, 'readwrite').objectStore(this.storeName).clear());\n\t}\n\n\tpublic beginTransaction(): IndexedDBTransaction {\n\t\tconst tx = this.db.transaction(this.storeName, 'readwrite');\n\t\treturn new IndexedDBTransaction(tx, tx.objectStore(this.storeName));\n\t}\n}\n\n/**\n * Configuration options for the IndexedDB file system.\n */\nexport interface IndexedDBOptions extends Omit<AsyncStoreOptions, 'store'> {\n\t/**\n\t * The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name.\n\t */\n\tstoreName?: string;\n\n\t/**\n\t * The IDBFactory to use. Defaults to `globalThis.indexedDB`.\n\t */\n\tidbFactory?: IDBFactory;\n}\n\n/**\n * A file system that uses the IndexedDB key value file system.\n */\n\nexport const IndexedDB = {\n\tname: 'IndexedDB',\n\n\toptions: {\n\t\tstoreName: {\n\t\t\ttype: 'string',\n\t\t\trequired: false,\n\t\t\tdescription: 'The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name.',\n\t\t},\n\t\tcacheSize: {\n\t\t\ttype: 'number',\n\t\t\trequired: false,\n\t\t\tdescription: 'The size of the inode cache. Defaults to 100. A size of 0 or below disables caching.',\n\t\t},\n\t\tidbFactory: {\n\t\t\ttype: 'object',\n\t\t\trequired: false,\n\t\t\tdescription: 'The IDBFactory to use. Defaults to globalThis.indexedDB.',\n\t\t},\n\t},\n\n\tasync isAvailable(idbFactory: IDBFactory = globalThis.indexedDB): Promise<boolean> {\n\t\ttry {\n\t\t\tif (!(idbFactory instanceof IDBFactory)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst req = idbFactory.open('__zenfs_test');\n\t\t\tawait wrap(req);\n\t\t\tidbFactory.deleteDatabase('__zenfs_test');\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\tidbFactory.deleteDatabase('__zenfs_test');\n\t\t\treturn false;\n\t\t}\n\t},\n\n\tcreate(options: IndexedDBOptions) {\n\t\tconst store = IndexedDBStore.create(options.storeName || 'zenfs', options.idbFactory);\n\t\tconst fs = new AsyncStoreFS({ ...options, store });\n\t\treturn fs;\n\t},\n} as const satisfies Backend;\n", "import type { Backend, Ino, SimpleSyncStore, SyncStore } from '@zenfs/core';\nimport { ApiError, ErrorCode, SimpleSyncTransaction, SyncStoreFS, decode, encode } from '@zenfs/core';\n\n/**\n * A synchronous key-value store backed by Storage.\n */\nexport class WebStorageStore implements SyncStore, SimpleSyncStore {\n\tpublic get name(): string {\n\t\treturn WebStorage.name;\n\t}\n\n\tconstructor(protected _storage: Storage) {}\n\n\tpublic clear(): void {\n\t\tthis._storage.clear();\n\t}\n\n\tpublic beginTransaction(): SimpleSyncTransaction {\n\t\t// No need to differentiate.\n\t\treturn new SimpleSyncTransaction(this);\n\t}\n\n\tpublic get(key: Ino): Uint8Array | undefined {\n\t\tconst data = this._storage.getItem(key.toString());\n\t\tif (typeof data != 'string') {\n\t\t\treturn;\n\t\t}\n\n\t\treturn encode(data);\n\t}\n\n\tpublic put(key: Ino, data: Uint8Array, overwrite: boolean): boolean {\n\t\ttry {\n\t\t\tif (!overwrite && this._storage.getItem(key.toString()) !== null) {\n\t\t\t\t// Don't want to overwrite the key!\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis._storage.setItem(key.toString(), decode(data));\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\tthrow new ApiError(ErrorCode.ENOSPC, 'Storage is full.');\n\t\t}\n\t}\n\n\tpublic remove(key: Ino): void {\n\t\ttry {\n\t\t\tthis._storage.removeItem(key.toString());\n\t\t} catch (e) {\n\t\t\tthrow new ApiError(ErrorCode.EIO, 'Unable to delete key ' + key + ': ' + e);\n\t\t}\n\t}\n}\n\n/**\n * Options to pass to the StorageFileSystem\n */\nexport interface WebStorageOptions {\n\t/**\n\t * The Storage to use. Defaults to globalThis.localStorage.\n\t */\n\tstorage?: Storage;\n}\n\n/**\n * A synchronous file system backed by a `Storage` (e.g. localStorage).\n */\nexport const WebStorage = {\n\tname: 'WebStorage',\n\n\toptions: {\n\t\tstorage: {\n\t\t\ttype: 'object',\n\t\t\trequired: false,\n\t\t\tdescription: 'The Storage to use. Defaults to globalThis.localStorage.',\n\t\t},\n\t},\n\n\tisAvailable(storage: Storage = globalThis.localStorage): boolean {\n\t\treturn storage instanceof globalThis.Storage;\n\t},\n\n\tcreate({ storage = globalThis.localStorage }: WebStorageOptions) {\n\t\treturn new SyncStoreFS({ store: new WebStorageStore(storage) });\n\t},\n} as const satisfies Backend;\n"],
5
- "mappings": "gfAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,mBAAAC,EAAA,yBAAAC,EAAA,cAAAC,EAAA,gBAAAC,EAAA,eAAAC,EAAA,oBAAAC,ICAA,IAAOC,EAAQ,MACT,CAAE,WAAAC,EAAY,SAAAC,EAAU,MAAAC,EAAO,aAAAC,EAAc,aAAAC,EAAc,YAAAC,EAAa,cAAAC,EAAe,IAAAC,GAAK,OAAAC,GAAQ,UAAAC,EAAW,KAAAC,GAAM,UAAAC,GAAW,WAAAC,EAAY,SAAAC,EAAU,SAAAC,EAAU,cAAAC,GAAe,cAAAC,GAAe,QAAAC,GAAS,eAAAC,GAAgB,WAAAC,GAAY,MAAAC,GAAO,SAAAC,GAAU,MAAAC,GAAO,WAAAC,GAAY,QAAAC,GAAS,UAAAC,GAAW,YAAAC,EAAa,WAAAC,GAAY,SAAAC,GAAU,sBAAAC,EAAuB,MAAAC,EAAO,YAAAC,GAAa,QAAAC,GAAS,KAAAC,GAAM,YAAAC,GAAa,YAAAC,EAAa,kBAAAC,GAAmB,YAAAC,GAAa,iBAAAC,GAAkB,OAAAC,GAAQ,WAAAC,GAAY,WAAAC,GAAY,eAAAC,GAAgB,aAAAC,GAAc,MAAAC,GAAO,UAAAC,GAAW,MAAAC,GAAO,UAAAC,GAAW,MAAAC,GAAO,UAAAC,GAAW,UAAAC,GAAW,UAAAC,GAAW,SAAAC,GAAU,aAAAC,GAAc,GAAAC,GAAI,OAAAC,GAAQ,cAAAC,GAAe,iBAAAC,GAAkB,kBA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ACD,EA7CaC,EAAAZ,EAAA,mBA4DN,IAAME,EAAa,CACzB,KAAM,aAEN,QAAS,CACR,QAAS,CACR,KAAM,SACN,SAAU,GACV,YAAa,0DACd,CACD,EAEA,YAAYW,EAAmB,WAAW,aAAuB,CAChE,OAAOA,aAAmB,WAAW,OACtC,EAEA,OAAO,CAAE,QAAAA,EAAU,WAAW,YAAa,EAAsB,CAChE,OAAO,IAAIC,EAAY,CAAE,MAAO,IAAId,EAAgBa,CAAO,CAAE,CAAC,CAC/D,CACD",
6
- "names": ["src_exports", "__export", "IndexedDB", "IndexedDBStore", "IndexedDBTransaction", "WebAccess", "WebAccessFS", "WebStorage", "WebStorageStore", "core_default", "ActionType", "ApiError", "Async", "AsyncIndexFS", "AsyncStoreFS", "BigIntStats", "BigIntStatsFs", "Dir", "Dirent", "ErrorCode", "File", "FileIndex", "FileSystem", "FileType", "InMemory", "InMemoryStore", "IndexDirInode", "IndexFS", "IndexFileInode", "IndexInode", "Inode", "LockedFS", "Mutex", "NoSyncFile", "Overlay", "OverlayFS", "PreloadFile", "ReadStream", "Readonly", "SimpleSyncTransaction", "Stats", "StatsCommon", "StatsFs", "Sync", "SyncIndexFS", "SyncStoreFS", "UnlockedOverlayFS", "WriteStream", "_toUnixTimestamp", "access", "accessSync", "appendFile", "appendFileSync", "checkOptions", "chmod", "chmodSync", "chown", "chownSync", "close", "closeSync", "configure", "constants", "copyFile", "copyFileSync", "cp", "cpSync", "createBackend", "createReadStream", "createWriteStream", "decode", "decodeDirListing", "encode", "encodeDirListing", "errorMessages", "exists", "existsSync", "fchmod", "fchmodSync", "fchown", "fchownSync", "fdatasync", "fdatasyncSync", "flagToMode", "flagToNumber", "flagToString", "fs", "fstat", "fstatSync", "fsync", "fsyncSync", "ftruncate", "ftruncateSync", "futimes", "futimesSync", "isAppendable", "isBackend", "isBackendConfig", "isExclusive", "isReadable", "isSynchronous", "isTruncating", "isWriteable", "lchmod", "lchmodSync", "lchown", "lchownSync", "levenshtein", "link", "linkSync", "lopenSync", "lstat", "lstatSync", "lutimes", "lutimesSync", "mkdir", "mkdirSync", "mkdirpSync", "mkdtemp", "mkdtempSync", "mount", "mountMapping", "mounts", "nop", "normalizeMode", "normalizeOptions", "normalizePath", "normalizeTime", "open", "openAsBlob", "openSync", "opendir", "opendirSync", "parseFlag", "pathExistsAction", "pathNotExistsAction", "promises", "randomIno", "read", "readFile", "readFileSync", "readSync", "readdir", "readdirSync", "readlink", "readlinkSync", "readv", "readvSync", "realpath", "realpathSync", "rename", "renameSync", "resolveMountConfig", "rm", "rmSync", "rmdir", "rmdirSync", "rootCred", "rootIno", "setImmediate", "size_max", "stat", "statSync", "statfs", "statfsSync", "symlink", "symlinkSync", "truncate", "truncateSync", "umount", "unlink", "unlinkSync", "unwatchFile", "utimes", "utimesSync", "watch", "watchFile", "write", "writeFile", "writeFileSync", "writeSync", "writev", "writevSync", "validateString", "str", "name", "__name", "normalizeString", "path", "allowAboveRoot", "res", "lastSegmentLength", "lastSlash", "dots", "char", "i", "lastSlashIndex", "__name", "normalize", "path", "validateString", "isAbsolute", "trailingSeparator", "normalizeString", "__name", "join", "args", "joined", "i", "arg", "validateString", "normalize", "__name", "dirname", "path", "validateString", "hasRoot", "end", "matchedSlash", "__name", "basename", "suffix", "start", "extIdx", "firstNonSlashEnd", "i", "errnoForDOMException", "ex", "__name", "convertException", "path", "syscall", "ApiError", "code", "ErrorCode", "error", "WebAccessFS", "Async", "FileSystem", "handle", "InMemory", "p", "data", "stats", "currentStats", "oldPath", "newPath", "files", "file", "join", "oldFile", "destFolder", "dirname", "writable", "basename", "ex", "convertException", "fname", "path", "flag", "ApiError", "Stats", "FileType", "lastModified", "size", "ErrorCode", "PreloadFile", "srcpath", "_keys", "key", "walked", "part", "dirHandle", "_ex", "fileHandle", "__name", "WebAccess", "options", "wrap", "request", "resolve", "reject", "e", "convertException", "__name", "IndexedDBTransaction", "tx", "store", "key", "data", "overwrite", "IndexedDBStore", "db", "storeName", "indexedDB", "req", "result", "IndexedDB", "idbFactory", "options", "AsyncStoreFS", "WebStorageStore", "_storage", "WebStorage", "SimpleSyncTransaction", "key", "data", "encode", "overwrite", "decode", "ApiError", "ErrorCode", "e", "__name", "storage", "SyncStoreFS"]
4
+ "sourcesContent": ["export * from './access.js';\nexport * from './IndexedDB.js';\nexport * from './Storage.js';\n", "export default ZenFS;\nconst { ActionType, Async, AsyncIndexFS, AsyncStoreFS, BigIntStats, BigIntStatsFs, Dir, Dirent, Errno, ErrnoError, Fetch, FetchFS, File, FileIndex, FileSystem, FileType, InMemory, InMemoryStore, IndexDirInode, IndexFS, IndexFileInode, IndexInode, Inode, LockedFS, Mutex, NoSyncFile, Overlay, OverlayFS, Port, PortFS, PortFile, PortStore, PortStoreBackend, PortTransaction, PreloadFile, ReadStream, Readonly, SimpleSyncTransaction, Stats, StatsCommon, StatsFs, Sync, SyncIndexFS, SyncStoreFS, UnlockedOverlayFS, WriteStream, _toUnixTimestamp, access, accessSync, appendFile, appendFileSync, attachFS, attachStore, checkOptions, chmod, chmodSync, chown, chownSync, close, closeSync, configure, constants, copyFile, copyFileSync, cp, cpSync, createBackend, createReadStream, createWriteStream, decode, decodeDirListing, detachFS, detachStore, encode, encodeDirListing, errorMessages, exists, existsSync, fchmod, fchmodSync, fchown, fchownSync, fdatasync, fdatasyncSync, flagToMode, flagToNumber, flagToString, fs, fstat, fstatSync, fsync, fsyncSync, ftruncate, ftruncateSync, futimes, futimesSync, isAppendable, isBackend, isBackendConfig, isExclusive, isReadable, isSynchronous, isTruncating, isWriteable, lchmod, lchmodSync, lchown, lchownSync, levenshtein, link, linkSync, lopenSync, lstat, lstatSync, lutimes, lutimesSync, mkdir, mkdirSync, mkdirpSync, mkdtemp, mkdtempSync, mount, mountObject, mounts, nop, normalizeMode, normalizeOptions, normalizePath, normalizeTime, open, openAsBlob, openSync, opendir, opendirSync, parseFlag, pathExistsAction, pathNotExistsAction, promises, randomIno, read, readFile, readFileSync, readSync, readdir, readdirSync, readlink, readlinkSync, readv, readvSync, realpath, realpathSync, rename, renameSync, resolveMountConfig, rm, rmSync, rmdir, rmdirSync, rootCred, rootIno, setImmediate, size_max, stat, statSync, statfs, statfsSync, symlink, symlinkSync, truncate, truncateSync, umount, unlink, unlinkSync, unwatchFile, utimes, utimesSync, watch, watchFile, write, writeFile, writeFileSync, writeSync, writev, writevSync } = ZenFS;\nexport { ActionType, Async, AsyncIndexFS, AsyncStoreFS, BigIntStats, BigIntStatsFs, Dir, Dirent, Errno, ErrnoError, Fetch, FetchFS, File, FileIndex, FileSystem, FileType, InMemory, InMemoryStore, IndexDirInode, IndexFS, IndexFileInode, IndexInode, Inode, LockedFS, Mutex, NoSyncFile, Overlay, OverlayFS, Port, PortFS, PortFile, PortStore, PortStoreBackend, PortTransaction, PreloadFile, ReadStream, Readonly, SimpleSyncTransaction, Stats, StatsCommon, StatsFs, Sync, SyncIndexFS, SyncStoreFS, UnlockedOverlayFS, WriteStream, _toUnixTimestamp, access, accessSync, appendFile, appendFileSync, attachFS, attachStore, checkOptions, chmod, chmodSync, chown, chownSync, close, closeSync, configure, constants, copyFile, copyFileSync, cp, cpSync, createBackend, createReadStream, createWriteStream, decode, decodeDirListing, detachFS, detachStore, encode, encodeDirListing, errorMessages, exists, existsSync, fchmod, fchmodSync, fchown, fchownSync, fdatasync, fdatasyncSync, flagToMode, flagToNumber, flagToString, fs, fstat, fstatSync, fsync, fsyncSync, ftruncate, ftruncateSync, futimes, futimesSync, isAppendable, isBackend, isBackendConfig, isExclusive, isReadable, isSynchronous, isTruncating, isWriteable, lchmod, lchmodSync, lchown, lchownSync, levenshtein, link, linkSync, lopenSync, lstat, lstatSync, lutimes, lutimesSync, mkdir, mkdirSync, mkdirpSync, mkdtemp, mkdtempSync, mount, mountObject, mounts, nop, normalizeMode, normalizeOptions, normalizePath, normalizeTime, open, openAsBlob, openSync, opendir, opendirSync, parseFlag, pathExistsAction, pathNotExistsAction, promises, randomIno, read, readFile, readFileSync, readSync, readdir, readdirSync, readlink, readlinkSync, readv, readvSync, realpath, realpathSync, rename, renameSync, resolveMountConfig, rm, rmSync, rmdir, rmdirSync, rootCred, rootIno, setImmediate, size_max, stat, statSync, statfs, statfsSync, symlink, symlinkSync, truncate, truncateSync, umount, unlink, unlinkSync, unwatchFile, utimes, utimesSync, watch, watchFile, write, writeFile, writeFileSync, writeSync, writev, writevSync };", "/*\nCopyright Joyent, Inc. and other Node contributors.\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to permit\npersons to whom the Software is furnished to do so, subject to the\nfollowing conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\nNO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\nDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\nUSE OR OTHER DEALINGS IN THE SOFTWARE.\n*/\nexport let cwd = '/';\nexport function cd(path) {\n cwd = resolve(cwd, path);\n}\nexport const sep = '/';\nfunction validateObject(str, name) {\n if (typeof str != 'object') {\n throw new TypeError(`\"${name}\" is not an object`);\n }\n}\n// Resolves . and .. elements in a path with directory names\nexport function normalizeString(path, allowAboveRoot) {\n let res = '';\n let lastSegmentLength = 0;\n let lastSlash = -1;\n let dots = 0;\n let char = '\\x00';\n for (let i = 0; i <= path.length; ++i) {\n if (i < path.length) {\n char = path[i];\n }\n else if (char == '/') {\n break;\n }\n else {\n char = '/';\n }\n if (char == '/') {\n if (lastSlash === i - 1 || dots === 1) {\n // NOOP\n }\n else if (dots === 2) {\n if (res.length < 2 || lastSegmentLength !== 2 || res.at(-1) !== '.' || res.at(-2) !== '.') {\n if (res.length > 2) {\n const lastSlashIndex = res.lastIndexOf('/');\n if (lastSlashIndex === -1) {\n res = '';\n lastSegmentLength = 0;\n }\n else {\n res = res.slice(0, lastSlashIndex);\n lastSegmentLength = res.length - 1 - res.lastIndexOf('/');\n }\n lastSlash = i;\n dots = 0;\n continue;\n }\n else if (res.length !== 0) {\n res = '';\n lastSegmentLength = 0;\n lastSlash = i;\n dots = 0;\n continue;\n }\n }\n if (allowAboveRoot) {\n res += res.length > 0 ? '/..' : '..';\n lastSegmentLength = 2;\n }\n }\n else {\n if (res.length > 0)\n res += '/' + path.slice(lastSlash + 1, i);\n else\n res = path.slice(lastSlash + 1, i);\n lastSegmentLength = i - lastSlash - 1;\n }\n lastSlash = i;\n dots = 0;\n }\n else if (char === '.' && dots !== -1) {\n ++dots;\n }\n else {\n dots = -1;\n }\n }\n return res;\n}\nexport function formatExt(ext) {\n return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';\n}\nexport function resolve(...parts) {\n let resolved = '';\n for (const part of [...parts.reverse(), cwd]) {\n if (!part.length) {\n continue;\n }\n resolved = `${part}/${resolved}`;\n if (part.startsWith('/')) {\n break;\n }\n }\n const absolute = resolved.startsWith('/');\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when cwd fails)\n // Normalize the path\n resolved = normalizeString(resolved, !absolute);\n if (absolute) {\n return `/${resolved}`;\n }\n return resolved.length ? resolved : '/';\n}\nexport function normalize(path) {\n if (!path.length)\n return '.';\n const isAbsolute = path.startsWith('/');\n const trailingSeparator = path.endsWith('/');\n // Normalize the path\n path = normalizeString(path, !isAbsolute);\n if (!path.length) {\n if (isAbsolute)\n return '/';\n return trailingSeparator ? './' : '.';\n }\n if (trailingSeparator)\n path += '/';\n return isAbsolute ? `/${path}` : path;\n}\nexport function isAbsolute(path) {\n return path.startsWith('/');\n}\nexport function join(...parts) {\n if (!parts.length)\n return '.';\n const joined = parts.join('/');\n if (!joined?.length)\n return '.';\n return normalize(joined);\n}\nexport function relative(from, to) {\n if (from === to)\n return '';\n // Trim leading forward slashes.\n from = resolve(from);\n to = resolve(to);\n if (from === to)\n return '';\n const fromStart = 1;\n const fromEnd = from.length;\n const fromLen = fromEnd - fromStart;\n const toStart = 1;\n const toLen = to.length - toStart;\n // Compare paths to find the longest common path from root\n const length = fromLen < toLen ? fromLen : toLen;\n let lastCommonSep = -1;\n let i = 0;\n for (; i < length; i++) {\n const fromCode = from[fromStart + i];\n if (fromCode !== to[toStart + i])\n break;\n else if (fromCode === '/')\n lastCommonSep = i;\n }\n if (i === length) {\n if (toLen > length) {\n if (to[toStart + i] === '/') {\n // We get here if `from` is the exact base path for `to`.\n // For example: from='/foo/bar'; to='/foo/bar/baz'\n return to.slice(toStart + i + 1);\n }\n if (i === 0) {\n // We get here if `from` is the root\n // For example: from='/'; to='/foo'\n return to.slice(toStart + i);\n }\n }\n else if (fromLen > length) {\n if (from[fromStart + i] === '/') {\n // We get here if `to` is the exact base path for `from`.\n // For example: from='/foo/bar/baz'; to='/foo/bar'\n lastCommonSep = i;\n }\n else if (i === 0) {\n // We get here if `to` is the root.\n // For example: from='/foo/bar'; to='/'\n lastCommonSep = 0;\n }\n }\n }\n let out = '';\n // Generate the relative path based on the path difference between `to`\n // and `from`.\n for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {\n if (i === fromEnd || from[i] === '/') {\n out += out.length === 0 ? '..' : '/..';\n }\n }\n // Lastly, append the rest of the destination (`to`) path that comes after\n // the common path parts.\n return `${out}${to.slice(toStart + lastCommonSep)}`;\n}\nexport function dirname(path) {\n if (path.length === 0)\n return '.';\n const hasRoot = path[0] === '/';\n let end = -1;\n let matchedSlash = true;\n for (let i = path.length - 1; i >= 1; --i) {\n if (path[i] === '/') {\n if (!matchedSlash) {\n end = i;\n break;\n }\n }\n else {\n // We saw the first non-path separator\n matchedSlash = false;\n }\n }\n if (end === -1)\n return hasRoot ? '/' : '.';\n if (hasRoot && end === 1)\n return '//';\n return path.slice(0, end);\n}\nexport function basename(path, suffix) {\n let start = 0;\n let end = -1;\n let matchedSlash = true;\n if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {\n if (suffix === path)\n return '';\n let extIdx = suffix.length - 1;\n let firstNonSlashEnd = -1;\n for (let i = path.length - 1; i >= 0; --i) {\n if (path[i] === '/') {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n }\n else {\n if (firstNonSlashEnd === -1) {\n // We saw the first non-path separator, remember this index in case\n // we need it if the extension ends up not matching\n matchedSlash = false;\n firstNonSlashEnd = i + 1;\n }\n if (extIdx >= 0) {\n // Try to match the explicit extension\n if (path[i] === suffix[extIdx]) {\n if (--extIdx === -1) {\n // We matched the extension, so mark this as the end of our path\n // component\n end = i;\n }\n }\n else {\n // Extension does not match, so our result is the entire path\n // component\n extIdx = -1;\n end = firstNonSlashEnd;\n }\n }\n }\n }\n if (start === end)\n end = firstNonSlashEnd;\n else if (end === -1)\n end = path.length;\n return path.slice(start, end);\n }\n for (let i = path.length - 1; i >= 0; --i) {\n if (path[i] === '/') {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n }\n else if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // path component\n matchedSlash = false;\n end = i + 1;\n }\n }\n if (end === -1)\n return '';\n return path.slice(start, end);\n}\nexport function extname(path) {\n let startDot = -1;\n let startPart = 0;\n let end = -1;\n let matchedSlash = true;\n // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n let preDotState = 0;\n for (let i = path.length - 1; i >= 0; --i) {\n if (path[i] === '/') {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n continue;\n }\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n if (path[i] === '.') {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1)\n startDot = i;\n else if (preDotState !== 1)\n preDotState = 1;\n }\n else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n if (startDot === -1 ||\n end === -1 ||\n // We saw a non-dot character immediately before the dot\n preDotState === 0 ||\n // The (right-most) trimmed path component is exactly '..'\n (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {\n return '';\n }\n return path.slice(startDot, end);\n}\nexport function format(pathObject) {\n validateObject(pathObject, 'pathObject');\n const dir = pathObject.dir || pathObject.root;\n const base = pathObject.base || `${pathObject.name || ''}${formatExt(pathObject.ext)}`;\n if (!dir) {\n return base;\n }\n return dir === pathObject.root ? `${dir}${base}` : `${dir}/${base}`;\n}\nexport function parse(path) {\n const isAbsolute = path.startsWith('/');\n const ret = { root: isAbsolute ? '/' : '', dir: '', base: '', ext: '', name: '' };\n if (path.length === 0)\n return ret;\n const start = isAbsolute ? 1 : 0;\n let startDot = -1;\n let startPart = 0;\n let end = -1;\n let matchedSlash = true;\n let i = path.length - 1;\n // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n let preDotState = 0;\n // Get non-dir info\n for (; i >= start; --i) {\n if (path[i] === '/') {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n continue;\n }\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n if (path[i] === '.') {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1)\n startDot = i;\n else if (preDotState !== 1)\n preDotState = 1;\n }\n else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n if (end !== -1) {\n const start = startPart === 0 && isAbsolute ? 1 : startPart;\n if (startDot === -1 ||\n // We saw a non-dot character immediately before the dot\n preDotState === 0 ||\n // The (right-most) trimmed path component is exactly '..'\n (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {\n ret.base = ret.name = path.slice(start, end);\n }\n else {\n ret.name = path.slice(start, startDot);\n ret.base = path.slice(start, end);\n ret.ext = path.slice(startDot, end);\n }\n }\n if (startPart > 0)\n ret.dir = path.slice(0, startPart - 1);\n else if (isAbsolute)\n ret.dir = '/';\n return ret;\n}\n", "import { ErrnoError, Errno } from '@zenfs/core';\n\n/**\n * Converts a DOMException into an Errno\n * @see https://developer.mozilla.org/Web/API/DOMException\n */\nfunction errnoForDOMException(ex: DOMException): keyof typeof Errno {\n\tswitch (ex.name) {\n\t\tcase 'IndexSizeError':\n\t\tcase 'HierarchyRequestError':\n\t\tcase 'InvalidCharacterError':\n\t\tcase 'InvalidStateError':\n\t\tcase 'SyntaxError':\n\t\tcase 'NamespaceError':\n\t\tcase 'TypeMismatchError':\n\t\tcase 'ConstraintError':\n\t\tcase 'VersionError':\n\t\tcase 'URLMismatchError':\n\t\tcase 'InvalidNodeTypeError':\n\t\t\treturn 'EINVAL';\n\t\tcase 'WrongDocumentError':\n\t\t\treturn 'EXDEV';\n\t\tcase 'NoModificationAllowedError':\n\t\tcase 'InvalidModificationError':\n\t\tcase 'InvalidAccessError':\n\t\tcase 'SecurityError':\n\t\tcase 'NotAllowedError':\n\t\t\treturn 'EACCES';\n\t\tcase 'NotFoundError':\n\t\t\treturn 'ENOENT';\n\t\tcase 'NotSupportedError':\n\t\t\treturn 'ENOTSUP';\n\t\tcase 'InUseAttributeError':\n\t\t\treturn 'EBUSY';\n\t\tcase 'NetworkError':\n\t\t\treturn 'ENETDOWN';\n\t\tcase 'AbortError':\n\t\t\treturn 'EINTR';\n\t\tcase 'QuotaExceededError':\n\t\t\treturn 'ENOSPC';\n\t\tcase 'TimeoutError':\n\t\t\treturn 'ETIMEDOUT';\n\t\tcase 'ReadOnlyError':\n\t\t\treturn 'EROFS';\n\t\tcase 'DataCloneError':\n\t\tcase 'EncodingError':\n\t\tcase 'NotReadableError':\n\t\tcase 'DataError':\n\t\tcase 'TransactionInactiveError':\n\t\tcase 'OperationError':\n\t\tcase 'UnknownError':\n\t\tdefault:\n\t\t\treturn 'EIO';\n\t}\n}\n\n/**\n * @internal\n */\nexport type ConvertException = ErrnoError | DOMException | Error;\n\n/**\n * Handles converting errors, then rethrowing them\n * @internal\n */\nexport function convertException(ex: ConvertException, path?: string, syscall?: string): ErrnoError {\n\tif (ex instanceof ErrnoError) {\n\t\treturn ex;\n\t}\n\n\tconst code = ex instanceof DOMException ? Errno[errnoForDOMException(ex)] : Errno.EIO;\n\tconst error = new ErrnoError(code, ex.message, path, syscall);\n\terror.stack = ex.stack!;\n\terror.cause = ex.cause;\n\treturn error;\n}\n", "import type { Backend, FileSystemMetadata } from '@zenfs/core';\nimport { ErrnoError, Async, Errno, FileSystem, FileType, InMemory, PreloadFile, Stats } from '@zenfs/core';\nimport { basename, dirname, join } from '@zenfs/core/emulation/path.js';\nimport { convertException, type ConvertException } from './utils.js';\n\ndeclare global {\n\tinterface FileSystemDirectoryHandle {\n\t\t[Symbol.iterator](): IterableIterator<[string, FileSystemHandle]>;\n\t\tentries(): IterableIterator<[string, FileSystemHandle]>;\n\t\tkeys(): IterableIterator<string>;\n\t\tvalues(): IterableIterator<FileSystemHandle>;\n\t}\n}\n\nexport interface WebAccessOptions {\n\thandle: FileSystemDirectoryHandle;\n}\n\nexport class WebAccessFS extends Async(FileSystem) {\n\tprivate _handles: Map<string, FileSystemHandle> = new Map();\n\n\t/**\n\t * @hidden\n\t */\n\t_sync: FileSystem;\n\n\tpublic constructor({ handle }: WebAccessOptions) {\n\t\tsuper();\n\t\tthis._handles.set('/', handle);\n\t\tthis._sync = InMemory.create({ name: 'accessfs-cache' });\n\t}\n\n\tpublic metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\t...super.metadata(),\n\t\t\tname: 'WebAccess',\n\t\t};\n\t}\n\n\tpublic async sync(p: string, data: Uint8Array, stats: Stats): Promise<void> {\n\t\tconst currentStats = await this.stat(p);\n\t\tif (stats.mtime !== currentStats!.mtime) {\n\t\t\tawait this.writeFile(p, data);\n\t\t}\n\t}\n\n\tpublic async rename(oldPath: string, newPath: string): Promise<void> {\n\t\ttry {\n\t\t\tconst handle = await this.getHandle(oldPath);\n\t\t\tif (handle instanceof FileSystemDirectoryHandle) {\n\t\t\t\tconst files = await this.readdir(oldPath);\n\n\t\t\t\tawait this.mkdir(newPath);\n\t\t\t\tif (files.length == 0) {\n\t\t\t\t\tawait this.unlink(oldPath);\n\t\t\t\t} else {\n\t\t\t\t\tfor (const file of files) {\n\t\t\t\t\t\tawait this.rename(join(oldPath, file), join(newPath, file));\n\t\t\t\t\t\tawait this.unlink(oldPath);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!(handle instanceof FileSystemFileHandle)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst oldFile = await handle.getFile(),\n\t\t\t\tdestFolder = await this.getHandle(dirname(newPath));\n\t\t\tif (!(destFolder instanceof FileSystemDirectoryHandle)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst newFile = await destFolder.getFileHandle(basename(newPath), { create: true });\n\t\t\tconst writable = await newFile.createWritable();\n\t\t\tawait writable.write(await oldFile.arrayBuffer());\n\n\t\t\twritable.close();\n\t\t\tawait this.unlink(oldPath);\n\t\t} catch (ex) {\n\t\t\tthrow convertException(ex as ConvertException, oldPath, 'rename');\n\t\t}\n\t}\n\n\tpublic async writeFile(fname: string, data: Uint8Array): Promise<void> {\n\t\tconst handle = await this.getHandle(dirname(fname));\n\t\tif (!(handle instanceof FileSystemDirectoryHandle)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst file = await handle.getFileHandle(basename(fname), { create: true });\n\t\tconst writable = await file.createWritable();\n\t\tawait writable.write(data);\n\t\tawait writable.close();\n\t}\n\n\tpublic async createFile(path: string, flag: string): Promise<PreloadFile<this>> {\n\t\tawait this.writeFile(path, new Uint8Array());\n\t\treturn this.openFile(path, flag);\n\t}\n\n\tpublic async stat(path: string): Promise<Stats> {\n\t\tconst handle = await this.getHandle(path);\n\t\tif (!handle) {\n\t\t\tthrow ErrnoError.With('ENOENT', path, 'stat');\n\t\t}\n\t\tif (handle instanceof FileSystemDirectoryHandle) {\n\t\t\treturn new Stats({ mode: 0o777 | FileType.DIRECTORY, size: 4096 });\n\t\t}\n\t\tif (handle instanceof FileSystemFileHandle) {\n\t\t\tconst { lastModified, size } = await handle.getFile();\n\t\t\treturn new Stats({ mode: 0o777 | FileType.FILE, size, mtimeMs: lastModified });\n\t\t}\n\t\tthrow new ErrnoError(Errno.EBADE, 'Handle is not a directory or file', path, 'stat');\n\t}\n\n\tpublic async openFile(path: string, flag: string): Promise<PreloadFile<this>> {\n\t\tconst handle = await this.getHandle(path);\n\t\tif (!(handle instanceof FileSystemFileHandle)) {\n\t\t\tthrow ErrnoError.With('EISDIR', path, 'openFile');\n\t\t}\n\t\ttry {\n\t\t\tconst file = await handle.getFile();\n\t\t\tconst data = new Uint8Array(await file.arrayBuffer());\n\t\t\tconst stats = new Stats({ mode: 0o777 | FileType.FILE, size: file.size, mtimeMs: file.lastModified });\n\t\t\treturn new PreloadFile(this, path, flag, stats, data);\n\t\t} catch (ex) {\n\t\t\tthrow convertException(ex as ConvertException, path, 'openFile');\n\t\t}\n\t}\n\n\tpublic async unlink(path: string): Promise<void> {\n\t\tconst handle = await this.getHandle(dirname(path));\n\t\tif (handle instanceof FileSystemDirectoryHandle) {\n\t\t\ttry {\n\t\t\t\tawait handle.removeEntry(basename(path), { recursive: true });\n\t\t\t} catch (ex) {\n\t\t\t\tthrow convertException(ex as ConvertException, path, 'unlink');\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async link(srcpath: string): Promise<void> {\n\t\tthrow ErrnoError.With('ENOSYS', srcpath, 'WebAccessFS.link');\n\t}\n\n\tpublic async rmdir(path: string): Promise<void> {\n\t\treturn this.unlink(path);\n\t}\n\n\tpublic async mkdir(path: string): Promise<void> {\n\t\tconst existingHandle = await this.getHandle(path);\n\t\tif (existingHandle) {\n\t\t\tthrow ErrnoError.With('EEXIST', path, 'mkdir');\n\t\t}\n\n\t\tconst handle = await this.getHandle(dirname(path));\n\t\tif (!(handle instanceof FileSystemDirectoryHandle)) {\n\t\t\tthrow ErrnoError.With('ENOTDIR', path, 'mkdir');\n\t\t}\n\t\tawait handle.getDirectoryHandle(basename(path), { create: true });\n\t}\n\n\tpublic async readdir(path: string): Promise<string[]> {\n\t\tconst handle = await this.getHandle(path);\n\t\tif (!(handle instanceof FileSystemDirectoryHandle)) {\n\t\t\tthrow ErrnoError.With('ENOTDIR', path, 'readdir');\n\t\t}\n\t\tconst _keys: string[] = [];\n\t\tfor await (const key of handle.keys()) {\n\t\t\t_keys.push(join(path, key));\n\t\t}\n\t\treturn _keys;\n\t}\n\n\tprotected async getHandle(path: string): Promise<FileSystemHandle> {\n\t\tif (this._handles.has(path)) {\n\t\t\treturn this._handles.get(path)!;\n\t\t}\n\n\t\tlet walked = '/';\n\n\t\tfor (const part of path.split('/').slice(1)) {\n\t\t\tconst handle = this._handles.get(walked);\n\t\t\tif (!(handle instanceof FileSystemDirectoryHandle)) {\n\t\t\t\tthrow ErrnoError.With('ENOTDIR', walked, 'getHandle');\n\t\t\t}\n\t\t\twalked = join(walked, part);\n\n\t\t\ttry {\n\t\t\t\tconst dirHandle = await handle.getDirectoryHandle(part);\n\t\t\t\tthis._handles.set(walked, dirHandle);\n\t\t\t} catch (_ex) {\n\t\t\t\tconst ex = _ex as DOMException;\n\t\t\t\tif (ex.name == 'TypeMismatchError') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst fileHandle = await handle.getFileHandle(part);\n\t\t\t\t\t\tthis._handles.set(walked, fileHandle);\n\t\t\t\t\t} catch (ex) {\n\t\t\t\t\t\tconvertException(ex as ConvertException, walked, 'getHandle');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (ex.name === 'TypeError') {\n\t\t\t\t\tthrow new ErrnoError(Errno.ENOENT, ex.message, walked, 'getHandle');\n\t\t\t\t}\n\n\t\t\t\tconvertException(ex, walked, 'getHandle');\n\t\t\t}\n\t\t}\n\n\t\treturn this._handles.get(path)!;\n\t}\n}\n\nexport const WebAccess = {\n\tname: 'WebAccess',\n\n\toptions: {\n\t\thandle: {\n\t\t\ttype: 'object',\n\t\t\trequired: true,\n\t\t\tdescription: 'The directory handle to use for the root',\n\t\t},\n\t},\n\n\tisAvailable(): boolean {\n\t\treturn typeof FileSystemHandle == 'function';\n\t},\n\n\tcreate(options: WebAccessOptions) {\n\t\treturn new WebAccessFS(options);\n\t},\n} as const satisfies Backend<WebAccessFS, WebAccessOptions>;\n", "import type { AsyncStore, AsyncStoreOptions, AsyncTransaction, Backend, Ino } from '@zenfs/core';\nimport { AsyncStoreFS } from '@zenfs/core';\nimport { convertException, type ConvertException } from './utils.js';\n\nfunction wrap<T>(request: IDBRequest<T>): Promise<T> {\n\treturn new Promise((resolve, reject) => {\n\t\trequest.onsuccess = () => resolve(request.result);\n\t\trequest.onerror = e => {\n\t\t\te.preventDefault();\n\t\t\treject(convertException(request.error!));\n\t\t};\n\t});\n}\n\n/**\n * @hidden\n */\nexport class IndexedDBTransaction implements AsyncTransaction {\n\tconstructor(\n\t\tpublic tx: IDBTransaction,\n\t\tpublic store: IDBObjectStore\n\t) {}\n\n\tpublic get(key: Ino): Promise<Uint8Array> {\n\t\treturn wrap<Uint8Array>(this.store.get(key.toString()));\n\t}\n\n\t/**\n\t * @todo return false when add has a key conflict (no error)\n\t */\n\tpublic async put(key: Ino, data: Uint8Array, overwrite: boolean): Promise<boolean> {\n\t\tawait wrap(this.store[overwrite ? 'put' : 'add'](data, key.toString()));\n\t\treturn true;\n\t}\n\n\tpublic remove(key: Ino): Promise<void> {\n\t\treturn wrap(this.store.delete(key.toString()));\n\t}\n\n\tpublic async commit(): Promise<void> {\n\t\treturn;\n\t}\n\n\tpublic async abort(): Promise<void> {\n\t\ttry {\n\t\t\tthis.tx.abort();\n\t\t} catch (e) {\n\t\t\tthrow convertException(e as ConvertException);\n\t\t}\n\t}\n}\n\nexport class IndexedDBStore implements AsyncStore {\n\tpublic static async create(storeName: string, indexedDB: IDBFactory = globalThis.indexedDB): Promise<IndexedDBStore> {\n\t\tconst req: IDBOpenDBRequest = indexedDB.open(storeName, 1);\n\n\t\treq.onupgradeneeded = () => {\n\t\t\tconst db: IDBDatabase = req.result;\n\t\t\t// This should never happen; we're at version 1. Why does another database exist?\n\t\t\tif (db.objectStoreNames.contains(storeName)) {\n\t\t\t\tdb.deleteObjectStore(storeName);\n\t\t\t}\n\t\t\tdb.createObjectStore(storeName);\n\t\t};\n\n\t\tconst result = await wrap(req);\n\t\treturn new IndexedDBStore(result, storeName);\n\t}\n\n\tconstructor(\n\t\tprotected db: IDBDatabase,\n\t\tprotected storeName: string\n\t) {}\n\n\tpublic get name(): string {\n\t\treturn IndexedDB.name + ':' + this.storeName;\n\t}\n\n\tpublic clear(): Promise<void> {\n\t\treturn wrap(this.db.transaction(this.storeName, 'readwrite').objectStore(this.storeName).clear());\n\t}\n\n\tpublic beginTransaction(): IndexedDBTransaction {\n\t\tconst tx = this.db.transaction(this.storeName, 'readwrite');\n\t\treturn new IndexedDBTransaction(tx, tx.objectStore(this.storeName));\n\t}\n}\n\n/**\n * Configuration options for the IndexedDB file system.\n */\nexport interface IndexedDBOptions extends Omit<AsyncStoreOptions, 'store'> {\n\t/**\n\t * The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name.\n\t */\n\tstoreName?: string;\n\n\t/**\n\t * The IDBFactory to use. Defaults to `globalThis.indexedDB`.\n\t */\n\tidbFactory?: IDBFactory;\n}\n\n/**\n * A file system that uses the IndexedDB key value file system.\n */\n\nexport const IndexedDB = {\n\tname: 'IndexedDB',\n\n\toptions: {\n\t\tstoreName: {\n\t\t\ttype: 'string',\n\t\t\trequired: false,\n\t\t\tdescription: 'The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name.',\n\t\t},\n\t\tlruCacheSize: {\n\t\t\ttype: 'number',\n\t\t\trequired: false,\n\t\t\tdescription: 'The size of the inode cache. Defaults to 100. A size of 0 or below disables caching.',\n\t\t},\n\t\tidbFactory: {\n\t\t\ttype: 'object',\n\t\t\trequired: false,\n\t\t\tdescription: 'The IDBFactory to use. Defaults to globalThis.indexedDB.',\n\t\t},\n\t},\n\n\tasync isAvailable(idbFactory: IDBFactory = globalThis.indexedDB): Promise<boolean> {\n\t\ttry {\n\t\t\tif (!(idbFactory instanceof IDBFactory)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst req = idbFactory.open('__zenfs_test');\n\t\t\tawait wrap(req);\n\t\t\tidbFactory.deleteDatabase('__zenfs_test');\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\tidbFactory.deleteDatabase('__zenfs_test');\n\t\t\treturn false;\n\t\t}\n\t},\n\n\tcreate(options: IndexedDBOptions) {\n\t\tconst store = IndexedDBStore.create(options.storeName || 'zenfs', options.idbFactory);\n\t\tconst fs = new AsyncStoreFS({ ...options, store });\n\t\treturn fs;\n\t},\n} as const satisfies Backend<AsyncStoreFS, IndexedDBOptions>;\n", "import type { Backend, Ino, SimpleSyncStore, SyncStore } from '@zenfs/core';\nimport { ErrnoError, Errno, SimpleSyncTransaction, SyncStoreFS, decode, encode } from '@zenfs/core';\n\n/**\n * A synchronous key-value store backed by Storage.\n */\nexport class WebStorageStore implements SyncStore, SimpleSyncStore {\n\tpublic get name(): string {\n\t\treturn WebStorage.name;\n\t}\n\n\tconstructor(protected _storage: Storage) {}\n\n\tpublic clear(): void {\n\t\tthis._storage.clear();\n\t}\n\n\tpublic beginTransaction(): SimpleSyncTransaction {\n\t\t// No need to differentiate.\n\t\treturn new SimpleSyncTransaction(this);\n\t}\n\n\tpublic get(key: Ino): Uint8Array | undefined {\n\t\tconst data = this._storage.getItem(key.toString());\n\t\tif (typeof data != 'string') {\n\t\t\treturn;\n\t\t}\n\n\t\treturn encode(data);\n\t}\n\n\tpublic put(key: Ino, data: Uint8Array, overwrite: boolean): boolean {\n\t\ttry {\n\t\t\tif (!overwrite && this._storage.getItem(key.toString()) !== null) {\n\t\t\t\t// Don't want to overwrite the key!\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis._storage.setItem(key.toString(), decode(data));\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\tthrow new ErrnoError(Errno.ENOSPC, 'Storage is full.');\n\t\t}\n\t}\n\n\tpublic remove(key: Ino): void {\n\t\ttry {\n\t\t\tthis._storage.removeItem(key.toString());\n\t\t} catch (e) {\n\t\t\tthrow new ErrnoError(Errno.EIO, 'Unable to delete key ' + key + ': ' + e);\n\t\t}\n\t}\n}\n\n/**\n * Options to pass to the StorageFileSystem\n */\nexport interface WebStorageOptions {\n\t/**\n\t * The Storage to use. Defaults to globalThis.localStorage.\n\t */\n\tstorage?: Storage;\n}\n\n/**\n * A synchronous file system backed by a `Storage` (e.g. localStorage).\n */\nexport const WebStorage = {\n\tname: 'WebStorage',\n\n\toptions: {\n\t\tstorage: {\n\t\t\ttype: 'object',\n\t\t\trequired: false,\n\t\t\tdescription: 'The Storage to use. Defaults to globalThis.localStorage.',\n\t\t},\n\t},\n\n\tisAvailable(storage: Storage = globalThis.localStorage): boolean {\n\t\treturn storage instanceof globalThis.Storage;\n\t},\n\n\tcreate({ storage = globalThis.localStorage }: WebStorageOptions) {\n\t\treturn new SyncStoreFS({ store: new WebStorageStore(storage) });\n\t},\n} as const satisfies Backend<SyncStoreFS, WebStorageOptions>;\n"],
5
+ "mappings": "gfAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,mBAAAC,EAAA,yBAAAC,EAAA,cAAAC,EAAA,gBAAAC,EAAA,eAAAC,EAAA,oBAAA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AEO,IAAIC,EAAkC,CAC5C,IAAMC,EAAO,KAAK,SAAS,QAAQD,EAAI,SAAS,CAAC,EACjD,GAAI,OAAOC,GAAQ,SAInB,OAAOC,EAAOD,CAAI,CACnB,CAEO,IAAID,EAAUC,EAAkBE,EAA6B,CACnE,GAAI,CACH,MAAI,CAACA,GAAa,KAAK,SAAS,QAAQH,EAAI,SAAS,CAAC,IAAM,KAEpD,IAER,KAAK,SAAS,QAAQA,EAAI,SAAS,EAAGI,EAAOH,CAAI,CAAC,EAC3C,GACR,MAAE,CACD,MAAM,IAAII,EAAWC,EAAM,OAAQ,kBAAkB,CACtD,CACD,CAEO,OAAON,EAAgB,CAC7B,GAAI,CACH,KAAK,SAAS,WAAWA,EAAI,SAAS,CAAC,CACxC,OAASO,EAAP,CACD,MAAM,IAAIF,EAAWC,EAAM,IAAK,wBAA0BN,EAAM,KAAOO,CAAC,CACzE,CACD,CACD,EA7CaC,EAAAZ,EAAA,mBA4DN,IAAME,EAAa,CACzB,KAAM,aAEN,QAAS,CACR,QAAS,CACR,KAAM,SACN,SAAU,GACV,YAAa,0DACd,CACD,EAEA,YAAYW,EAAmB,WAAW,aAAuB,CAChE,OAAOA,aAAmB,WAAW,OACtC,EAEA,OAAO,CAAE,QAAAA,EAAU,WAAW,YAAa,EAAsB,CAChE,OAAO,IAAIC,EAAY,CAAE,MAAO,IAAId,EAAgBa,CAAO,CAAE,CAAC,CAC/D,CACD",
6
+ "names": ["src_exports", "__export", "IndexedDB", "IndexedDBStore", "IndexedDBTransaction", "WebAccess", "WebAccessFS", "WebStorage", "WebStorageStore", "core_default", "ActionType", "Async", "AsyncIndexFS", "AsyncStoreFS", "BigIntStats", "BigIntStatsFs", "Dir", "Dirent", "Errno", "ErrnoError", "Fetch", "FetchFS", "File", "FileIndex", "FileSystem", "FileType", "InMemory", "InMemoryStore", "IndexDirInode", "IndexFS", "IndexFileInode", "IndexInode", "Inode", "LockedFS", "Mutex", "NoSyncFile", "Overlay", "OverlayFS", "Port", "PortFS", "PortFile", "PortStore", "PortStoreBackend", "PortTransaction", "PreloadFile", "ReadStream", "Readonly", "SimpleSyncTransaction", "Stats", "StatsCommon", "StatsFs", "Sync", "SyncIndexFS", "SyncStoreFS", "UnlockedOverlayFS", "WriteStream", "_toUnixTimestamp", "access", "accessSync", "appendFile", "appendFileSync", "attachFS", "attachStore", "checkOptions", "chmod", "chmodSync", "chown", "chownSync", "close", "closeSync", "configure", "constants", "copyFile", "copyFileSync", "cp", "cpSync", "createBackend", "createReadStream", "createWriteStream", "decode", "decodeDirListing", "detachFS", "detachStore", "encode", "encodeDirListing", "errorMessages", "exists", "existsSync", "fchmod", "fchmodSync", "fchown", "fchownSync", "fdatasync", "fdatasyncSync", "flagToMode", "flagToNumber", "flagToString", "fs", "fstat", "fstatSync", "fsync", "fsyncSync", "ftruncate", "ftruncateSync", "futimes", "futimesSync", "isAppendable", "isBackend", "isBackendConfig", "isExclusive", "isReadable", "isSynchronous", "isTruncating", "isWriteable", "lchmod", "lchmodSync", "lchown", "lchownSync", "levenshtein", "link", "linkSync", "lopenSync", "lstat", "lstatSync", "lutimes", "lutimesSync", "mkdir", "mkdirSync", "mkdirpSync", "mkdtemp", "mkdtempSync", "mount", "mountObject", "mounts", "nop", "normalizeMode", "normalizeOptions", "normalizePath", "normalizeTime", "open", "openAsBlob", "openSync", "opendir", "opendirSync", "parseFlag", "pathExistsAction", "pathNotExistsAction", "promises", "randomIno", "read", "readFile", "readFileSync", "readSync", "readdir", "readdirSync", "readlink", "readlinkSync", "readv", "readvSync", "realpath", "realpathSync", "rename", "renameSync", "resolveMountConfig", "rm", "rmSync", "rmdir", "rmdirSync", "rootCred", "rootIno", "setImmediate", "size_max", "stat", "statSync", "statfs", "statfsSync", "symlink", "symlinkSync", "truncate", "truncateSync", "umount", "unlink", "unlinkSync", "unwatchFile", "utimes", "utimesSync", "watch", "watchFile", "write", "writeFile", "writeFileSync", "writeSync", "writev", "writevSync", "normalizeString", "path", "allowAboveRoot", "res", "lastSegmentLength", "lastSlash", "dots", "char", "i", "lastSlashIndex", "__name", "normalize", "path", "isAbsolute", "trailingSeparator", "normalizeString", "__name", "join", "parts", "joined", "normalize", "__name", "dirname", "path", "hasRoot", "end", "matchedSlash", "__name", "basename", "suffix", "start", "extIdx", "firstNonSlashEnd", "i", "errnoForDOMException", "ex", "__name", "convertException", "path", "syscall", "ErrnoError", "code", "Errno", "error", "WebAccessFS", "Async", "FileSystem", "handle", "InMemory", "p", "data", "stats", "currentStats", "oldPath", "newPath", "files", "file", "join", "oldFile", "destFolder", "dirname", "writable", "basename", "ex", "convertException", "fname", "path", "flag", "ErrnoError", "Stats", "FileType", "lastModified", "size", "Errno", "PreloadFile", "srcpath", "_keys", "key", "walked", "part", "dirHandle", "_ex", "fileHandle", "__name", "WebAccess", "options", "wrap", "request", "resolve", "reject", "e", "convertException", "__name", "IndexedDBTransaction", "tx", "store", "key", "data", "overwrite", "IndexedDBStore", "db", "storeName", "indexedDB", "req", "result", "IndexedDB", "idbFactory", "options", "AsyncStoreFS", "WebStorageStore", "_storage", "WebStorage", "SimpleSyncTransaction", "key", "data", "encode", "overwrite", "decode", "ErrnoError", "Errno", "e", "__name", "storage", "SyncStoreFS"]
7
7
  }
package/dist/utils.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { ApiError } from '@zenfs/core';
1
+ import { ErrnoError } from '@zenfs/core';
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export type ConvertException = ApiError | DOMException | Error;
5
+ export type ConvertException = ErrnoError | DOMException | Error;
6
6
  /**
7
7
  * Handles converting errors, then rethrowing them
8
8
  * @internal
9
9
  */
10
- export declare function convertException(ex: ConvertException, path?: string, syscall?: string): ApiError;
10
+ export declare function convertException(ex: ConvertException, path?: string, syscall?: string): ErrnoError;
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
- import { ApiError, ErrorCode } from '@zenfs/core';
1
+ import { ErrnoError, Errno } from '@zenfs/core';
2
2
  /**
3
- * Converts a DOMException into an ErrorCode
3
+ * Converts a DOMException into an Errno
4
4
  * @see https://developer.mozilla.org/Web/API/DOMException
5
5
  */
6
6
  function errnoForDOMException(ex) {
@@ -57,11 +57,11 @@ function errnoForDOMException(ex) {
57
57
  * @internal
58
58
  */
59
59
  export function convertException(ex, path, syscall) {
60
- if (ex instanceof ApiError) {
60
+ if (ex instanceof ErrnoError) {
61
61
  return ex;
62
62
  }
63
- const code = ex instanceof DOMException ? ErrorCode[errnoForDOMException(ex)] : ErrorCode.EIO;
64
- const error = new ApiError(code, ex.message, path, syscall);
63
+ const code = ex instanceof DOMException ? Errno[errnoForDOMException(ex)] : Errno.EIO;
64
+ const error = new ErrnoError(code, ex.message, path, syscall);
65
65
  error.stack = ex.stack;
66
66
  error.cause = ex.cause;
67
67
  return error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/dom",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "DOM backends for ZenFS",
5
5
  "main": "dist/index.js",
6
6
  "types": "src/index.ts",
@@ -46,6 +46,6 @@
46
46
  "typescript": "5.2.2"
47
47
  },
48
48
  "peerDependencies": {
49
- "@zenfs/core": "^0.9.7"
49
+ "@zenfs/core": "^0.10.0"
50
50
  }
51
51
  }
package/readme.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  - `WebStorage`: Stores files in a `Storage` object, like `localStorage` and `sessionStorage`.
11
11
  - `IndexedDB`: Stores files into an `IndexedDB` object database.
12
- - `WebAccess`: Store files using the [Web File System API](https://developer.mozilla.org/Web/API/File_System_API).
12
+ - `WebAccess`: Store files using the [File System Access API](https://developer.mozilla.org/Web/API/File_System_API).
13
13
 
14
14
  For more information, see the [API documentation](https://zen-fs.github.io/dom).
15
15
 
package/src/IndexedDB.ts CHANGED
@@ -114,7 +114,7 @@ export const IndexedDB = {
114
114
  required: false,
115
115
  description: 'The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name.',
116
116
  },
117
- cacheSize: {
117
+ lruCacheSize: {
118
118
  type: 'number',
119
119
  required: false,
120
120
  description: 'The size of the inode cache. Defaults to 100. A size of 0 or below disables caching.',
@@ -146,4 +146,4 @@ export const IndexedDB = {
146
146
  const fs = new AsyncStoreFS({ ...options, store });
147
147
  return fs;
148
148
  },
149
- } as const satisfies Backend;
149
+ } as const satisfies Backend<AsyncStoreFS, IndexedDBOptions>;
package/src/Storage.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Backend, Ino, SimpleSyncStore, SyncStore } from '@zenfs/core';
2
- import { ApiError, ErrorCode, SimpleSyncTransaction, SyncStoreFS, decode, encode } from '@zenfs/core';
2
+ import { ErrnoError, Errno, SimpleSyncTransaction, SyncStoreFS, decode, encode } from '@zenfs/core';
3
3
 
4
4
  /**
5
5
  * A synchronous key-value store backed by Storage.
@@ -38,7 +38,7 @@ export class WebStorageStore implements SyncStore, SimpleSyncStore {
38
38
  this._storage.setItem(key.toString(), decode(data));
39
39
  return true;
40
40
  } catch (e) {
41
- throw new ApiError(ErrorCode.ENOSPC, 'Storage is full.');
41
+ throw new ErrnoError(Errno.ENOSPC, 'Storage is full.');
42
42
  }
43
43
  }
44
44
 
@@ -46,7 +46,7 @@ export class WebStorageStore implements SyncStore, SimpleSyncStore {
46
46
  try {
47
47
  this._storage.removeItem(key.toString());
48
48
  } catch (e) {
49
- throw new ApiError(ErrorCode.EIO, 'Unable to delete key ' + key + ': ' + e);
49
+ throw new ErrnoError(Errno.EIO, 'Unable to delete key ' + key + ': ' + e);
50
50
  }
51
51
  }
52
52
  }
@@ -82,4 +82,4 @@ export const WebStorage = {
82
82
  create({ storage = globalThis.localStorage }: WebStorageOptions) {
83
83
  return new SyncStoreFS({ store: new WebStorageStore(storage) });
84
84
  },
85
- } as const satisfies Backend;
85
+ } as const satisfies Backend<SyncStoreFS, WebStorageOptions>;
package/src/access.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Backend, FileSystemMetadata } from '@zenfs/core';
2
- import { ApiError, Async, ErrorCode, FileSystem, FileType, InMemory, PreloadFile, Stats } from '@zenfs/core';
2
+ import { ErrnoError, Async, Errno, FileSystem, FileType, InMemory, PreloadFile, Stats } from '@zenfs/core';
3
3
  import { basename, dirname, join } from '@zenfs/core/emulation/path.js';
4
4
  import { convertException, type ConvertException } from './utils.js';
5
5
 
@@ -99,7 +99,7 @@ export class WebAccessFS extends Async(FileSystem) {
99
99
  public async stat(path: string): Promise<Stats> {
100
100
  const handle = await this.getHandle(path);
101
101
  if (!handle) {
102
- throw ApiError.With('ENOENT', path, 'stat');
102
+ throw ErrnoError.With('ENOENT', path, 'stat');
103
103
  }
104
104
  if (handle instanceof FileSystemDirectoryHandle) {
105
105
  return new Stats({ mode: 0o777 | FileType.DIRECTORY, size: 4096 });
@@ -108,13 +108,13 @@ export class WebAccessFS extends Async(FileSystem) {
108
108
  const { lastModified, size } = await handle.getFile();
109
109
  return new Stats({ mode: 0o777 | FileType.FILE, size, mtimeMs: lastModified });
110
110
  }
111
- throw new ApiError(ErrorCode.EBADE, 'Handle is not a directory or file', path, 'stat');
111
+ throw new ErrnoError(Errno.EBADE, 'Handle is not a directory or file', path, 'stat');
112
112
  }
113
113
 
114
114
  public async openFile(path: string, flag: string): Promise<PreloadFile<this>> {
115
115
  const handle = await this.getHandle(path);
116
116
  if (!(handle instanceof FileSystemFileHandle)) {
117
- throw ApiError.With('EISDIR', path, 'openFile');
117
+ throw ErrnoError.With('EISDIR', path, 'openFile');
118
118
  }
119
119
  try {
120
120
  const file = await handle.getFile();
@@ -138,7 +138,7 @@ export class WebAccessFS extends Async(FileSystem) {
138
138
  }
139
139
 
140
140
  public async link(srcpath: string): Promise<void> {
141
- throw ApiError.With('ENOSYS', srcpath, 'WebAccessFS.link');
141
+ throw ErrnoError.With('ENOSYS', srcpath, 'WebAccessFS.link');
142
142
  }
143
143
 
144
144
  public async rmdir(path: string): Promise<void> {
@@ -148,12 +148,12 @@ export class WebAccessFS extends Async(FileSystem) {
148
148
  public async mkdir(path: string): Promise<void> {
149
149
  const existingHandle = await this.getHandle(path);
150
150
  if (existingHandle) {
151
- throw ApiError.With('EEXIST', path, 'mkdir');
151
+ throw ErrnoError.With('EEXIST', path, 'mkdir');
152
152
  }
153
153
 
154
154
  const handle = await this.getHandle(dirname(path));
155
155
  if (!(handle instanceof FileSystemDirectoryHandle)) {
156
- throw ApiError.With('ENOTDIR', path, 'mkdir');
156
+ throw ErrnoError.With('ENOTDIR', path, 'mkdir');
157
157
  }
158
158
  await handle.getDirectoryHandle(basename(path), { create: true });
159
159
  }
@@ -161,7 +161,7 @@ export class WebAccessFS extends Async(FileSystem) {
161
161
  public async readdir(path: string): Promise<string[]> {
162
162
  const handle = await this.getHandle(path);
163
163
  if (!(handle instanceof FileSystemDirectoryHandle)) {
164
- throw ApiError.With('ENOTDIR', path, 'readdir');
164
+ throw ErrnoError.With('ENOTDIR', path, 'readdir');
165
165
  }
166
166
  const _keys: string[] = [];
167
167
  for await (const key of handle.keys()) {
@@ -180,7 +180,7 @@ export class WebAccessFS extends Async(FileSystem) {
180
180
  for (const part of path.split('/').slice(1)) {
181
181
  const handle = this._handles.get(walked);
182
182
  if (!(handle instanceof FileSystemDirectoryHandle)) {
183
- throw ApiError.With('ENOTDIR', walked, 'getHandle');
183
+ throw ErrnoError.With('ENOTDIR', walked, 'getHandle');
184
184
  }
185
185
  walked = join(walked, part);
186
186
 
@@ -199,7 +199,7 @@ export class WebAccessFS extends Async(FileSystem) {
199
199
  }
200
200
 
201
201
  if (ex.name === 'TypeError') {
202
- throw new ApiError(ErrorCode.ENOENT, ex.message, walked, 'getHandle');
202
+ throw new ErrnoError(Errno.ENOENT, ex.message, walked, 'getHandle');
203
203
  }
204
204
 
205
205
  convertException(ex, walked, 'getHandle');
@@ -228,4 +228,4 @@ export const WebAccess = {
228
228
  create(options: WebAccessOptions) {
229
229
  return new WebAccessFS(options);
230
230
  },
231
- } as const satisfies Backend;
231
+ } as const satisfies Backend<WebAccessFS, WebAccessOptions>;
package/src/utils.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { ApiError, ErrorCode } from '@zenfs/core';
1
+ import { ErrnoError, Errno } from '@zenfs/core';
2
2
 
3
3
  /**
4
- * Converts a DOMException into an ErrorCode
4
+ * Converts a DOMException into an Errno
5
5
  * @see https://developer.mozilla.org/Web/API/DOMException
6
6
  */
7
- function errnoForDOMException(ex: DOMException): keyof typeof ErrorCode {
7
+ function errnoForDOMException(ex: DOMException): keyof typeof Errno {
8
8
  switch (ex.name) {
9
9
  case 'IndexSizeError':
10
10
  case 'HierarchyRequestError':
@@ -57,19 +57,19 @@ function errnoForDOMException(ex: DOMException): keyof typeof ErrorCode {
57
57
  /**
58
58
  * @internal
59
59
  */
60
- export type ConvertException = ApiError | DOMException | Error;
60
+ export type ConvertException = ErrnoError | DOMException | Error;
61
61
 
62
62
  /**
63
63
  * Handles converting errors, then rethrowing them
64
64
  * @internal
65
65
  */
66
- export function convertException(ex: ConvertException, path?: string, syscall?: string): ApiError {
67
- if (ex instanceof ApiError) {
66
+ export function convertException(ex: ConvertException, path?: string, syscall?: string): ErrnoError {
67
+ if (ex instanceof ErrnoError) {
68
68
  return ex;
69
69
  }
70
70
 
71
- const code = ex instanceof DOMException ? ErrorCode[errnoForDOMException(ex)] : ErrorCode.EIO;
72
- const error = new ApiError(code, ex.message, path, syscall);
71
+ const code = ex instanceof DOMException ? Errno[errnoForDOMException(ex)] : Errno.EIO;
72
+ const error = new ErrnoError(code, ex.message, path, syscall);
73
73
  error.stack = ex.stack!;
74
74
  error.cause = ex.cause;
75
75
  return error;