@componentor/fs 1.2.8 → 2.0.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/README.md +398 -634
- package/dist/index.cjs +2637 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +606 -0
- package/dist/index.d.ts +539 -481
- package/dist/index.js +2358 -2480
- package/dist/index.js.map +1 -1
- package/dist/kernel.js +496 -0
- package/dist/kernel.js.map +1 -0
- package/package.json +39 -45
- package/dist/opfs-hybrid.d.ts +0 -198
- package/dist/opfs-hybrid.js +0 -2743
- package/dist/opfs-hybrid.js.map +0 -1
- package/dist/opfs-worker-proxy.d.ts +0 -224
- package/dist/opfs-worker-proxy.js +0 -274
- package/dist/opfs-worker-proxy.js.map +0 -1
- package/dist/opfs-worker.js +0 -2923
- package/dist/opfs-worker.js.map +0 -1
- package/src/constants.ts +0 -52
- package/src/errors.ts +0 -88
- package/src/file-handle.ts +0 -100
- package/src/global.d.ts +0 -57
- package/src/handle-manager.ts +0 -302
- package/src/index.ts +0 -1416
- package/src/opfs-hybrid.ts +0 -265
- package/src/opfs-worker-proxy.ts +0 -374
- package/src/opfs-worker.ts +0 -253
- package/src/packed-storage.ts +0 -604
- package/src/path-utils.ts +0 -97
- package/src/streams.ts +0 -109
- package/src/symlink-manager.ts +0 -338
- package/src/types.ts +0 -289
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File system types matching Node.js fs module interfaces
|
|
3
|
+
*/
|
|
4
|
+
type Encoding = 'utf8' | 'utf-8' | 'ascii' | 'base64' | 'hex' | 'binary';
|
|
5
|
+
interface ReadOptions {
|
|
6
|
+
encoding?: Encoding | null;
|
|
7
|
+
flag?: string;
|
|
8
|
+
}
|
|
9
|
+
interface WriteOptions {
|
|
10
|
+
encoding?: Encoding;
|
|
11
|
+
mode?: number;
|
|
12
|
+
flag?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to flush data to storage after writing.
|
|
15
|
+
* - true (default): Data is immediately persisted - safe but slower
|
|
16
|
+
* - false: Data is written but not flushed - faster but may be lost on crash
|
|
17
|
+
*/
|
|
18
|
+
flush?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface MkdirOptions {
|
|
21
|
+
recursive?: boolean;
|
|
22
|
+
mode?: number;
|
|
23
|
+
}
|
|
24
|
+
interface RmdirOptions {
|
|
25
|
+
recursive?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface RmOptions {
|
|
28
|
+
recursive?: boolean;
|
|
29
|
+
force?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface ReaddirOptions {
|
|
32
|
+
encoding?: Encoding | null;
|
|
33
|
+
withFileTypes?: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface StatOptions {
|
|
36
|
+
bigint?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface Stats {
|
|
39
|
+
isFile(): boolean;
|
|
40
|
+
isDirectory(): boolean;
|
|
41
|
+
isBlockDevice(): boolean;
|
|
42
|
+
isCharacterDevice(): boolean;
|
|
43
|
+
isSymbolicLink(): boolean;
|
|
44
|
+
isFIFO(): boolean;
|
|
45
|
+
isSocket(): boolean;
|
|
46
|
+
dev: number;
|
|
47
|
+
ino: number;
|
|
48
|
+
mode: number;
|
|
49
|
+
nlink: number;
|
|
50
|
+
uid: number;
|
|
51
|
+
gid: number;
|
|
52
|
+
rdev: number;
|
|
53
|
+
size: number;
|
|
54
|
+
blksize: number;
|
|
55
|
+
blocks: number;
|
|
56
|
+
atimeMs: number;
|
|
57
|
+
mtimeMs: number;
|
|
58
|
+
ctimeMs: number;
|
|
59
|
+
birthtimeMs: number;
|
|
60
|
+
atime: Date;
|
|
61
|
+
mtime: Date;
|
|
62
|
+
ctime: Date;
|
|
63
|
+
birthtime: Date;
|
|
64
|
+
}
|
|
65
|
+
interface Dirent {
|
|
66
|
+
name: string;
|
|
67
|
+
isFile(): boolean;
|
|
68
|
+
isDirectory(): boolean;
|
|
69
|
+
isBlockDevice(): boolean;
|
|
70
|
+
isCharacterDevice(): boolean;
|
|
71
|
+
isSymbolicLink(): boolean;
|
|
72
|
+
isFIFO(): boolean;
|
|
73
|
+
isSocket(): boolean;
|
|
74
|
+
}
|
|
75
|
+
interface FileSystemPromises {
|
|
76
|
+
readFile(path: string, options?: ReadOptions | Encoding | null): Promise<Uint8Array | string>;
|
|
77
|
+
writeFile(path: string, data: Uint8Array | string, options?: WriteOptions | Encoding): Promise<void>;
|
|
78
|
+
appendFile(path: string, data: Uint8Array | string, options?: WriteOptions | Encoding): Promise<void>;
|
|
79
|
+
mkdir(path: string, options?: MkdirOptions | number): Promise<string | undefined>;
|
|
80
|
+
rmdir(path: string, options?: RmdirOptions): Promise<void>;
|
|
81
|
+
rm(path: string, options?: RmOptions): Promise<void>;
|
|
82
|
+
unlink(path: string): Promise<void>;
|
|
83
|
+
readdir(path: string, options?: ReaddirOptions | Encoding | null): Promise<string[] | Dirent[]>;
|
|
84
|
+
stat(path: string, options?: StatOptions): Promise<Stats>;
|
|
85
|
+
lstat(path: string, options?: StatOptions): Promise<Stats>;
|
|
86
|
+
access(path: string, mode?: number): Promise<void>;
|
|
87
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
88
|
+
copyFile(src: string, dest: string, mode?: number): Promise<void>;
|
|
89
|
+
truncate(path: string, len?: number): Promise<void>;
|
|
90
|
+
realpath(path: string): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Check if a path exists.
|
|
93
|
+
* Note: This is not in Node.js fs.promises but is commonly needed.
|
|
94
|
+
*/
|
|
95
|
+
exists(path: string): Promise<boolean>;
|
|
96
|
+
/**
|
|
97
|
+
* Change file mode (no-op in OPFS - permissions not supported).
|
|
98
|
+
*/
|
|
99
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Change file owner (no-op in OPFS - ownership not supported).
|
|
102
|
+
*/
|
|
103
|
+
chown(path: string, uid: number, gid: number): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Change file timestamps (no-op in OPFS - timestamps are read-only).
|
|
106
|
+
*/
|
|
107
|
+
utimes(path: string, atime: Date | number, mtime: Date | number): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Create a symbolic link.
|
|
110
|
+
* Emulated by storing target path in a special file format.
|
|
111
|
+
*/
|
|
112
|
+
symlink(target: string, path: string, type?: string): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Read a symbolic link target.
|
|
115
|
+
*/
|
|
116
|
+
readlink(path: string): Promise<string>;
|
|
117
|
+
/**
|
|
118
|
+
* Create a hard link.
|
|
119
|
+
* Emulated by copying the file (true hard links not supported in OPFS).
|
|
120
|
+
*/
|
|
121
|
+
link(existingPath: string, newPath: string): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Open a file and return a FileHandle.
|
|
124
|
+
*/
|
|
125
|
+
open(path: string, flags?: string | number, mode?: number): Promise<FileHandle>;
|
|
126
|
+
/**
|
|
127
|
+
* Open a directory for iteration.
|
|
128
|
+
*/
|
|
129
|
+
opendir(path: string): Promise<Dir>;
|
|
130
|
+
/**
|
|
131
|
+
* Create a unique temporary directory.
|
|
132
|
+
*/
|
|
133
|
+
mkdtemp(prefix: string): Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Watch a file or directory for changes.
|
|
136
|
+
*/
|
|
137
|
+
watch(path: string, options?: WatchOptions): AsyncIterable<WatchEventType>;
|
|
138
|
+
/**
|
|
139
|
+
* Flush all pending writes to storage.
|
|
140
|
+
* Use after writes with { flush: false } to ensure data is persisted.
|
|
141
|
+
*/
|
|
142
|
+
flush(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Purge all kernel caches.
|
|
145
|
+
* Use between major operations to ensure clean state.
|
|
146
|
+
*/
|
|
147
|
+
purge(): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
type PathLike = string;
|
|
150
|
+
interface ReadStreamOptions {
|
|
151
|
+
flags?: string;
|
|
152
|
+
encoding?: Encoding | null;
|
|
153
|
+
fd?: number | null;
|
|
154
|
+
mode?: number;
|
|
155
|
+
autoClose?: boolean;
|
|
156
|
+
emitClose?: boolean;
|
|
157
|
+
start?: number;
|
|
158
|
+
end?: number;
|
|
159
|
+
highWaterMark?: number;
|
|
160
|
+
}
|
|
161
|
+
interface WriteStreamOptions {
|
|
162
|
+
flags?: string;
|
|
163
|
+
encoding?: Encoding;
|
|
164
|
+
fd?: number | null;
|
|
165
|
+
mode?: number;
|
|
166
|
+
autoClose?: boolean;
|
|
167
|
+
emitClose?: boolean;
|
|
168
|
+
start?: number;
|
|
169
|
+
highWaterMark?: number;
|
|
170
|
+
flush?: boolean;
|
|
171
|
+
}
|
|
172
|
+
interface WatchOptions {
|
|
173
|
+
persistent?: boolean;
|
|
174
|
+
recursive?: boolean;
|
|
175
|
+
encoding?: Encoding;
|
|
176
|
+
signal?: AbortSignal;
|
|
177
|
+
}
|
|
178
|
+
interface WatchFileOptions {
|
|
179
|
+
persistent?: boolean;
|
|
180
|
+
interval?: number;
|
|
181
|
+
}
|
|
182
|
+
interface WatchEventType {
|
|
183
|
+
eventType: 'rename' | 'change';
|
|
184
|
+
filename: string | null;
|
|
185
|
+
}
|
|
186
|
+
interface FileHandle {
|
|
187
|
+
fd: number;
|
|
188
|
+
read(buffer: Uint8Array, offset?: number, length?: number, position?: number | null): Promise<{
|
|
189
|
+
bytesRead: number;
|
|
190
|
+
buffer: Uint8Array;
|
|
191
|
+
}>;
|
|
192
|
+
write(buffer: Uint8Array, offset?: number, length?: number, position?: number | null): Promise<{
|
|
193
|
+
bytesWritten: number;
|
|
194
|
+
buffer: Uint8Array;
|
|
195
|
+
}>;
|
|
196
|
+
readFile(options?: ReadOptions | Encoding | null): Promise<Uint8Array | string>;
|
|
197
|
+
writeFile(data: Uint8Array | string, options?: WriteOptions | Encoding): Promise<void>;
|
|
198
|
+
truncate(len?: number): Promise<void>;
|
|
199
|
+
stat(): Promise<Stats>;
|
|
200
|
+
sync(): Promise<void>;
|
|
201
|
+
datasync(): Promise<void>;
|
|
202
|
+
close(): Promise<void>;
|
|
203
|
+
}
|
|
204
|
+
interface Dir {
|
|
205
|
+
path: string;
|
|
206
|
+
read(): Promise<Dirent | null>;
|
|
207
|
+
close(): Promise<void>;
|
|
208
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Dirent>;
|
|
209
|
+
}
|
|
210
|
+
interface FSWatcher {
|
|
211
|
+
close(): void;
|
|
212
|
+
ref(): this;
|
|
213
|
+
unref(): this;
|
|
214
|
+
}
|
|
215
|
+
interface StatWatcher {
|
|
216
|
+
ref(): this;
|
|
217
|
+
unref(): this;
|
|
218
|
+
}
|
|
219
|
+
type WatchListener = (eventType: 'rename' | 'change', filename: string | null) => void;
|
|
220
|
+
type WatchFileListener = (curr: Stats, prev: Stats) => void;
|
|
221
|
+
interface FileSystemChangeRecord {
|
|
222
|
+
changedHandle: FileSystemHandle | null;
|
|
223
|
+
relativePathComponents: string[];
|
|
224
|
+
relativePathMovedFrom: string[] | null;
|
|
225
|
+
root: FileSystemHandle;
|
|
226
|
+
type: 'appeared' | 'disappeared' | 'modified' | 'moved' | 'errored' | 'unknown';
|
|
227
|
+
}
|
|
228
|
+
type FileSystemObserverCallback = (records: FileSystemChangeRecord[], observer: FileSystemObserverInterface) => void;
|
|
229
|
+
interface FileSystemObserverInterface {
|
|
230
|
+
observe(handle: FileSystemHandle, options?: {
|
|
231
|
+
recursive?: boolean;
|
|
232
|
+
}): Promise<void>;
|
|
233
|
+
disconnect(): void;
|
|
234
|
+
}
|
|
235
|
+
declare global {
|
|
236
|
+
interface Window {
|
|
237
|
+
FileSystemObserver?: new (callback: FileSystemObserverCallback) => FileSystemObserverInterface;
|
|
238
|
+
}
|
|
239
|
+
var FileSystemObserver: (new (callback: FileSystemObserverCallback) => FileSystemObserverInterface) | undefined;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* OPFS FileSystem - Node.js fs-compatible API
|
|
244
|
+
* Supports two performance tiers:
|
|
245
|
+
* - Tier 1 (Sync): SharedArrayBuffer + Atomics - requires crossOriginIsolated (COOP/COEP headers)
|
|
246
|
+
* - Tier 2 (Async): Promises API using Worker kernel - always available
|
|
247
|
+
*/
|
|
248
|
+
|
|
249
|
+
declare class OPFSFileSystem {
|
|
250
|
+
private worker;
|
|
251
|
+
private pending;
|
|
252
|
+
private initialized;
|
|
253
|
+
private initPromise;
|
|
254
|
+
private fdTable;
|
|
255
|
+
private nextFd;
|
|
256
|
+
private statCache;
|
|
257
|
+
constructor();
|
|
258
|
+
private invalidateStat;
|
|
259
|
+
private invalidateStatsUnder;
|
|
260
|
+
private initWorker;
|
|
261
|
+
private asyncCall;
|
|
262
|
+
private syncKernel;
|
|
263
|
+
private syncKernelReady;
|
|
264
|
+
/**
|
|
265
|
+
* Initialize sync operations with a kernel worker loaded from URL.
|
|
266
|
+
* Required for Tier 1 (SharedArrayBuffer + Atomics) to work in nested Workers.
|
|
267
|
+
* @param kernelUrl URL to the kernel.js file (defaults to '/kernel.js')
|
|
268
|
+
*/
|
|
269
|
+
initSync(kernelUrl?: string): Promise<void>;
|
|
270
|
+
private static readonly META_SIZE;
|
|
271
|
+
private static readonly DEFAULT_DATA_SIZE;
|
|
272
|
+
private static readonly MAX_CHUNK_SIZE;
|
|
273
|
+
private syncBufferPool;
|
|
274
|
+
private getSyncBuffers;
|
|
275
|
+
private syncCallTier1;
|
|
276
|
+
private asyncOperationPromise;
|
|
277
|
+
private syncCallTier1Async;
|
|
278
|
+
private syncCallTier1AsyncImpl;
|
|
279
|
+
private syncStatTier1Async;
|
|
280
|
+
private syncCallTier1ChunkedAsync;
|
|
281
|
+
private syncCallTier1ChunkedReadAsync;
|
|
282
|
+
private syncCallTier1Chunked;
|
|
283
|
+
private syncCallTier1ChunkedRead;
|
|
284
|
+
private syncStatTier1;
|
|
285
|
+
private syncCall;
|
|
286
|
+
readFileSync(filePath: string, options?: ReadOptions | Encoding | null): Uint8Array | string;
|
|
287
|
+
writeFileSync(filePath: string, data: Uint8Array | string, options?: WriteOptions | Encoding): void;
|
|
288
|
+
appendFileSync(filePath: string, data: Uint8Array | string, options?: WriteOptions | Encoding): void;
|
|
289
|
+
existsSync(filePath: string): boolean;
|
|
290
|
+
mkdirSync(filePath: string, options?: MkdirOptions | number): string | undefined;
|
|
291
|
+
rmdirSync(filePath: string, options?: RmdirOptions): void;
|
|
292
|
+
rmSync(filePath: string, options?: RmOptions): void;
|
|
293
|
+
unlinkSync(filePath: string): void;
|
|
294
|
+
readdirSync(filePath: string, options?: ReaddirOptions | Encoding | null): string[] | Dirent[];
|
|
295
|
+
statSync(filePath: string): Stats;
|
|
296
|
+
lstatSync(filePath: string): Stats;
|
|
297
|
+
/**
|
|
298
|
+
* Create stats object for a symlink file.
|
|
299
|
+
*/
|
|
300
|
+
private createSymlinkStats;
|
|
301
|
+
renameSync(oldPath: string, newPath: string): void;
|
|
302
|
+
copyFileSync(src: string, dest: string): void;
|
|
303
|
+
truncateSync(filePath: string, len?: number): void;
|
|
304
|
+
/**
|
|
305
|
+
* Flush all pending writes to storage.
|
|
306
|
+
* Use this after writes with { flush: false } to ensure data is persisted.
|
|
307
|
+
*/
|
|
308
|
+
flushSync(): void;
|
|
309
|
+
/**
|
|
310
|
+
* Alias for flushSync() - matches Node.js fdatasync behavior
|
|
311
|
+
*/
|
|
312
|
+
fdatasyncSync(): void;
|
|
313
|
+
/**
|
|
314
|
+
* Purge all kernel caches (sync handles, directory handles).
|
|
315
|
+
* Use between major operations to ensure clean state.
|
|
316
|
+
*/
|
|
317
|
+
purgeSync(): void;
|
|
318
|
+
accessSync(filePath: string, _mode?: number): void;
|
|
319
|
+
openSync(filePath: string, flags?: string | number): number;
|
|
320
|
+
closeSync(fd: number): void;
|
|
321
|
+
readSync(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null): number;
|
|
322
|
+
writeSync(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null): number;
|
|
323
|
+
fstatSync(fd: number): Stats;
|
|
324
|
+
ftruncateSync(fd: number, len?: number): void;
|
|
325
|
+
/**
|
|
326
|
+
* Resolve a path to an absolute path.
|
|
327
|
+
* OPFS doesn't support symlinks, so this just normalizes the path.
|
|
328
|
+
*/
|
|
329
|
+
realpathSync(filePath: string): string;
|
|
330
|
+
/**
|
|
331
|
+
* Change file mode (no-op in OPFS - permissions not supported).
|
|
332
|
+
*/
|
|
333
|
+
chmodSync(_filePath: string, _mode: number): void;
|
|
334
|
+
/**
|
|
335
|
+
* Change file owner (no-op in OPFS - ownership not supported).
|
|
336
|
+
*/
|
|
337
|
+
chownSync(_filePath: string, _uid: number, _gid: number): void;
|
|
338
|
+
/**
|
|
339
|
+
* Change file timestamps (no-op in OPFS - timestamps are read-only).
|
|
340
|
+
*/
|
|
341
|
+
utimesSync(_filePath: string, _atime: Date | number, _mtime: Date | number): void;
|
|
342
|
+
private static readonly SYMLINK_MAGIC;
|
|
343
|
+
/**
|
|
344
|
+
* Create a symbolic link.
|
|
345
|
+
* Emulated by storing target path in a special file format.
|
|
346
|
+
*/
|
|
347
|
+
symlinkSync(target: string, filePath: string, _type?: string): void;
|
|
348
|
+
/**
|
|
349
|
+
* Read a symbolic link target.
|
|
350
|
+
*/
|
|
351
|
+
readlinkSync(filePath: string): string;
|
|
352
|
+
/**
|
|
353
|
+
* Check if a file is a symlink (sync).
|
|
354
|
+
*/
|
|
355
|
+
private isSymlinkSync;
|
|
356
|
+
/**
|
|
357
|
+
* Check if a file is a symlink (async).
|
|
358
|
+
*/
|
|
359
|
+
private isSymlinkAsync;
|
|
360
|
+
/**
|
|
361
|
+
* Create a hard link.
|
|
362
|
+
* Emulated by copying the file (true hard links not supported in OPFS).
|
|
363
|
+
*/
|
|
364
|
+
linkSync(existingPath: string, newPath: string): void;
|
|
365
|
+
private parseFlags;
|
|
366
|
+
private fastCall;
|
|
367
|
+
promises: FileSystemPromises;
|
|
368
|
+
/**
|
|
369
|
+
* Async flush - use after promises.writeFile with { flush: false }
|
|
370
|
+
*/
|
|
371
|
+
flush(): Promise<void>;
|
|
372
|
+
/**
|
|
373
|
+
* Async purge - clears all kernel caches
|
|
374
|
+
*/
|
|
375
|
+
purge(): Promise<void>;
|
|
376
|
+
constants: {
|
|
377
|
+
readonly F_OK: 0;
|
|
378
|
+
readonly R_OK: 4;
|
|
379
|
+
readonly W_OK: 2;
|
|
380
|
+
readonly X_OK: 1;
|
|
381
|
+
readonly COPYFILE_EXCL: 1;
|
|
382
|
+
readonly COPYFILE_FICLONE: 2;
|
|
383
|
+
readonly COPYFILE_FICLONE_FORCE: 4;
|
|
384
|
+
readonly O_RDONLY: 0;
|
|
385
|
+
readonly O_WRONLY: 1;
|
|
386
|
+
readonly O_RDWR: 2;
|
|
387
|
+
readonly O_CREAT: 64;
|
|
388
|
+
readonly O_EXCL: 128;
|
|
389
|
+
readonly O_TRUNC: 512;
|
|
390
|
+
readonly O_APPEND: 1024;
|
|
391
|
+
readonly O_SYNC: 4096;
|
|
392
|
+
readonly S_IFMT: 61440;
|
|
393
|
+
readonly S_IFREG: 32768;
|
|
394
|
+
readonly S_IFDIR: 16384;
|
|
395
|
+
readonly S_IFCHR: 8192;
|
|
396
|
+
readonly S_IFBLK: 24576;
|
|
397
|
+
readonly S_IFIFO: 4096;
|
|
398
|
+
readonly S_IFLNK: 40960;
|
|
399
|
+
readonly S_IFSOCK: 49152;
|
|
400
|
+
readonly S_IRWXU: 448;
|
|
401
|
+
readonly S_IRUSR: 256;
|
|
402
|
+
readonly S_IWUSR: 128;
|
|
403
|
+
readonly S_IXUSR: 64;
|
|
404
|
+
readonly S_IRWXG: 56;
|
|
405
|
+
readonly S_IRGRP: 32;
|
|
406
|
+
readonly S_IWGRP: 16;
|
|
407
|
+
readonly S_IXGRP: 8;
|
|
408
|
+
readonly S_IRWXO: 7;
|
|
409
|
+
readonly S_IROTH: 4;
|
|
410
|
+
readonly S_IWOTH: 2;
|
|
411
|
+
readonly S_IXOTH: 1;
|
|
412
|
+
};
|
|
413
|
+
private createFileHandle;
|
|
414
|
+
private createDir;
|
|
415
|
+
private watchedFiles;
|
|
416
|
+
private static readonly hasNativeObserver;
|
|
417
|
+
private getDirectoryHandle;
|
|
418
|
+
private getFileHandle;
|
|
419
|
+
private mapChangeType;
|
|
420
|
+
private createAsyncWatcher;
|
|
421
|
+
private createNativeAsyncWatcher;
|
|
422
|
+
private createPollingAsyncWatcher;
|
|
423
|
+
/**
|
|
424
|
+
* Watch a file or directory for changes.
|
|
425
|
+
* Uses native FileSystemObserver when available, falls back to polling.
|
|
426
|
+
*/
|
|
427
|
+
watch(filePath: string, options?: WatchOptions | WatchListener, listener?: WatchListener): FSWatcher;
|
|
428
|
+
private createNativeWatcher;
|
|
429
|
+
private createPollingWatcher;
|
|
430
|
+
/**
|
|
431
|
+
* Watch a file for changes using native FileSystemObserver or stat polling.
|
|
432
|
+
*/
|
|
433
|
+
watchFile(filePath: string, options?: WatchFileOptions | WatchFileListener, listener?: WatchFileListener): StatWatcher;
|
|
434
|
+
/**
|
|
435
|
+
* Stop watching a file.
|
|
436
|
+
*/
|
|
437
|
+
unwatchFile(filePath: string, listener?: WatchFileListener): void;
|
|
438
|
+
/**
|
|
439
|
+
* Create a readable stream for a file.
|
|
440
|
+
*/
|
|
441
|
+
createReadStream(filePath: string, options?: ReadStreamOptions | string): ReadableStream<Uint8Array>;
|
|
442
|
+
/**
|
|
443
|
+
* Create a writable stream for a file.
|
|
444
|
+
*/
|
|
445
|
+
createWriteStream(filePath: string, options?: WriteStreamOptions | string): WritableStream<Uint8Array>;
|
|
446
|
+
/**
|
|
447
|
+
* Open a directory for iteration (sync).
|
|
448
|
+
*/
|
|
449
|
+
opendirSync(dirPath: string): Dir;
|
|
450
|
+
/**
|
|
451
|
+
* Create a unique temporary directory (sync).
|
|
452
|
+
*/
|
|
453
|
+
mkdtempSync(prefix: string): string;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* File system constants matching Node.js fs.constants
|
|
458
|
+
*/
|
|
459
|
+
declare const constants: {
|
|
460
|
+
readonly F_OK: 0;
|
|
461
|
+
readonly R_OK: 4;
|
|
462
|
+
readonly W_OK: 2;
|
|
463
|
+
readonly X_OK: 1;
|
|
464
|
+
readonly COPYFILE_EXCL: 1;
|
|
465
|
+
readonly COPYFILE_FICLONE: 2;
|
|
466
|
+
readonly COPYFILE_FICLONE_FORCE: 4;
|
|
467
|
+
readonly O_RDONLY: 0;
|
|
468
|
+
readonly O_WRONLY: 1;
|
|
469
|
+
readonly O_RDWR: 2;
|
|
470
|
+
readonly O_CREAT: 64;
|
|
471
|
+
readonly O_EXCL: 128;
|
|
472
|
+
readonly O_TRUNC: 512;
|
|
473
|
+
readonly O_APPEND: 1024;
|
|
474
|
+
readonly O_SYNC: 4096;
|
|
475
|
+
readonly S_IFMT: 61440;
|
|
476
|
+
readonly S_IFREG: 32768;
|
|
477
|
+
readonly S_IFDIR: 16384;
|
|
478
|
+
readonly S_IFCHR: 8192;
|
|
479
|
+
readonly S_IFBLK: 24576;
|
|
480
|
+
readonly S_IFIFO: 4096;
|
|
481
|
+
readonly S_IFLNK: 40960;
|
|
482
|
+
readonly S_IFSOCK: 49152;
|
|
483
|
+
readonly S_IRWXU: 448;
|
|
484
|
+
readonly S_IRUSR: 256;
|
|
485
|
+
readonly S_IWUSR: 128;
|
|
486
|
+
readonly S_IXUSR: 64;
|
|
487
|
+
readonly S_IRWXG: 56;
|
|
488
|
+
readonly S_IRGRP: 32;
|
|
489
|
+
readonly S_IWGRP: 16;
|
|
490
|
+
readonly S_IXGRP: 8;
|
|
491
|
+
readonly S_IRWXO: 7;
|
|
492
|
+
readonly S_IROTH: 4;
|
|
493
|
+
readonly S_IWOTH: 2;
|
|
494
|
+
readonly S_IXOTH: 1;
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Node.js compatible filesystem error classes
|
|
499
|
+
*/
|
|
500
|
+
declare class FSError extends Error {
|
|
501
|
+
code: string;
|
|
502
|
+
errno: number;
|
|
503
|
+
syscall?: string;
|
|
504
|
+
path?: string;
|
|
505
|
+
constructor(code: string, errno: number, message: string, syscall?: string, path?: string);
|
|
506
|
+
}
|
|
507
|
+
declare function createENOENT(syscall: string, path: string): FSError;
|
|
508
|
+
declare function createEEXIST(syscall: string, path: string): FSError;
|
|
509
|
+
declare function createEISDIR(syscall: string, path: string): FSError;
|
|
510
|
+
declare function createENOTDIR(syscall: string, path: string): FSError;
|
|
511
|
+
declare function createENOTEMPTY(syscall: string, path: string): FSError;
|
|
512
|
+
declare function createEACCES(syscall: string, path: string): FSError;
|
|
513
|
+
declare function createEINVAL(syscall: string, path: string): FSError;
|
|
514
|
+
declare function mapErrorCode(errorName: string, syscall: string, path: string): FSError;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* POSIX-style path utilities for OPFS
|
|
518
|
+
* Mirrors Node.js path module behavior
|
|
519
|
+
*/
|
|
520
|
+
declare const sep = "/";
|
|
521
|
+
declare const delimiter = ":";
|
|
522
|
+
declare function normalize(p: string): string;
|
|
523
|
+
declare function join(...paths: string[]): string;
|
|
524
|
+
declare function resolve(...paths: string[]): string;
|
|
525
|
+
declare function isAbsolute(p: string): boolean;
|
|
526
|
+
declare function dirname(p: string): string;
|
|
527
|
+
declare function basename(p: string, ext?: string): string;
|
|
528
|
+
declare function extname(p: string): string;
|
|
529
|
+
declare function relative(from: string, to: string): string;
|
|
530
|
+
declare function parse(p: string): {
|
|
531
|
+
root: string;
|
|
532
|
+
dir: string;
|
|
533
|
+
base: string;
|
|
534
|
+
ext: string;
|
|
535
|
+
name: string;
|
|
536
|
+
};
|
|
537
|
+
declare function format(pathObject: {
|
|
538
|
+
root?: string;
|
|
539
|
+
dir?: string;
|
|
540
|
+
base?: string;
|
|
541
|
+
ext?: string;
|
|
542
|
+
name?: string;
|
|
543
|
+
}): string;
|
|
544
|
+
declare const posix: {
|
|
545
|
+
sep: string;
|
|
546
|
+
delimiter: string;
|
|
547
|
+
normalize: typeof normalize;
|
|
548
|
+
join: typeof join;
|
|
549
|
+
resolve: typeof resolve;
|
|
550
|
+
isAbsolute: typeof isAbsolute;
|
|
551
|
+
dirname: typeof dirname;
|
|
552
|
+
basename: typeof basename;
|
|
553
|
+
extname: typeof extname;
|
|
554
|
+
relative: typeof relative;
|
|
555
|
+
parse: typeof parse;
|
|
556
|
+
format: typeof format;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
declare const path_basename: typeof basename;
|
|
560
|
+
declare const path_delimiter: typeof delimiter;
|
|
561
|
+
declare const path_dirname: typeof dirname;
|
|
562
|
+
declare const path_extname: typeof extname;
|
|
563
|
+
declare const path_format: typeof format;
|
|
564
|
+
declare const path_isAbsolute: typeof isAbsolute;
|
|
565
|
+
declare const path_join: typeof join;
|
|
566
|
+
declare const path_normalize: typeof normalize;
|
|
567
|
+
declare const path_parse: typeof parse;
|
|
568
|
+
declare const path_posix: typeof posix;
|
|
569
|
+
declare const path_relative: typeof relative;
|
|
570
|
+
declare const path_resolve: typeof resolve;
|
|
571
|
+
declare const path_sep: typeof sep;
|
|
572
|
+
declare namespace path {
|
|
573
|
+
export { path_basename as basename, posix as default, path_delimiter as delimiter, path_dirname as dirname, path_extname as extname, path_format as format, path_isAbsolute as isAbsolute, path_join as join, path_normalize as normalize, path_parse as parse, path_posix as posix, path_relative as relative, path_resolve as resolve, path_sep as sep };
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* OPFS-FS: Battle-tested OPFS-based Node.js fs polyfill
|
|
578
|
+
*
|
|
579
|
+
* Provides a Node.js-compatible filesystem API that works in browsers using OPFS.
|
|
580
|
+
*
|
|
581
|
+
* Features:
|
|
582
|
+
* - Synchronous API: fs.readFileSync, fs.writeFileSync, etc. (requires crossOriginIsolated)
|
|
583
|
+
* - Async Promises API: fs.promises.readFile, fs.promises.writeFile, etc.
|
|
584
|
+
* - Cross-tab safety via navigator.locks
|
|
585
|
+
*
|
|
586
|
+
* Performance Tiers:
|
|
587
|
+
* - Tier 1 (Sync): SharedArrayBuffer + Atomics - requires crossOriginIsolated (COOP/COEP headers)
|
|
588
|
+
* - Tier 2 (Async): Promises API - always available
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```typescript
|
|
592
|
+
* import { fs } from '@componentor/fs';
|
|
593
|
+
*
|
|
594
|
+
* // Sync API (requires crossOriginIsolated)
|
|
595
|
+
* fs.writeFileSync('/hello.txt', 'Hello World!');
|
|
596
|
+
* const data = fs.readFileSync('/hello.txt', 'utf8');
|
|
597
|
+
*
|
|
598
|
+
* // Async API (always available)
|
|
599
|
+
* await fs.promises.writeFile('/async.txt', 'Async data');
|
|
600
|
+
* const content = await fs.promises.readFile('/async.txt', 'utf8');
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
|
|
604
|
+
declare const fs: OPFSFileSystem;
|
|
605
|
+
|
|
606
|
+
export { type Dirent, type Encoding, FSError, type FileSystemPromises, type MkdirOptions, OPFSFileSystem, type PathLike, type ReadOptions, type ReaddirOptions, type RmOptions, type RmdirOptions, type Stats, type WriteOptions, constants, createEACCES, createEEXIST, createEINVAL, createEISDIR, createENOENT, createENOTDIR, createENOTEMPTY, fs as default, fs, mapErrorCode, path };
|