@zenfs/dom 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/IndexedDB.d.ts +24 -7
- package/dist/IndexedDB.js +19 -25
- package/dist/Storage.d.ts +16 -5
- package/dist/Storage.js +5 -5
- package/dist/access.d.ts +75 -0
- package/dist/{FileSystemAccess.js → access.js} +8 -27
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/FileSystemAccess.d.ts +0 -53
package/dist/IndexedDB.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AsyncStoreOptions, Ino } from '@zenfs/core';
|
|
2
2
|
import { AsyncTransaction, AsyncStore, AsyncStoreFS } from '@zenfs/core';
|
|
3
3
|
/**
|
|
4
4
|
* @hidden
|
|
@@ -28,15 +28,11 @@ export declare class IndexedDBStore implements AsyncStore {
|
|
|
28
28
|
/**
|
|
29
29
|
* Configuration options for the IndexedDB file system.
|
|
30
30
|
*/
|
|
31
|
-
export interface IndexedDBOptions {
|
|
31
|
+
export interface IndexedDBOptions extends Omit<AsyncStoreOptions, 'store'> {
|
|
32
32
|
/**
|
|
33
33
|
* The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name.
|
|
34
34
|
*/
|
|
35
35
|
storeName?: string;
|
|
36
|
-
/**
|
|
37
|
-
* The size of the inode cache. Defaults to 100. A size of 0 or below disables caching.
|
|
38
|
-
*/
|
|
39
|
-
cacheSize?: number;
|
|
40
36
|
/**
|
|
41
37
|
* The IDBFactory to use. Defaults to `globalThis.indexedDB`.
|
|
42
38
|
*/
|
|
@@ -45,4 +41,25 @@ export interface IndexedDBOptions {
|
|
|
45
41
|
/**
|
|
46
42
|
* A file system that uses the IndexedDB key value file system.
|
|
47
43
|
*/
|
|
48
|
-
export declare const IndexedDB:
|
|
44
|
+
export declare const IndexedDB: {
|
|
45
|
+
readonly name: "IndexedDB";
|
|
46
|
+
readonly options: {
|
|
47
|
+
readonly storeName: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
readonly required: false;
|
|
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
|
+
};
|
|
52
|
+
readonly cacheSize: {
|
|
53
|
+
readonly type: "number";
|
|
54
|
+
readonly required: false;
|
|
55
|
+
readonly description: "The size of the inode cache. Defaults to 100. A size of 0 or below disables caching.";
|
|
56
|
+
};
|
|
57
|
+
readonly idbFactory: {
|
|
58
|
+
readonly type: "object";
|
|
59
|
+
readonly required: false;
|
|
60
|
+
readonly description: "The IDBFactory to use. Defaults to globalThis.indexedDB.";
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
readonly isAvailable: (idbFactory?: IDBFactory) => Promise<boolean>;
|
|
64
|
+
readonly create: ({ lruCacheSize, storeName, idbFactory }: IndexedDBOptions) => AsyncStoreFS;
|
|
65
|
+
};
|
package/dist/IndexedDB.js
CHANGED
|
@@ -73,23 +73,18 @@ export class IndexedDBTransaction {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
export class IndexedDBStore {
|
|
76
|
-
static create(storeName, indexedDB) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
req.onerror = e => {
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
reject(new ApiError(ErrorCode.EACCES));
|
|
91
|
-
};
|
|
92
|
-
});
|
|
76
|
+
static async create(storeName, indexedDB) {
|
|
77
|
+
const req = indexedDB.open(storeName, 1);
|
|
78
|
+
req.onupgradeneeded = () => {
|
|
79
|
+
const db = req.result;
|
|
80
|
+
// This should never happen; we're at version 1. Why does another database exist?
|
|
81
|
+
if (db.objectStoreNames.contains(storeName)) {
|
|
82
|
+
db.deleteObjectStore(storeName);
|
|
83
|
+
}
|
|
84
|
+
db.createObjectStore(storeName);
|
|
85
|
+
};
|
|
86
|
+
const result = await wrap(req);
|
|
87
|
+
return new IndexedDBStore(result, storeName);
|
|
93
88
|
}
|
|
94
89
|
constructor(db, storeName) {
|
|
95
90
|
this.db = db;
|
|
@@ -140,25 +135,24 @@ export const IndexedDB = {
|
|
|
140
135
|
description: 'The IDBFactory to use. Defaults to globalThis.indexedDB.',
|
|
141
136
|
},
|
|
142
137
|
},
|
|
143
|
-
isAvailable(idbFactory = globalThis.indexedDB) {
|
|
138
|
+
async isAvailable(idbFactory = globalThis.indexedDB) {
|
|
144
139
|
try {
|
|
145
140
|
if (!(idbFactory instanceof IDBFactory)) {
|
|
146
141
|
return false;
|
|
147
142
|
}
|
|
148
143
|
const req = idbFactory.open('__zenfs_test');
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
req.onsuccess = () => idbFactory.deleteDatabase('__zenfs_test');
|
|
144
|
+
await wrap(req);
|
|
145
|
+
idbFactory.deleteDatabase('__zenfs_test');
|
|
146
|
+
return true;
|
|
153
147
|
}
|
|
154
148
|
catch (e) {
|
|
149
|
+
idbFactory.deleteDatabase('__zenfs_test');
|
|
155
150
|
return false;
|
|
156
151
|
}
|
|
157
|
-
return true;
|
|
158
152
|
},
|
|
159
|
-
create({
|
|
153
|
+
create({ lruCacheSize = 100, storeName = 'zenfs', idbFactory = globalThis.indexedDB }) {
|
|
160
154
|
const store = IndexedDBStore.create(storeName, idbFactory);
|
|
161
|
-
const fs = new AsyncStoreFS({
|
|
155
|
+
const fs = new AsyncStoreFS({ lruCacheSize, store });
|
|
162
156
|
return fs;
|
|
163
157
|
},
|
|
164
158
|
};
|
package/dist/Storage.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Ino } from '@zenfs/core';
|
|
2
2
|
import { SyncStore, SimpleSyncStore, SimpleSyncTransaction, SyncStoreFS } from '@zenfs/core';
|
|
3
3
|
/**
|
|
4
4
|
* A synchronous key-value store backed by Storage.
|
|
5
5
|
*/
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class WebStorageStore implements SyncStore, SimpleSyncStore {
|
|
7
7
|
protected _storage: Storage;
|
|
8
8
|
get name(): string;
|
|
9
9
|
constructor(_storage: Storage);
|
|
@@ -16,13 +16,24 @@ export declare class StorageStore implements SyncStore, SimpleSyncStore {
|
|
|
16
16
|
/**
|
|
17
17
|
* Options to pass to the StorageFileSystem
|
|
18
18
|
*/
|
|
19
|
-
export interface
|
|
19
|
+
export interface WebStorageOptions {
|
|
20
20
|
/**
|
|
21
21
|
* The Storage to use. Defaults to globalThis.localStorage.
|
|
22
22
|
*/
|
|
23
|
-
storage
|
|
23
|
+
storage?: Storage;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* A synchronous file system backed by a `Storage` (e.g. localStorage).
|
|
27
27
|
*/
|
|
28
|
-
export declare const
|
|
28
|
+
export declare const WebStorage: {
|
|
29
|
+
readonly name: "WebStorage";
|
|
30
|
+
readonly options: {
|
|
31
|
+
readonly storage: {
|
|
32
|
+
readonly type: "object";
|
|
33
|
+
readonly required: false;
|
|
34
|
+
readonly description: "The Storage to use. Defaults to globalThis.localStorage.";
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
readonly isAvailable: (storage?: Storage) => boolean;
|
|
38
|
+
readonly create: ({ storage }: WebStorageOptions) => SyncStoreFS;
|
|
39
|
+
};
|
package/dist/Storage.js
CHANGED
|
@@ -2,9 +2,9 @@ import { SimpleSyncTransaction, SyncStoreFS, ApiError, ErrorCode, encode, decode
|
|
|
2
2
|
/**
|
|
3
3
|
* A synchronous key-value store backed by Storage.
|
|
4
4
|
*/
|
|
5
|
-
export class
|
|
5
|
+
export class WebStorageStore {
|
|
6
6
|
get name() {
|
|
7
|
-
return
|
|
7
|
+
return WebStorage.name;
|
|
8
8
|
}
|
|
9
9
|
constructor(_storage) {
|
|
10
10
|
this._storage = _storage;
|
|
@@ -48,8 +48,8 @@ export class StorageStore {
|
|
|
48
48
|
/**
|
|
49
49
|
* A synchronous file system backed by a `Storage` (e.g. localStorage).
|
|
50
50
|
*/
|
|
51
|
-
export const
|
|
52
|
-
name: '
|
|
51
|
+
export const WebStorage = {
|
|
52
|
+
name: 'WebStorage',
|
|
53
53
|
options: {
|
|
54
54
|
storage: {
|
|
55
55
|
type: 'object',
|
|
@@ -61,6 +61,6 @@ export const Storage = {
|
|
|
61
61
|
return storage instanceof globalThis.Storage;
|
|
62
62
|
},
|
|
63
63
|
create({ storage = globalThis.localStorage }) {
|
|
64
|
-
return new SyncStoreFS({ store: new
|
|
64
|
+
return new SyncStoreFS({ store: new WebStorageStore(storage) });
|
|
65
65
|
},
|
|
66
66
|
};
|
package/dist/access.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { FileSystemMetadata } from '@zenfs/core';
|
|
2
|
+
import { FileSystem, PreloadFile, Stats } from '@zenfs/core';
|
|
3
|
+
declare global {
|
|
4
|
+
interface FileSystemDirectoryHandle {
|
|
5
|
+
[Symbol.iterator](): IterableIterator<[string, FileSystemHandle]>;
|
|
6
|
+
entries(): IterableIterator<[string, FileSystemHandle]>;
|
|
7
|
+
keys(): IterableIterator<string>;
|
|
8
|
+
values(): IterableIterator<FileSystemHandle>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export interface WebAccessOptions {
|
|
12
|
+
handle: FileSystemDirectoryHandle;
|
|
13
|
+
}
|
|
14
|
+
declare const WebAccessFS_base: (abstract new (...args: any[]) => {
|
|
15
|
+
_sync: FileSystem;
|
|
16
|
+
metadata(): FileSystemMetadata;
|
|
17
|
+
ready(): Promise<any>;
|
|
18
|
+
renameSync(oldPath: string, newPath: string, cred: import("@zenfs/core").Cred): void;
|
|
19
|
+
statSync(path: string, cred: import("@zenfs/core").Cred): Stats;
|
|
20
|
+
createFileSync(path: string, flag: string, mode: number, cred: import("@zenfs/core").Cred): import("@zenfs/core").File;
|
|
21
|
+
openFileSync(path: string, flag: string, cred: import("@zenfs/core").Cred): import("@zenfs/core").File;
|
|
22
|
+
unlinkSync(path: string, cred: import("@zenfs/core").Cred): void;
|
|
23
|
+
rmdirSync(path: string, cred: import("@zenfs/core").Cred): void;
|
|
24
|
+
mkdirSync(path: string, mode: number, cred: import("@zenfs/core").Cred): void;
|
|
25
|
+
readdirSync(path: string, cred: import("@zenfs/core").Cred): string[];
|
|
26
|
+
linkSync(srcpath: string, dstpath: string, cred: import("@zenfs/core").Cred): void;
|
|
27
|
+
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
28
|
+
rename(oldPath: string, newPath: string, cred: import("@zenfs/core").Cred): Promise<void>;
|
|
29
|
+
stat(path: string, cred: import("@zenfs/core").Cred): Promise<Stats>;
|
|
30
|
+
openFile(path: string, flag: string, cred: import("@zenfs/core").Cred): Promise<import("@zenfs/core").File>;
|
|
31
|
+
createFile(path: string, flag: string, mode: number, cred: import("@zenfs/core").Cred): Promise<import("@zenfs/core").File>;
|
|
32
|
+
unlink(path: string, cred: import("@zenfs/core").Cred): Promise<void>;
|
|
33
|
+
rmdir(path: string, cred: import("@zenfs/core").Cred): Promise<void>;
|
|
34
|
+
mkdir(path: string, mode: number, cred: import("@zenfs/core").Cred): Promise<void>;
|
|
35
|
+
readdir(path: string, cred: import("@zenfs/core").Cred): Promise<string[]>;
|
|
36
|
+
exists(path: string, cred: import("@zenfs/core").Cred): Promise<boolean>;
|
|
37
|
+
existsSync(path: string, cred: import("@zenfs/core").Cred): boolean;
|
|
38
|
+
link(srcpath: string, dstpath: string, cred: import("@zenfs/core").Cred): Promise<void>;
|
|
39
|
+
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
40
|
+
}) & typeof FileSystem;
|
|
41
|
+
export declare class WebAccessFS extends WebAccessFS_base {
|
|
42
|
+
private _handles;
|
|
43
|
+
/**
|
|
44
|
+
* @hidden
|
|
45
|
+
*/
|
|
46
|
+
_sync: FileSystem;
|
|
47
|
+
ready(): Promise<this>;
|
|
48
|
+
constructor({ handle }: WebAccessOptions);
|
|
49
|
+
metadata(): FileSystemMetadata;
|
|
50
|
+
sync(p: string, data: Uint8Array, stats: Stats): Promise<void>;
|
|
51
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
52
|
+
writeFile(fname: string, data: Uint8Array): Promise<void>;
|
|
53
|
+
createFile(path: string, flag: string): Promise<PreloadFile<this>>;
|
|
54
|
+
stat(path: string): Promise<Stats>;
|
|
55
|
+
openFile(path: string, flag: string): Promise<PreloadFile<this>>;
|
|
56
|
+
unlink(path: string): Promise<void>;
|
|
57
|
+
link(): Promise<void>;
|
|
58
|
+
rmdir(path: string): Promise<void>;
|
|
59
|
+
mkdir(path: string): Promise<void>;
|
|
60
|
+
readdir(path: string): Promise<string[]>;
|
|
61
|
+
protected getHandle(path: string): Promise<FileSystemHandle>;
|
|
62
|
+
}
|
|
63
|
+
export declare const WebAccess: {
|
|
64
|
+
readonly name: "WebAccess";
|
|
65
|
+
readonly options: {
|
|
66
|
+
readonly handle: {
|
|
67
|
+
readonly type: "object";
|
|
68
|
+
readonly required: true;
|
|
69
|
+
readonly description: "The directory handle to use for the root";
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
readonly isAvailable: () => boolean;
|
|
73
|
+
readonly create: (options: WebAccessOptions) => WebAccessFS;
|
|
74
|
+
};
|
|
75
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiError, Async, ErrorCode, FileSystem, FileType, PreloadFile, Stats } from '@zenfs/core';
|
|
1
|
+
import { ApiError, Async, ErrorCode, FileSystem, FileType, InMemory, PreloadFile, Stats } from '@zenfs/core';
|
|
2
2
|
import { basename, dirname, join } from '@zenfs/core/emulation/path.js';
|
|
3
3
|
const handleError = (path = '', syscall, error) => {
|
|
4
4
|
if (error.name === 'NotFoundError') {
|
|
@@ -6,27 +6,7 @@ const handleError = (path = '', syscall, error) => {
|
|
|
6
6
|
}
|
|
7
7
|
throw error;
|
|
8
8
|
};
|
|
9
|
-
export class
|
|
10
|
-
constructor(_fs, _path, _flag, _stat, contents) {
|
|
11
|
-
super(_fs, _path, _flag, _stat, contents);
|
|
12
|
-
}
|
|
13
|
-
syncSync() {
|
|
14
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
15
|
-
}
|
|
16
|
-
async sync() {
|
|
17
|
-
if (this.isDirty()) {
|
|
18
|
-
await this.fs.sync(this.path, this.buffer, this.stats);
|
|
19
|
-
this.resetDirty();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async close() {
|
|
23
|
-
await this.sync();
|
|
24
|
-
}
|
|
25
|
-
closeSync() {
|
|
26
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export class FileSystemAccessFS extends Async(FileSystem) {
|
|
9
|
+
export class WebAccessFS extends Async(FileSystem) {
|
|
30
10
|
async ready() {
|
|
31
11
|
return this;
|
|
32
12
|
}
|
|
@@ -34,11 +14,12 @@ export class FileSystemAccessFS extends Async(FileSystem) {
|
|
|
34
14
|
super();
|
|
35
15
|
this._handles = new Map();
|
|
36
16
|
this._handles.set('/', handle);
|
|
17
|
+
this._sync = InMemory.create({ name: 'accessfs-cache' });
|
|
37
18
|
}
|
|
38
19
|
metadata() {
|
|
39
20
|
return {
|
|
40
21
|
...super.metadata(),
|
|
41
|
-
name: '
|
|
22
|
+
name: 'WebAccess',
|
|
42
23
|
};
|
|
43
24
|
}
|
|
44
25
|
async sync(p, data, stats) {
|
|
@@ -114,7 +95,7 @@ export class FileSystemAccessFS extends Async(FileSystem) {
|
|
|
114
95
|
const file = await handle.getFile();
|
|
115
96
|
const data = new Uint8Array(await file.arrayBuffer());
|
|
116
97
|
const stats = new Stats({ mode: 0o777 | FileType.FILE, size: file.size, mtimeMs: file.lastModified });
|
|
117
|
-
return new
|
|
98
|
+
return new PreloadFile(this, path, flag, stats, data);
|
|
118
99
|
}
|
|
119
100
|
}
|
|
120
101
|
async unlink(path) {
|
|
@@ -195,8 +176,8 @@ export class FileSystemAccessFS extends Async(FileSystem) {
|
|
|
195
176
|
return await getHandleParts(pathParts);
|
|
196
177
|
}
|
|
197
178
|
}
|
|
198
|
-
export const
|
|
199
|
-
name: '
|
|
179
|
+
export const WebAccess = {
|
|
180
|
+
name: 'WebAccess',
|
|
200
181
|
options: {
|
|
201
182
|
handle: {
|
|
202
183
|
type: 'object',
|
|
@@ -208,6 +189,6 @@ export const FileSystemAccess = {
|
|
|
208
189
|
return typeof FileSystemHandle == 'function';
|
|
209
190
|
},
|
|
210
191
|
create(options) {
|
|
211
|
-
return new
|
|
192
|
+
return new WebAccessFS(options);
|
|
212
193
|
},
|
|
213
194
|
};
|
package/dist/browser.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var ZenFS_DOM=(()=>{var E=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var l=(r,e)=>E(r,"name",{value:e,configurable:!0});var R=(r,e)=>{for(var t in e)E(r,t,{get:e[t],enumerable:!0})},L=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of j(e))!q.call(r,n)&&n!==t&&E(r,n,{get:()=>e[n],enumerable:!(i=C(e,n))||i.enumerable});return r};var W=r=>L(E({},"__esModule",{value:!0}),r);var X={};R(X,{FileSystemAccess:()=>Q,FileSystemAccessFS:()=>w,FileSystemAccessFile:()=>p,IndexedDB:()=>$,IndexedDBStore:()=>m,IndexedDBTransaction:()=>I,Storage:()=>M,StorageStore:()=>x});var J=ZenFS,{ActionType:K,ApiError:c,Async:H,AsyncFile:V,AsyncFileIndexFS:ee,AsyncMirror:te,AsyncMirrorFS:re,AsyncStoreFS:k,BigIntStats:ie,BigIntStatsFs:ne,ErrorCode:d,ErrorStrings:se,File:oe,FileIndex:ae,FileIndexFS:le,FileSystem:B,FileType:D,InMemory:ce,InMemoryStore:de,IndexDirInode:fe,IndexFileInode:ue,IndexInode:me,Inode:ye,LockedFS:ge,MirrorFile:Se,Mutex:he,NoSyncFile:be,Overlay:pe,OverlayFS:we,OverlayFile:Fe,PreloadFile:O,Readonly:Ie,SimpleSyncTransaction:P,Stats:A,StatsCommon:xe,StatsFs:Ee,Sync:De,SyncFile:Ae,SyncFileIndexFS:ve,SyncStoreFS:N,SyncStoreFile:Te,UnlockedOverlayFS:He,checkOptions:ke,configure:Be,createBackend:Oe,decode:_,decodeDirListing:Pe,encode:z,encodeDirListing:Ne,flagToMode:_e,flagToNumber:ze,flagToString:$e,fs:Me,initialize:Ue,isAppendable:Ce,isBackend:je,isBackendConfig:qe,isExclusive:Re,isReadable:Le,isSynchronous:We,isTruncating:Ye,isWriteable:Ze,levenshtein:Qe,mkdirpSync:Xe,parseFlag:Ge,pathExistsAction:Je,pathNotExistsAction:Ke,randomIno:Ve,resolveBackend:et,rootCred:tt,rootIno:rt,setImmediate:it,size_max:nt,wait:st}=ZenFS;function g(r,e){if(typeof r!="string")throw new TypeError(`"${e}" is not a string`)}l(g,"validateString");function Y(r,e){let t="",i=0,n=-1,s=0,a="\0";for(let o=0;o<=r.length;++o){if(o<r.length)a=r[o];else{if(a=="/")break;a="/"}if(a=="/"){if(!(n===o-1||s===1))if(s===2){if(t.length<2||i!==2||t.at(-1)!=="."||t.at(-2)!=="."){if(t.length>2){let u=t.lastIndexOf("/");u===-1?(t="",i=0):(t=t.slice(0,u),i=t.length-1-t.lastIndexOf("/")),n=o,s=0;continue}else if(t.length!==0){t="",i=0,n=o,s=0;continue}}e&&(t+=t.length>0?"/..":"..",i=2)}else t.length>0?t+="/"+r.slice(n+1,o):t=r.slice(n+1,o),i=o-n-1;n=o,s=0}else a==="."&&s!==-1?++s:s=-1}return t}l(Y,"normalizeString");function Z(r){if(g(r,"path"),r.length===0)return".";let e=r[0]==="/",t=r.at(-1)==="/";return r=Y(r,!e),r.length===0?e?"/":t?"./":".":(t&&(r+="/"),e?`/${r}`:r)}l(Z,"normalize");function S(...r){if(r.length===0)return".";let e;for(let t=0;t<r.length;++t){let i=r[t];g(i,"path"),i.length>0&&(e===void 0?e=i:e+=`/${i}`)}return e===void 0?".":Z(e)}l(S,"join");function h(r){if(g(r,"path"),r.length===0)return".";let e=r[0]==="/",t=-1,i=!0;for(let n=r.length-1;n>=1;--n)if(r[n]==="/"){if(!i){t=n;break}}else i=!1;return t===-1?e?"/":".":e&&t===1?"//":r.slice(0,t)}l(h,"dirname");function b(r,e){e!==void 0&&g(e,"ext"),g(r,"path");let t=0,i=-1,n=!0;if(e!==void 0&&e.length>0&&e.length<=r.length){if(e===r)return"";let s=e.length-1,a=-1;for(let o=r.length-1;o>=0;--o)if(r[o]==="/"){if(!n){t=o+1;break}}else a===-1&&(n=!1,a=o+1),s>=0&&(r[o]===e[s]?--s===-1&&(i=o):(s=-1,i=a));return t===i?i=a:i===-1&&(i=r.length),r.slice(t,i)}for(let s=r.length-1;s>=0;--s)if(r[s]==="/"){if(!n){t=s+1;break}}else i===-1&&(n=!1,i=s+1);return i===-1?"":r.slice(t,i)}l(b,"basename");var v=l((r="",e,t)=>{throw t.name==="NotFoundError"?c.With("ENOENT",r,e):t},"handleError"),p=class extends O{constructor(e,t,i,n,s){super(e,t,i,n,s)}syncSync(){throw new c(d.ENOTSUP)}async sync(){this.isDirty()&&(await this.fs.sync(this.path,this.buffer,this.stats),this.resetDirty())}async close(){await this.sync()}closeSync(){throw new c(d.ENOTSUP)}};l(p,"FileSystemAccessFile");var w=class extends H(B){_handles=new Map;async ready(){return this}constructor({handle:e}){super(),this._handles.set("/",e)}metadata(){return{...super.metadata(),name:"FileSystemAccess"}}async sync(e,t,i){let n=await this.stat(e);i.mtime!==n.mtime&&await this.writeFile(e,t)}async rename(e,t){try{let i=await this.getHandle(e);if(i instanceof FileSystemDirectoryHandle){let y=await this.readdir(e);if(await this.mkdir(t),y.length==0)await this.unlink(e);else for(let f of y)await this.rename(S(e,f),S(t,f)),await this.unlink(e)}if(!(i instanceof FileSystemFileHandle))return;let n=await i.getFile(),s=await this.getHandle(h(t));if(!(s instanceof FileSystemDirectoryHandle))return;let o=await(await s.getFileHandle(b(t),{create:!0})).createWritable(),u=await n.arrayBuffer();await o.write(u),o.close(),await this.unlink(e)}catch(i){v(e,"rename",i)}}async writeFile(e,t){let i=await this.getHandle(h(e));if(!(i instanceof FileSystemDirectoryHandle))return;let s=await(await i.getFileHandle(b(e),{create:!0})).createWritable();await s.write(t),await s.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 c.With("ENOENT",e,"stat");if(t instanceof FileSystemDirectoryHandle)return new A({mode:511|D.DIRECTORY,size:4096});if(t instanceof FileSystemFileHandle){let{lastModified:i,size:n}=await t.getFile();return new A({mode:511|D.FILE,size:n,mtimeMs:i})}}async openFile(e,t){let i=await this.getHandle(e);if(i instanceof FileSystemFileHandle){let n=await i.getFile(),s=new Uint8Array(await n.arrayBuffer()),a=new A({mode:511|D.FILE,size:n.size,mtimeMs:n.lastModified});return new p(this,e,t,a,s)}}async unlink(e){let t=await this.getHandle(h(e));if(t instanceof FileSystemDirectoryHandle)try{await t.removeEntry(b(e),{recursive:!0})}catch(i){v(e,"unlink",i)}}async link(){throw new c(d.ENOTSUP)}async rmdir(e){return this.unlink(e)}async mkdir(e){if(await this.getHandle(e))throw c.With("EEXIST",e,"mkdir");let i=await this.getHandle(h(e));i instanceof FileSystemDirectoryHandle&&await i.getDirectoryHandle(b(e),{create:!0})}async readdir(e){let t=await this.getHandle(e);if(!(t instanceof FileSystemDirectoryHandle))throw c.With("ENOTDIR",e,"readdir");let i=[];for await(let n of t.keys())i.push(S(e,n));return i}async getHandle(e){if(this._handles.has(e))return this._handles.get(e);let t="/",[,...i]=e.split("/"),n=l(async([s,...a])=>{let o=S(t,s),u=l(f=>{if(t=o,this._handles.set(t,f),a.length===0)return this._handles.get(e);n(a)},"continueWalk"),y=this._handles.get(t);try{return u(await y.getDirectoryHandle(s))}catch(f){if(f.name==="TypeMismatchError")try{return u(await y.getFileHandle(s))}catch(U){v(o,"getHandle",U)}else{if(f.message==="Name is not allowed.")throw new c(d.ENOENT,f.message,o);v(o,"getHandle",f)}}},"getHandleParts");return await n(i)}};l(w,"FileSystemAccessFS");var Q={name:"FileSystemAccess",options:{handle:{type:"object",required:!0,description:"The directory handle to use for the root"}},isAvailable(){return typeof FileSystemHandle=="function"},create(r){return new w(r)}};function F(r,e=r.toString()){switch(r.name){case"NotFoundError":return new c(d.ENOENT,e);case"QuotaExceededError":return new c(d.ENOSPC,e);default:return new c(d.EIO,e)}}l(F,"convertError");function T(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=i=>{i.preventDefault(),t(new c(d.EIO))}})}l(T,"wrap");var I=class{constructor(e,t){this.tx=e;this.store=t}async get(e){try{return await T(this.store.get(e.toString()))}catch(t){throw F(t)}}async put(e,t,i){try{return await T(i?this.store.put(t,e.toString()):this.store.add(t,e.toString())),!0}catch(n){throw F(n)}}async remove(e){try{await T(this.store.delete(e.toString()))}catch(t){throw F(t)}}async commit(){}async abort(){try{this.tx.abort()}catch(e){throw F(e)}}};l(I,"IndexedDBTransaction");var m=class{constructor(e,t){this.db=e;this.storeName=t}static create(e,t){return new Promise((i,n)=>{let s=t.open(e,1);s.onupgradeneeded=()=>{let a=s.result;a.objectStoreNames.contains(e)&&a.deleteObjectStore(e),a.createObjectStore(e)},s.onsuccess=()=>i(new m(s.result,e)),s.onerror=a=>{a.preventDefault(),n(new c(d.EACCES))}})}get name(){return $.name+":"+this.storeName}clear(){return new Promise((e,t)=>{try{let i=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).clear();i.onsuccess=()=>e(),i.onerror=n=>{n.preventDefault(),t(new c(d.EIO))}}catch(i){t(F(i))}})}beginTransaction(){let e=this.db.transaction(this.storeName,"readwrite"),t=e.objectStore(this.storeName);return new I(e,t)}};l(m,"IndexedDBStore");var $={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."}},isAvailable(r=globalThis.indexedDB){try{if(!(r instanceof IDBFactory))return!1;let e=r.open("__zenfs_test");if(!e)return!1;e.onsuccess=()=>r.deleteDatabase("__zenfs_test")}catch{return!1}return!0},create({cacheSize:r=100,storeName:e="zenfs",idbFactory:t=globalThis.indexedDB}){let i=m.create(e,t);return new k({cacheSize:r,store:i})}};var x=class{constructor(e){this._storage=e}get name(){return M.name}clear(){this._storage.clear()}beginTransaction(){return new P(this)}get(e){let t=this._storage.getItem(e.toString());if(typeof t=="string")return z(t)}put(e,t,i){try{return!i&&this._storage.getItem(e.toString())!==null?!1:(this._storage.setItem(e.toString(),_(t)),!0)}catch{throw new c(d.ENOSPC,"Storage is full.")}}remove(e){try{this._storage.removeItem(e.toString())}catch(t){throw new c(d.EIO,"Unable to delete key "+e+": "+t)}}};l(x,"StorageStore");var M={name:"Storage",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 x(r)})}};return W(X);})();
|
|
1
|
+
var ZenFS_DOM=(()=>{var D=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var a=(n,e)=>D(n,"name",{value:e,configurable:!0});var j=(n,e)=>{for(var t in e)D(n,t,{get:e[t],enumerable:!0})},q=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of U(e))!R.call(n,i)&&i!==t&&D(n,i,{get:()=>e[i],enumerable:!(r=C(e,i))||r.enumerable});return n};var L=n=>q(D({},"__esModule",{value:!0}),n);var X={};j(X,{IndexedDB:()=>z,IndexedDBStore:()=>m,IndexedDBTransaction:()=>I,WebAccess:()=>Q,WebAccessFS:()=>w,WebStorage:()=>M,WebStorageStore:()=>x});var J=ZenFS,{ActionType:K,ApiError:c,Async:A,AsyncFileIndexFS:V,AsyncStoreFS:T,BigIntStats:ee,BigIntStatsFs:te,Dir:ne,Dirent:re,ErrorCode:d,ErrorStrings:ie,File:se,FileIndex:oe,FileIndexFS:ae,FileSystem:H,FileType:E,InMemory:B,InMemoryStore:le,IndexDirInode:ce,IndexFileInode:de,IndexInode:fe,Inode:ue,LockedFS:me,Mutex:ye,NoSyncFile:Se,Overlay:ge,OverlayFS:he,PreloadFile:O,ReadStream:pe,Readonly:we,SimpleSyncTransaction:_,Stats:k,StatsCommon:be,StatsFs:Fe,Sync:Ie,SyncFileIndexFS:xe,SyncStoreFS:N,UnlockedOverlayFS:De,WriteStream:Ee,_toUnixTimestamp:ke,access:ve,accessSync:Ae,appendFile:Te,appendFileSync:He,checkOptions:Be,chmod:Oe,chmodSync:_e,chown:Ne,chownSync:Pe,close:$e,closeSync:ze,configure:Me,constants:We,copyFile:Ce,copyFileSync:Ue,cp:Re,cpSync:je,createBackend:qe,createReadStream:Le,createWriteStream:Ye,decode:P,decodeDirListing:Ze,encode:$,encodeDirListing:Qe,exists:Xe,existsSync:Ge,fchmod:Je,fchmodSync:Ke,fchown:Ve,fchownSync:et,fdatasync:tt,fdatasyncSync:nt,flagToMode:rt,flagToNumber:it,flagToString:st,fs:ot,fstat:at,fstatSync:lt,fsync:ct,fsyncSync:dt,ftruncate:ft,ftruncateSync:ut,futimes:mt,futimesSync:yt,isAppendable:St,isBackend:gt,isBackendConfig:ht,isExclusive:pt,isReadable:wt,isSynchronous:bt,isTruncating:Ft,isWriteable:It,lchmod:xt,lchmodSync:Dt,lchown:Et,lchownSync:kt,levenshtein:vt,link:At,linkSync:Tt,lopenSync:Ht,lstat:Bt,lstatSync:Ot,lutimes:_t,lutimesSync:Nt,mkdir:Pt,mkdirSync:$t,mkdirpSync:zt,mkdtemp:Mt,mkdtempSync:Wt,mount:Ct,mountMapping:Ut,mounts:Rt,open:jt,openAsBlob:qt,openSync:Lt,opendir:Yt,opendirSync:Zt,parseFlag:Qt,pathExistsAction:Xt,pathNotExistsAction:Gt,promises:Jt,randomIno:Kt,read:Vt,readFile:en,readFileSync:tn,readSync:nn,readdir:rn,readdirSync:sn,readlink:on,readlinkSync:an,readv:ln,readvSync:cn,realpath:dn,realpathSync:fn,rename:un,renameSync:mn,resolveMountConfig:yn,rm:Sn,rmSync:gn,rmdir:hn,rmdirSync:pn,rootCred:wn,rootIno:bn,setImmediate:Fn,size_max:In,stat:xn,statSync:Dn,statfs:En,statfsSync:kn,symlink:vn,symlinkSync:An,truncate:Tn,truncateSync:Hn,umount:Bn,unlink:On,unlinkSync:_n,unwatchFile:Nn,utimes:Pn,utimesSync:$n,wait:zn,watch:Mn,watchFile:Wn,write:Cn,writeFile:Un,writeFileSync:Rn,writeSync:jn,writev:qn,writevSync:Ln}=ZenFS;function S(n,e){if(typeof n!="string")throw new TypeError(`"${e}" is not a string`)}a(S,"validateString");function Y(n,e){let t="",r=0,i=-1,s=0,l="\0";for(let o=0;o<=n.length;++o){if(o<n.length)l=n[o];else{if(l=="/")break;l="/"}if(l=="/"){if(!(i===o-1||s===1))if(s===2){if(t.length<2||r!==2||t.at(-1)!=="."||t.at(-2)!=="."){if(t.length>2){let u=t.lastIndexOf("/");u===-1?(t="",r=0):(t=t.slice(0,u),r=t.length-1-t.lastIndexOf("/")),i=o,s=0;continue}else if(t.length!==0){t="",r=0,i=o,s=0;continue}}e&&(t+=t.length>0?"/..":"..",r=2)}else t.length>0?t+="/"+n.slice(i+1,o):t=n.slice(i+1,o),r=o-i-1;i=o,s=0}else l==="."&&s!==-1?++s:s=-1}return t}a(Y,"normalizeString");function Z(n){if(S(n,"path"),n.length===0)return".";let e=n[0]==="/",t=n.at(-1)==="/";return n=Y(n,!e),n.length===0?e?"/":t?"./":".":(t&&(n+="/"),e?`/${n}`:n)}a(Z,"normalize");function g(...n){if(n.length===0)return".";let e;for(let t=0;t<n.length;++t){let r=n[t];S(r,"path"),r.length>0&&(e===void 0?e=r:e+=`/${r}`)}return e===void 0?".":Z(e)}a(g,"join");function h(n){if(S(n,"path"),n.length===0)return".";let e=n[0]==="/",t=-1,r=!0;for(let i=n.length-1;i>=1;--i)if(n[i]==="/"){if(!r){t=i;break}}else r=!1;return t===-1?e?"/":".":e&&t===1?"//":n.slice(0,t)}a(h,"dirname");function p(n,e){e!==void 0&&S(e,"ext"),S(n,"path");let t=0,r=-1,i=!0;if(e!==void 0&&e.length>0&&e.length<=n.length){if(e===n)return"";let s=e.length-1,l=-1;for(let o=n.length-1;o>=0;--o)if(n[o]==="/"){if(!i){t=o+1;break}}else l===-1&&(i=!1,l=o+1),s>=0&&(n[o]===e[s]?--s===-1&&(r=o):(s=-1,r=l));return t===r?r=l:r===-1&&(r=n.length),n.slice(t,r)}for(let s=n.length-1;s>=0;--s)if(n[s]==="/"){if(!i){t=s+1;break}}else r===-1&&(i=!1,r=s+1);return r===-1?"":n.slice(t,r)}a(p,"basename");var v=a((n="",e,t)=>{throw t.name==="NotFoundError"?c.With("ENOENT",n,e):t},"handleError"),w=class extends A(H){_handles=new Map;_sync;async ready(){return this}constructor({handle:e}){super(),this._handles.set("/",e),this._sync=B.create({name:"accessfs-cache"})}metadata(){return{...super.metadata(),name:"WebAccess"}}async sync(e,t,r){let i=await this.stat(e);r.mtime!==i.mtime&&await this.writeFile(e,t)}async rename(e,t){try{let r=await this.getHandle(e);if(r instanceof FileSystemDirectoryHandle){let y=await this.readdir(e);if(await this.mkdir(t),y.length==0)await this.unlink(e);else for(let f of y)await this.rename(g(e,f),g(t,f)),await this.unlink(e)}if(!(r instanceof FileSystemFileHandle))return;let i=await r.getFile(),s=await this.getHandle(h(t));if(!(s instanceof FileSystemDirectoryHandle))return;let o=await(await s.getFileHandle(p(t),{create:!0})).createWritable(),u=await i.arrayBuffer();await o.write(u),o.close(),await this.unlink(e)}catch(r){v(e,"rename",r)}}async writeFile(e,t){let r=await this.getHandle(h(e));if(!(r instanceof FileSystemDirectoryHandle))return;let s=await(await r.getFileHandle(p(e),{create:!0})).createWritable();await s.write(t),await s.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 c.With("ENOENT",e,"stat");if(t instanceof FileSystemDirectoryHandle)return new k({mode:511|E.DIRECTORY,size:4096});if(t instanceof FileSystemFileHandle){let{lastModified:r,size:i}=await t.getFile();return new k({mode:511|E.FILE,size:i,mtimeMs:r})}}async openFile(e,t){let r=await this.getHandle(e);if(r instanceof FileSystemFileHandle){let i=await r.getFile(),s=new Uint8Array(await i.arrayBuffer()),l=new k({mode:511|E.FILE,size:i.size,mtimeMs:i.lastModified});return new O(this,e,t,l,s)}}async unlink(e){let t=await this.getHandle(h(e));if(t instanceof FileSystemDirectoryHandle)try{await t.removeEntry(p(e),{recursive:!0})}catch(r){v(e,"unlink",r)}}async link(){throw new c(d.ENOTSUP)}async rmdir(e){return this.unlink(e)}async mkdir(e){if(await this.getHandle(e))throw c.With("EEXIST",e,"mkdir");let r=await this.getHandle(h(e));r instanceof FileSystemDirectoryHandle&&await r.getDirectoryHandle(p(e),{create:!0})}async readdir(e){let t=await this.getHandle(e);if(!(t instanceof FileSystemDirectoryHandle))throw c.With("ENOTDIR",e,"readdir");let r=[];for await(let i of t.keys())r.push(g(e,i));return r}async getHandle(e){if(this._handles.has(e))return this._handles.get(e);let t="/",[,...r]=e.split("/"),i=a(async([s,...l])=>{let o=g(t,s),u=a(f=>{if(t=o,this._handles.set(t,f),l.length===0)return this._handles.get(e);i(l)},"continueWalk"),y=this._handles.get(t);try{return u(await y.getDirectoryHandle(s))}catch(f){if(f.name==="TypeMismatchError")try{return u(await y.getFileHandle(s))}catch(W){v(o,"getHandle",W)}else{if(f.message==="Name is not allowed.")throw new c(d.ENOENT,f.message,o);v(o,"getHandle",f)}}},"getHandleParts");return await i(r)}};a(w,"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(n){return new w(n)}};function b(n,e=n.toString()){switch(n.name){case"NotFoundError":return new c(d.ENOENT,e);case"QuotaExceededError":return new c(d.ENOSPC,e);default:return new c(d.EIO,e)}}a(b,"convertError");function F(n){return new Promise((e,t)=>{n.onsuccess=()=>e(n.result),n.onerror=r=>{r.preventDefault(),t(new c(d.EIO))}})}a(F,"wrap");var I=class{constructor(e,t){this.tx=e;this.store=t}async get(e){try{return await F(this.store.get(e.toString()))}catch(t){throw b(t)}}async put(e,t,r){try{return await F(r?this.store.put(t,e.toString()):this.store.add(t,e.toString())),!0}catch(i){throw b(i)}}async remove(e){try{await F(this.store.delete(e.toString()))}catch(t){throw b(t)}}async commit(){}async abort(){try{this.tx.abort()}catch(e){throw b(e)}}};a(I,"IndexedDBTransaction");var m=class{constructor(e,t){this.db=e;this.storeName=t}static async create(e,t){let r=t.open(e,1);r.onupgradeneeded=()=>{let s=r.result;s.objectStoreNames.contains(e)&&s.deleteObjectStore(e),s.createObjectStore(e)};let i=await F(r);return new m(i,e)}get name(){return z.name+":"+this.storeName}clear(){return new Promise((e,t)=>{try{let r=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).clear();r.onsuccess=()=>e(),r.onerror=i=>{i.preventDefault(),t(new c(d.EIO))}}catch(r){t(b(r))}})}beginTransaction(){let e=this.db.transaction(this.storeName,"readwrite"),t=e.objectStore(this.storeName);return new I(e,t)}};a(m,"IndexedDBStore");var z={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(n=globalThis.indexedDB){try{if(!(n instanceof IDBFactory))return!1;let e=n.open("__zenfs_test");return await F(e),n.deleteDatabase("__zenfs_test"),!0}catch{return n.deleteDatabase("__zenfs_test"),!1}},create({lruCacheSize:n=100,storeName:e="zenfs",idbFactory:t=globalThis.indexedDB}){let r=m.create(e,t);return new T({lruCacheSize:n,store:r})}};var x=class{constructor(e){this._storage=e}get name(){return M.name}clear(){this._storage.clear()}beginTransaction(){return new _(this)}get(e){let t=this._storage.getItem(e.toString());if(typeof t=="string")return $(t)}put(e,t,r){try{return!r&&this._storage.getItem(e.toString())!==null?!1:(this._storage.setItem(e.toString(),P(t)),!0)}catch{throw new c(d.ENOSPC,"Storage is full.")}}remove(e){try{this._storage.removeItem(e.toString())}catch(t){throw new c(d.EIO,"Unable to delete key "+e+": "+t)}}};a(x,"WebStorageStore");var M={name:"WebStorage",options:{storage:{type:"object",required:!1,description:"The Storage to use. Defaults to globalThis.localStorage."}},isAvailable(n=globalThis.localStorage){return n instanceof globalThis.Storage},create({storage:n=globalThis.localStorage}){return new N({store:new x(n)})}};return L(X);})();
|
|
2
2
|
//# sourceMappingURL=browser.min.js.map
|
package/dist/browser.min.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "global-externals:@zenfs/core", "../node_modules/@zenfs/core/dist/emulation/path.js", "../src/
|
|
4
|
-
"sourcesContent": ["export * from './FileSystemAccess.js';\nexport * from './IndexedDB.js';\nexport * from './Storage.js';\n", "export default ZenFS;\nconst { ActionType, ApiError, Async, AsyncFile, AsyncFileIndexFS, AsyncMirror, AsyncMirrorFS, AsyncStoreFS, BigIntStats, BigIntStatsFs, ErrorCode, ErrorStrings, File, FileIndex, FileIndexFS, FileSystem, FileType, InMemory, InMemoryStore, IndexDirInode, IndexFileInode, IndexInode, Inode, LockedFS, MirrorFile, Mutex, NoSyncFile, Overlay, OverlayFS, OverlayFile, PreloadFile, Readonly, SimpleSyncTransaction, Stats, StatsCommon, StatsFs, Sync, SyncFile, SyncFileIndexFS, SyncStoreFS, SyncStoreFile, UnlockedOverlayFS, checkOptions, configure, createBackend, decode, decodeDirListing, encode, encodeDirListing, flagToMode, flagToNumber, flagToString, fs, initialize, isAppendable, isBackend, isBackendConfig, isExclusive, isReadable, isSynchronous, isTruncating, isWriteable, levenshtein, mkdirpSync, parseFlag, pathExistsAction, pathNotExistsAction, randomIno, resolveBackend, rootCred, rootIno, setImmediate, size_max, wait } = ZenFS;\nexport { ActionType, ApiError, Async, AsyncFile, AsyncFileIndexFS, AsyncMirror, AsyncMirrorFS, AsyncStoreFS, BigIntStats, BigIntStatsFs, ErrorCode, ErrorStrings, File, FileIndex, FileIndexFS, FileSystem, FileType, InMemory, InMemoryStore, IndexDirInode, IndexFileInode, IndexInode, Inode, LockedFS, MirrorFile, Mutex, NoSyncFile, Overlay, OverlayFS, OverlayFile, PreloadFile, Readonly, SimpleSyncTransaction, Stats, StatsCommon, StatsFs, Sync, SyncFile, SyncFileIndexFS, SyncStoreFS, SyncStoreFile, UnlockedOverlayFS, checkOptions, configure, createBackend, decode, decodeDirListing, encode, encodeDirListing, flagToMode, flagToNumber, flagToString, fs, initialize, isAppendable, isBackend, isBackendConfig, isExclusive, isReadable, isSynchronous, isTruncating, isWriteable, levenshtein, mkdirpSync, parseFlag, pathExistsAction, pathNotExistsAction, randomIno, resolveBackend, rootCred, rootIno, setImmediate, size_max, wait };", "/*\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 const cwd = '/';\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 resolvedPath = '';\n let resolvedAbsolute = false;\n for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {\n const path = i >= 0 ? args[i] : cwd;\n validateString(path, `paths[${i}]`);\n // Skip empty entries\n if (path.length === 0) {\n continue;\n }\n resolvedPath = `${path}/${resolvedPath}`;\n resolvedAbsolute = 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 process.cwd() fails)\n // Normalize the path\n resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);\n if (resolvedAbsolute) {\n return `/${resolvedPath}`;\n }\n return resolvedPath.length > 0 ? resolvedPath : '.';\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 type { Backend, FileSystemMetadata } from '@zenfs/core';\nimport { ApiError, Async, ErrorCode, FileSystem, FileType, PreloadFile, Stats } from '@zenfs/core';\nimport { basename, dirname, join } from '@zenfs/core/emulation/path.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 FileSystemAccessOptions {\n\thandle: FileSystemDirectoryHandle;\n}\n\nconst handleError = (path = '', syscall: string, error: Error) => {\n\tif (error.name === 'NotFoundError') {\n\t\tthrow ApiError.With('ENOENT', path, syscall);\n\t}\n\n\tthrow error as ApiError;\n};\n\nexport class FileSystemAccessFile extends PreloadFile<FileSystemAccessFS> {\n\tconstructor(_fs: FileSystemAccessFS, _path: string, _flag: string, _stat: Stats, contents?: Uint8Array) {\n\t\tsuper(_fs, _path, _flag, _stat, contents);\n\t}\n\n\tpublic syncSync(): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\n\tpublic async sync(): Promise<void> {\n\t\tif (this.isDirty()) {\n\t\t\tawait this.fs.sync(this.path, this.buffer, this.stats);\n\t\t\tthis.resetDirty();\n\t\t}\n\t}\n\n\tpublic async close(): Promise<void> {\n\t\tawait this.sync();\n\t}\n\n\tpublic closeSync(): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n}\n\nexport class FileSystemAccessFS extends Async(FileSystem) {\n\tprivate _handles: Map<string, FileSystemHandle> = new Map();\n\n\tpublic async ready(): Promise<this> {\n\t\treturn this;\n\t}\n\n\tpublic constructor({ handle }: FileSystemAccessOptions) {\n\t\tsuper();\n\t\tthis._handles.set('/', handle);\n\t}\n\n\tpublic metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\t...super.metadata(),\n\t\t\tname: 'FileSystemAccess',\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\tconst buffer = await oldFile.arrayBuffer();\n\t\t\tawait writable.write(buffer);\n\n\t\t\twritable.close();\n\t\t\tawait this.unlink(oldPath);\n\t\t} catch (err) {\n\t\t\thandleError(oldPath, 'rename', err);\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<FileSystemAccessFile> {\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}\n\n\tpublic async openFile(path: string, flag: string): Promise<FileSystemAccessFile> {\n\t\tconst handle = await this.getHandle(path);\n\t\tif (handle instanceof FileSystemFileHandle) {\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 FileSystemAccessFile(this, path, flag, stats, data);\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 (e) {\n\t\t\t\thandleError(path, 'unlink', e);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async link(): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\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\tawait handle.getDirectoryHandle(basename(path), { create: true });\n\t\t}\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 walkedPath = '/';\n\t\tconst [, ...pathParts] = path.split('/');\n\t\tconst getHandleParts = async ([pathPart, ...remainingPathParts]: string[]) => {\n\t\t\tconst walkingPath = join(walkedPath, pathPart);\n\t\t\tconst continueWalk = (handle: FileSystemHandle) => {\n\t\t\t\twalkedPath = walkingPath;\n\t\t\t\tthis._handles.set(walkedPath, handle);\n\n\t\t\t\tif (remainingPathParts.length === 0) {\n\t\t\t\t\treturn this._handles.get(path);\n\t\t\t\t}\n\n\t\t\t\tgetHandleParts(remainingPathParts);\n\t\t\t};\n\t\t\tconst handle = this._handles.get(walkedPath) as FileSystemDirectoryHandle;\n\n\t\t\ttry {\n\t\t\t\treturn continueWalk(await handle.getDirectoryHandle(pathPart));\n\t\t\t} catch (error) {\n\t\t\t\tif (error.name === 'TypeMismatchError') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn continueWalk(await handle.getFileHandle(pathPart));\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\thandleError(walkingPath, 'getHandle', err);\n\t\t\t\t\t}\n\t\t\t\t} else if (error.message === 'Name is not allowed.') {\n\t\t\t\t\tthrow new ApiError(ErrorCode.ENOENT, error.message, walkingPath);\n\t\t\t\t} else {\n\t\t\t\t\thandleError(walkingPath, 'getHandle', error);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\treturn await getHandleParts(pathParts);\n\t}\n}\n\nexport const FileSystemAccess: Backend<FileSystemAccessFS> = {\n\tname: 'FileSystemAccess',\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: FileSystemAccessOptions) {\n\t\treturn new FileSystemAccessFS(options);\n\t},\n};\n", "import type { Backend, Ino } from '@zenfs/core';\nimport { AsyncTransaction, AsyncStore, AsyncStoreFS, ApiError, ErrorCode } from '@zenfs/core';\n\n/**\n * Converts a DOMException or a DOMError from an IndexedDB event into a\n * standardized ZenFS API error.\n * @hidden\n */\nfunction convertError(e: { name: string }, message: string = e.toString()): ApiError {\n\tswitch (e.name) {\n\t\tcase 'NotFoundError':\n\t\t\treturn new ApiError(ErrorCode.ENOENT, message);\n\t\tcase 'QuotaExceededError':\n\t\t\treturn new ApiError(ErrorCode.ENOSPC, message);\n\t\tdefault:\n\t\t\t// The rest do not seem to map cleanly to standard error codes.\n\t\t\treturn new ApiError(ErrorCode.EIO, message);\n\t}\n}\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(new ApiError(ErrorCode.EIO));\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 async get(key: Ino): Promise<Uint8Array> {\n\t\ttry {\n\t\t\treturn await wrap<Uint8Array>(this.store.get(key.toString()));\n\t\t} catch (e) {\n\t\t\tthrow convertError(e);\n\t\t}\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\ttry {\n\t\t\tawait wrap(overwrite ? this.store.put(data, key.toString()) : this.store.add(data, key.toString()));\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\tthrow convertError(e);\n\t\t}\n\t}\n\n\tpublic async remove(key: Ino): Promise<void> {\n\t\ttry {\n\t\t\tawait wrap(this.store.delete(key.toString()));\n\t\t} catch (e) {\n\t\t\tthrow convertError(e);\n\t\t}\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 convertError(e);\n\t\t}\n\t}\n}\n\nexport class IndexedDBStore implements AsyncStore {\n\tpublic static create(storeName: string, indexedDB: IDBFactory): Promise<IndexedDBStore> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst req: IDBOpenDBRequest = indexedDB.open(storeName, 1);\n\n\t\t\treq.onupgradeneeded = () => {\n\t\t\t\tconst db: IDBDatabase = req.result;\n\t\t\t\t// This should never happen; we're at version 1. Why does another database exist?\n\t\t\t\tif (db.objectStoreNames.contains(storeName)) {\n\t\t\t\t\tdb.deleteObjectStore(storeName);\n\t\t\t\t}\n\t\t\t\tdb.createObjectStore(storeName);\n\t\t\t};\n\n\t\t\treq.onsuccess = () => resolve(new IndexedDBStore(req.result, storeName));\n\n\t\t\treq.onerror = e => {\n\t\t\t\te.preventDefault();\n\t\t\t\treject(new ApiError(ErrorCode.EACCES));\n\t\t\t};\n\t\t});\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 new Promise((resolve, reject) => {\n\t\t\ttry {\n\t\t\t\tconst req: IDBRequest = this.db.transaction(this.storeName, 'readwrite').objectStore(this.storeName).clear();\n\t\t\t\treq.onsuccess = () => resolve();\n\t\t\t\treq.onerror = e => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\treject(new ApiError(ErrorCode.EIO));\n\t\t\t\t};\n\t\t\t} catch (e) {\n\t\t\t\treject(convertError(e));\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic beginTransaction(): IndexedDBTransaction {\n\t\tconst tx = this.db.transaction(this.storeName, 'readwrite'),\n\t\t\tobjectStore = tx.objectStore(this.storeName);\n\t\treturn new IndexedDBTransaction(tx, objectStore);\n\t}\n}\n\n/**\n * Configuration options for the IndexedDB file system.\n */\nexport interface IndexedDBOptions {\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 size of the inode cache. Defaults to 100. A size of 0 or below disables caching.\n\t */\n\tcacheSize?: number;\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: Backend<AsyncStoreFS> = {\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\tisAvailable(idbFactory: IDBFactory = globalThis.indexedDB): 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\tif (!req) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treq.onsuccess = () => idbFactory.deleteDatabase('__zenfs_test');\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t},\n\n\tcreate({ cacheSize = 100, storeName = 'zenfs', idbFactory = globalThis.indexedDB }: IndexedDBOptions) {\n\t\tconst store = IndexedDBStore.create(storeName, idbFactory);\n\t\tconst fs = new AsyncStoreFS({ cacheSize, store });\n\t\treturn fs;\n\t},\n};\n", "import type { Backend, Ino } from '@zenfs/core';\nimport { SyncStore, SimpleSyncStore, SimpleSyncTransaction, SyncStoreFS, ApiError, ErrorCode, encode, decode } from '@zenfs/core';\n\n/**\n * A synchronous key-value store backed by Storage.\n */\nexport class StorageStore implements SyncStore, SimpleSyncStore {\n\tpublic get name(): string {\n\t\treturn Storage.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 StorageOptions {\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 Storage: Backend<SyncStoreFS> = {\n\tname: 'Storage',\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 }: StorageOptions) {\n\t\treturn new SyncStoreFS({ store: new StorageStore(storage) });\n\t},\n};\n"],
|
|
5
|
-
"mappings": "meAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,EAAA,uBAAAC,EAAA,yBAAAC,EAAA,cAAAC,EAAA,mBAAAC,EAAA,yBAAAC,EAAA,YAAAC,EAAA,iBAAAC,ICAA,IAAOC,EAAQ,MACT,CAAE,WAAAC,EAAY,SAAAC,EAAU,MAAAC,EAAO,UAAAC,EAAW,iBAAAC,GAAkB,YAAAC,GAAa,cAAAC,GAAe,aAAAC,EAAc,YAAAC,GAAa,cAAAC,GAAe,UAAAC,EAAW,aAAAC,GAAc,KAAAC,GAAM,UAAAC,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mB,CAC7D,OAAO,IAAIC,EAAY,CAAE,MAAO,IAAId,EAAaa,CAAO,CAAE,CAAC,CAC5D,CACD",
|
|
6
|
-
"names": ["src_exports", "__export", "
|
|
3
|
+
"sources": ["../src/index.ts", "global-externals:@zenfs/core", "../node_modules/@zenfs/core/dist/emulation/path.js", "../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, AsyncFileIndexFS, AsyncStoreFS, BigIntStats, BigIntStatsFs, Dir, Dirent, ErrorCode, ErrorStrings, File, FileIndex, FileIndexFS, FileSystem, FileType, InMemory, InMemoryStore, IndexDirInode, IndexFileInode, IndexInode, Inode, LockedFS, Mutex, NoSyncFile, Overlay, OverlayFS, PreloadFile, ReadStream, Readonly, SimpleSyncTransaction, Stats, StatsCommon, StatsFs, Sync, SyncFileIndexFS, 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, 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, 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, wait, watch, watchFile, write, writeFile, writeFileSync, writeSync, writev, writevSync } = ZenFS;\nexport { ActionType, ApiError, Async, AsyncFileIndexFS, AsyncStoreFS, BigIntStats, BigIntStatsFs, Dir, Dirent, ErrorCode, ErrorStrings, File, FileIndex, FileIndexFS, FileSystem, FileType, InMemory, InMemoryStore, IndexDirInode, IndexFileInode, IndexInode, Inode, LockedFS, Mutex, NoSyncFile, Overlay, OverlayFS, PreloadFile, ReadStream, Readonly, SimpleSyncTransaction, Stats, StatsCommon, StatsFs, Sync, SyncFileIndexFS, 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, 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, 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, wait, 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 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';\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\nconst handleError = (path = '', syscall: string, error: Error) => {\n\tif (error.name === 'NotFoundError') {\n\t\tthrow ApiError.With('ENOENT', path, syscall);\n\t}\n\n\tthrow error as ApiError;\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 async ready(): Promise<this> {\n\t\treturn this;\n\t}\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\tconst buffer = await oldFile.arrayBuffer();\n\t\t\tawait writable.write(buffer);\n\n\t\t\twritable.close();\n\t\t\tawait this.unlink(oldPath);\n\t\t} catch (err) {\n\t\t\thandleError(oldPath, 'rename', err);\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}\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\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}\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 (e) {\n\t\t\t\thandleError(path, 'unlink', e);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async link(): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\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\tawait handle.getDirectoryHandle(basename(path), { create: true });\n\t\t}\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 walkedPath = '/';\n\t\tconst [, ...pathParts] = path.split('/');\n\t\tconst getHandleParts = async ([pathPart, ...remainingPathParts]: string[]) => {\n\t\t\tconst walkingPath = join(walkedPath, pathPart);\n\t\t\tconst continueWalk = (handle: FileSystemHandle) => {\n\t\t\t\twalkedPath = walkingPath;\n\t\t\t\tthis._handles.set(walkedPath, handle);\n\n\t\t\t\tif (remainingPathParts.length === 0) {\n\t\t\t\t\treturn this._handles.get(path);\n\t\t\t\t}\n\n\t\t\t\tgetHandleParts(remainingPathParts);\n\t\t\t};\n\t\t\tconst handle = this._handles.get(walkedPath) as FileSystemDirectoryHandle;\n\n\t\t\ttry {\n\t\t\t\treturn continueWalk(await handle.getDirectoryHandle(pathPart));\n\t\t\t} catch (error) {\n\t\t\t\tif (error.name === 'TypeMismatchError') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn continueWalk(await handle.getFileHandle(pathPart));\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\thandleError(walkingPath, 'getHandle', err);\n\t\t\t\t\t}\n\t\t\t\t} else if (error.message === 'Name is not allowed.') {\n\t\t\t\t\tthrow new ApiError(ErrorCode.ENOENT, error.message, walkingPath);\n\t\t\t\t} else {\n\t\t\t\t\thandleError(walkingPath, 'getHandle', error);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\treturn await getHandleParts(pathParts);\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 { AsyncStoreOptions, Backend, Ino } from '@zenfs/core';\nimport { AsyncTransaction, AsyncStore, AsyncStoreFS, ApiError, ErrorCode } from '@zenfs/core';\n\n/**\n * Converts a DOMException or a DOMError from an IndexedDB event into a\n * standardized ZenFS API error.\n * @hidden\n */\nfunction convertError(e: { name: string }, message: string = e.toString()): ApiError {\n\tswitch (e.name) {\n\t\tcase 'NotFoundError':\n\t\t\treturn new ApiError(ErrorCode.ENOENT, message);\n\t\tcase 'QuotaExceededError':\n\t\t\treturn new ApiError(ErrorCode.ENOSPC, message);\n\t\tdefault:\n\t\t\t// The rest do not seem to map cleanly to standard error codes.\n\t\t\treturn new ApiError(ErrorCode.EIO, message);\n\t}\n}\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(new ApiError(ErrorCode.EIO));\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 async get(key: Ino): Promise<Uint8Array> {\n\t\ttry {\n\t\t\treturn await wrap<Uint8Array>(this.store.get(key.toString()));\n\t\t} catch (e) {\n\t\t\tthrow convertError(e);\n\t\t}\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\ttry {\n\t\t\tawait wrap(overwrite ? this.store.put(data, key.toString()) : this.store.add(data, key.toString()));\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\tthrow convertError(e);\n\t\t}\n\t}\n\n\tpublic async remove(key: Ino): Promise<void> {\n\t\ttry {\n\t\t\tawait wrap(this.store.delete(key.toString()));\n\t\t} catch (e) {\n\t\t\tthrow convertError(e);\n\t\t}\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 convertError(e);\n\t\t}\n\t}\n}\n\nexport class IndexedDBStore implements AsyncStore {\n\tpublic static async create(storeName: string, indexedDB: IDBFactory): 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 new Promise((resolve, reject) => {\n\t\t\ttry {\n\t\t\t\tconst req: IDBRequest = this.db.transaction(this.storeName, 'readwrite').objectStore(this.storeName).clear();\n\t\t\t\treq.onsuccess = () => resolve();\n\t\t\t\treq.onerror = e => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\treject(new ApiError(ErrorCode.EIO));\n\t\t\t\t};\n\t\t\t} catch (e) {\n\t\t\t\treject(convertError(e));\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic beginTransaction(): IndexedDBTransaction {\n\t\tconst tx = this.db.transaction(this.storeName, 'readwrite'),\n\t\t\tobjectStore = tx.objectStore(this.storeName);\n\t\treturn new IndexedDBTransaction(tx, objectStore);\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({ lruCacheSize = 100, storeName = 'zenfs', idbFactory = globalThis.indexedDB }: IndexedDBOptions) {\n\t\tconst store = IndexedDBStore.create(storeName, idbFactory);\n\t\tconst fs = new AsyncStoreFS({ lruCacheSize, store });\n\t\treturn fs;\n\t},\n} as const satisfies Backend;\n", "import type { Backend, Ino } from '@zenfs/core';\nimport { SyncStore, SimpleSyncStore, SimpleSyncTransaction, SyncStoreFS, ApiError, ErrorCode, encode, decode } 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": "meAAA,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,iBAAAC,EAAkB,aAAAC,EAAc,YAAAC,GAAa,cAAAC,GAAe,IAAAC,GAAK,OAAAC,GAAQ,UAAAC,EAAW,aAAAC,GAAc,KAAAC,GAAM,UAAAC,GAAW,YAAAC,GAAa,WAAAC,EAAY,SAAAC,EAAU,SAAAC,EAAU,cAAAC,GAAe,cAAAC,GAAe,eAAAC,GAAgB,WAAAC,GAAY,MAAAC,GAAO,SAAAC,GAAU,MAAAC,GAAO,WAAAC,GAAY,QAAAC,GAAS,UAAAC,GAAW,YAAAC,EAAa,WAAAC,GAAY,SAAA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S,EAAGI,EAAOH,CAAI,CAAC,EAC3C,GACR,MAAE,CACD,MAAM,IAAII,EAASC,EAAU,OAAQ,kBAAkB,CACxD,CACD,CAEO,OAAON,EAAgB,CAC7B,GAAI,CACH,KAAK,SAAS,WAAWA,EAAI,SAAS,CAAC,CACxC,OAASO,EAAP,CACD,MAAM,IAAIF,EAASC,EAAU,IAAK,wBAA0BN,EAAM,KAAOO,CAAC,CAC3E,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", "ApiError", "Async", "AsyncFileIndexFS", "AsyncStoreFS", "BigIntStats", "BigIntStatsFs", "Dir", "Dirent", "ErrorCode", "ErrorStrings", "File", "FileIndex", "FileIndexFS", "FileSystem", "FileType", "InMemory", "InMemoryStore", "IndexDirInode", "IndexFileInode", "IndexInode", "Inode", "LockedFS", "Mutex", "NoSyncFile", "Overlay", "OverlayFS", "PreloadFile", "ReadStream", "Readonly", "SimpleSyncTransaction", "Stats", "StatsCommon", "StatsFs", "Sync", "SyncFileIndexFS", "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", "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", "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", "wait", "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", "handleError", "__name", "path", "syscall", "error", "ApiError", "WebAccessFS", "Async", "FileSystem", "handle", "InMemory", "p", "data", "stats", "currentStats", "oldPath", "newPath", "files", "file", "join", "oldFile", "destFolder", "dirname", "writable", "basename", "buffer", "err", "fname", "flag", "Stats", "FileType", "lastModified", "size", "PreloadFile", "e", "ErrorCode", "_keys", "key", "walkedPath", "pathParts", "getHandleParts", "pathPart", "remainingPathParts", "walkingPath", "continueWalk", "WebAccess", "options", "convertError", "e", "message", "ApiError", "ErrorCode", "__name", "wrap", "request", "resolve", "reject", "IndexedDBTransaction", "tx", "store", "key", "data", "overwrite", "IndexedDBStore", "db", "storeName", "indexedDB", "req", "result", "IndexedDB", "objectStore", "idbFactory", "lruCacheSize", "AsyncStoreFS", "WebStorageStore", "_storage", "WebStorage", "SimpleSyncTransaction", "key", "data", "encode", "overwrite", "decode", "ApiError", "ErrorCode", "e", "__name", "storage", "SyncStoreFS"]
|
|
7
7
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/dom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "DOM backends for ZenFS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist",
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"typescript": "5.2.2"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@zenfs/core": "^0.
|
|
56
|
+
"@zenfs/core": "^0.7.0"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { Backend, FileSystemMetadata } from '@zenfs/core';
|
|
2
|
-
import { FileSystem, PreloadFile, Stats } from '@zenfs/core';
|
|
3
|
-
declare global {
|
|
4
|
-
interface FileSystemDirectoryHandle {
|
|
5
|
-
[Symbol.iterator](): IterableIterator<[string, FileSystemHandle]>;
|
|
6
|
-
entries(): IterableIterator<[string, FileSystemHandle]>;
|
|
7
|
-
keys(): IterableIterator<string>;
|
|
8
|
-
values(): IterableIterator<FileSystemHandle>;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export interface FileSystemAccessOptions {
|
|
12
|
-
handle: FileSystemDirectoryHandle;
|
|
13
|
-
}
|
|
14
|
-
export declare class FileSystemAccessFile extends PreloadFile<FileSystemAccessFS> {
|
|
15
|
-
constructor(_fs: FileSystemAccessFS, _path: string, _flag: string, _stat: Stats, contents?: Uint8Array);
|
|
16
|
-
syncSync(): void;
|
|
17
|
-
sync(): Promise<void>;
|
|
18
|
-
close(): Promise<void>;
|
|
19
|
-
closeSync(): void;
|
|
20
|
-
}
|
|
21
|
-
declare const FileSystemAccessFS_base: (abstract new (...args: any[]) => {
|
|
22
|
-
metadata(): FileSystemMetadata;
|
|
23
|
-
renameSync(oldPath: string, newPath: string, cred: import("@zenfs/core").Cred): void;
|
|
24
|
-
statSync(path: string, cred: import("@zenfs/core").Cred): Stats;
|
|
25
|
-
createFileSync(path: string, flag: string, mode: number, cred: import("@zenfs/core").Cred): import("@zenfs/core").File;
|
|
26
|
-
openFileSync(path: string, flag: string, cred: import("@zenfs/core").Cred): import("@zenfs/core").File;
|
|
27
|
-
unlinkSync(path: string, cred: import("@zenfs/core").Cred): void;
|
|
28
|
-
rmdirSync(path: string, cred: import("@zenfs/core").Cred): void;
|
|
29
|
-
mkdirSync(path: string, mode: number, cred: import("@zenfs/core").Cred): void;
|
|
30
|
-
readdirSync(path: string, cred: import("@zenfs/core").Cred): string[];
|
|
31
|
-
linkSync(srcpath: string, dstpath: string, cred: import("@zenfs/core").Cred): void;
|
|
32
|
-
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
33
|
-
}) & typeof FileSystem;
|
|
34
|
-
export declare class FileSystemAccessFS extends FileSystemAccessFS_base {
|
|
35
|
-
private _handles;
|
|
36
|
-
ready(): Promise<this>;
|
|
37
|
-
constructor({ handle }: FileSystemAccessOptions);
|
|
38
|
-
metadata(): FileSystemMetadata;
|
|
39
|
-
sync(p: string, data: Uint8Array, stats: Stats): Promise<void>;
|
|
40
|
-
rename(oldPath: string, newPath: string): Promise<void>;
|
|
41
|
-
writeFile(fname: string, data: Uint8Array): Promise<void>;
|
|
42
|
-
createFile(path: string, flag: string): Promise<FileSystemAccessFile>;
|
|
43
|
-
stat(path: string): Promise<Stats>;
|
|
44
|
-
openFile(path: string, flag: string): Promise<FileSystemAccessFile>;
|
|
45
|
-
unlink(path: string): Promise<void>;
|
|
46
|
-
link(): Promise<void>;
|
|
47
|
-
rmdir(path: string): Promise<void>;
|
|
48
|
-
mkdir(path: string): Promise<void>;
|
|
49
|
-
readdir(path: string): Promise<string[]>;
|
|
50
|
-
protected getHandle(path: string): Promise<FileSystemHandle>;
|
|
51
|
-
}
|
|
52
|
-
export declare const FileSystemAccess: Backend<FileSystemAccessFS>;
|
|
53
|
-
export {};
|