opfs-worker 0.1.1

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline.cjs","sources":["../src/inline.ts"],"sourcesContent":["/**\n * Inline worker export for factory-based worker creation\n * \n * This export provides a factory function that creates worker instances with Comlink wrapping.\n * Use this when you want a simple, ready-to-use file system interface.\n * \n * @example\n * ```typescript\n * import { createWorker } from 'opfs-worker/inline-worker';\n * \n * const fs = await createWorker();\n * await fs.writeFile('/test.txt', 'Hello World');\n * ```\n */\n\nimport { wrap, type Remote } from 'comlink';\n\nimport WorkerCtor from './opfs.worker?worker&inline';\n\nimport type { OPFSWorker } from './types';\n\nexport * from './types';\n\nexport type RemoteOPFSWorker = Remote<OPFSWorker>;\n\n/**\n * Creates a new file system instance with inline worker\n * @returns Promise resolving to the file system interface\n */\nexport async function createWorker(): Promise<RemoteOPFSWorker> {\n return wrap<OPFSWorker>(new WorkerCtor());\n}\n"],"names":["createWorker","wrap","WorkerCtor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qdA6BA,eAAsBA,GAA0C,CAC5D,OAAOC,EAAAA,KAAiB,IAAIC,CAAY,CAC5C"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Inline worker export for factory-based worker creation
3
+ *
4
+ * This export provides a factory function that creates worker instances with Comlink wrapping.
5
+ * Use this when you want a simple, ready-to-use file system interface.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { createWorker } from 'opfs-worker/inline-worker';
10
+ *
11
+ * const fs = await createWorker();
12
+ * await fs.writeFile('/test.txt', 'Hello World');
13
+ * ```
14
+ */
15
+ import { type Remote } from 'comlink';
16
+ import type { OPFSWorker } from './types';
17
+ export * from './types';
18
+ export type RemoteOPFSWorker = Remote<OPFSWorker>;
19
+ /**
20
+ * Creates a new file system instance with inline worker
21
+ * @returns Promise resolving to the file system interface
22
+ */
23
+ export declare function createWorker(): Promise<RemoteOPFSWorker>;
24
+ //# sourceMappingURL=inline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../src/inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,cAAc,SAAS,CAAC;AAExB,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAElD;;;GAGG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAE9D"}
package/dist/inline.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Inline worker export for factory-based worker creation
3
+ *
4
+ * This export provides a factory function that creates worker instances with Comlink wrapping.
5
+ * Use this when you want a simple, ready-to-use file system interface.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { createWorker } from 'opfs-worker/inline-worker';
10
+ *
11
+ * const fs = await createWorker();
12
+ * await fs.writeFile('/test.txt', 'Hello World');
13
+ * ```
14
+ */
15
+ import { wrap } from 'comlink';
16
+ import WorkerCtor from './opfs.worker?worker&inline';
17
+ export * from './types';
18
+ /**
19
+ * Creates a new file system instance with inline worker
20
+ * @returns Promise resolving to the file system interface
21
+ */
22
+ export async function createWorker() {
23
+ return wrap(new WorkerCtor());
24
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline.js","sources":["../src/inline.ts"],"sourcesContent":["/**\n * Inline worker export for factory-based worker creation\n * \n * This export provides a factory function that creates worker instances with Comlink wrapping.\n * Use this when you want a simple, ready-to-use file system interface.\n * \n * @example\n * ```typescript\n * import { createWorker } from 'opfs-worker/inline-worker';\n * \n * const fs = await createWorker();\n * await fs.writeFile('/test.txt', 'Hello World');\n * ```\n */\n\nimport { wrap, type Remote } from 'comlink';\n\nimport WorkerCtor from './opfs.worker?worker&inline';\n\nimport type { OPFSWorker } from './types';\n\nexport * from './types';\n\nexport type RemoteOPFSWorker = Remote<OPFSWorker>;\n\n/**\n * Creates a new file system instance with inline worker\n * @returns Promise resolving to the file system interface\n */\nexport async function createWorker(): Promise<RemoteOPFSWorker> {\n return wrap<OPFSWorker>(new WorkerCtor());\n}\n"],"names":["createWorker","wrap","WorkerCtor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,eAAsBA,IAA0C;AAC5D,SAAOC,EAAiB,IAAIC,GAAY;AAC5C;"}
@@ -0,0 +1,447 @@
1
+ import type { DirentData, FileStat } from './types';
2
+ import type { BufferEncoding } from 'typescript';
3
+ /**
4
+ * OPFS (Origin Private File System) File System implementation
5
+ *
6
+ * This class provides a high-level interface for working with the browser's
7
+ * Origin Private File System API, offering file and directory operations
8
+ * similar to Node.js fs module.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const fs = new OPFSFileSystem();
13
+ * await fs.init('/my-app');
14
+ * await fs.writeFile('/data/config.json', JSON.stringify({ theme: 'dark' }));
15
+ * const config = await fs.readFile('/data/config.json');
16
+ * ```
17
+ */
18
+ export declare class OPFSWorker {
19
+ /** Root directory handle for the file system */
20
+ private root;
21
+ /**
22
+ * Creates a new OPFSFileSystem instance
23
+ *
24
+ * @throws {OPFSError} If OPFS is not supported in the current browser
25
+ */
26
+ constructor();
27
+ /**
28
+ * Initialize the file system within a given directory
29
+ *
30
+ * This method sets up the root directory for all subsequent operations.
31
+ * It must be called before any other file system operations.
32
+ *
33
+ * @param root - The root path for the file system (default: '/')
34
+ * @returns Promise that resolves to true if initialization was successful
35
+ * @throws {OPFSError} If initialization fails
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const fs = new OPFSFileSystem();
40
+ * const success = await fs.init('/my-app');
41
+ * ```
42
+ */
43
+ mount(root?: string): Promise<boolean>;
44
+ /**
45
+ * Get a directory handle from a path
46
+ *
47
+ * Navigates through the directory structure to find or create a directory
48
+ * at the specified path.
49
+ *
50
+ * @param path - The path to the directory (string or array of segments)
51
+ * @param create - Whether to create the directory if it doesn't exist (default: false)
52
+ * @param from - The directory to start from (default: root directory)
53
+ * @returns Promise that resolves to the directory handle
54
+ * @throws {OPFSError} If the directory cannot be accessed or created
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const docsDir = await fs.getDirectoryHandle('/users/john/documents', true);
59
+ * const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
60
+ * ```
61
+ */
62
+ private getDirectoryHandle;
63
+ /**
64
+ * Get a file handle from a path
65
+ *
66
+ * Navigates to the parent directory and retrieves or creates a file handle
67
+ * for the specified file path.
68
+ *
69
+ * @param path - The path to the file (string or array of segments)
70
+ * @param create - Whether to create the file if it doesn't exist (default: false)
71
+ * @param from - The directory to start from (default: root directory)
72
+ * @returns Promise that resolves to the file handle
73
+ * @throws {PathError} If the path is empty
74
+ * @throws {OPFSError} If the file cannot be accessed or created
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const fileHandle = await fs.getFileHandle('/config/settings.json', true);
79
+ * const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
80
+ * ```
81
+ */
82
+ private getFileHandle;
83
+ /**
84
+ * Recursively list all files and directories with their stats
85
+ *
86
+ * Traverses the entire file system starting from the root and returns
87
+ * a Map containing all paths and their corresponding file statistics.
88
+ *
89
+ * @param options - Options for indexing
90
+ * @param options.includeHash - Whether to calculate file hash (default: false)
91
+ * @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)
92
+ * @returns Promise that resolves to a Map of path => FileStat
93
+ * @throws {OPFSError} If the indexing operation fails
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * // Basic index without hash
98
+ * const index = await fs.index();
99
+ *
100
+ * // Index with file hash
101
+ * const indexWithHash = await fs.index({
102
+ * includeHash: true,
103
+ * hashAlgorithm: 'SHA-1'
104
+ * });
105
+ *
106
+ * // Iterate through all files and directories
107
+ * for (const [path, stat] of index) {
108
+ * console.log(`${path}: ${stat.isFile ? 'file' : 'directory'} (${stat.size} bytes)`);
109
+ * if (stat.hash) console.log(` Hash: ${stat.hash}`);
110
+ * }
111
+ *
112
+ * // Get specific file stats
113
+ * const fileStats = index.get('/data/config.json');
114
+ * if (fileStats) {
115
+ * console.log(`File size: ${fileStats.size} bytes`);
116
+ * if (fileStats.hash) console.log(`Hash: ${fileStats.hash}`);
117
+ * }
118
+ * ```
119
+ */
120
+ index(options?: {
121
+ includeHash?: boolean;
122
+ hashAlgorithm?: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
123
+ }): Promise<Map<string, FileStat>>;
124
+ /**
125
+ * Read a file from the file system
126
+ *
127
+ * Reads the contents of a file and returns it as a string or binary data
128
+ * depending on the specified encoding.
129
+ *
130
+ * @param path - The path to the file to read
131
+ * @param encoding - The encoding to use for reading the file
132
+ * @returns Promise that resolves to the file contents
133
+ * @throws {FileNotFoundError} If the file does not exist
134
+ * @throws {OPFSError} If reading the file fails
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // Read as text
139
+ * const content = await fs.readFile('/config/settings.json');
140
+ *
141
+ * // Read as binary
142
+ * const binaryData = await fs.readFile('/images/logo.png', 'binary');
143
+ *
144
+ * // Read with specific encoding
145
+ * const utf8Content = await fs.readFile('/data/utf8.txt', 'utf-8');
146
+ * ```
147
+ */
148
+ readFile(path: string, encoding: 'binary'): Promise<Uint8Array>;
149
+ readFile(path: string, encoding?: BufferEncoding): Promise<string>;
150
+ /**
151
+ * Write data to a file
152
+ *
153
+ * Creates or overwrites a file with the specified data. If the file already
154
+ * exists, it will be truncated before writing.
155
+ *
156
+ * @param path - The path to the file to write
157
+ * @param data - The data to write to the file (string, Uint8Array, or ArrayBuffer)
158
+ * @param encoding - The encoding to use when writing string data (default: 'utf-8')
159
+ * @returns Promise that resolves when the write operation is complete
160
+ * @throws {OPFSError} If writing the file fails
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * // Write text data
165
+ * await fs.writeFile('/config/settings.json', JSON.stringify({ theme: 'dark' }));
166
+ *
167
+ * // Write binary data
168
+ * const binaryData = new Uint8Array([1, 2, 3, 4, 5]);
169
+ * await fs.writeFile('/data/binary.dat', binaryData);
170
+ *
171
+ * // Write with specific encoding
172
+ * await fs.writeFile('/data/utf16.txt', 'Hello World', 'utf-16le');
173
+ * ```
174
+ */
175
+ writeFile(path: string, data: string | Uint8Array | ArrayBuffer, encoding?: BufferEncoding): Promise<void>;
176
+ /**
177
+ * Append data to a file
178
+ *
179
+ * Adds data to the end of an existing file. If the file doesn't exist,
180
+ * it will be created.
181
+ *
182
+ * @param path - The path to the file to append to
183
+ * @param data - The data to append to the file (string, Uint8Array, or ArrayBuffer)
184
+ * @param encoding - The encoding to use when appending string data (default: 'utf-8')
185
+ * @returns Promise that resolves when the append operation is complete
186
+ * @throws {OPFSError} If appending to the file fails
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * // Append text to a log file
191
+ * await fs.appendFile('/logs/app.log', `[${new Date().toISOString()}] User logged in\n`);
192
+ *
193
+ * // Append binary data
194
+ * const additionalData = new Uint8Array([6, 7, 8]);
195
+ * await fs.appendFile('/data/binary.dat', additionalData);
196
+ * ```
197
+ */
198
+ appendFile(path: string, data: string | Uint8Array | ArrayBuffer, encoding?: BufferEncoding): Promise<void>;
199
+ /**
200
+ * Create a directory
201
+ *
202
+ * Creates a new directory at the specified path. If the recursive option
203
+ * is enabled, parent directories will be created as needed.
204
+ *
205
+ * @param path - The path where the directory should be created
206
+ * @param options - Options for directory creation
207
+ * @param options.recursive - Whether to create parent directories if they don't exist (default: false)
208
+ * @returns Promise that resolves when the directory is created
209
+ * @throws {OPFSError} If the directory cannot be created
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * // Create a single directory
214
+ * await fs.mkdir('/users/john');
215
+ *
216
+ * // Create nested directories
217
+ * await fs.mkdir('/users/john/documents/projects', { recursive: true });
218
+ * ```
219
+ */
220
+ mkdir(path: string, options?: {
221
+ recursive?: boolean;
222
+ }): Promise<void>;
223
+ /**
224
+ * Get file or directory stats
225
+ *
226
+ * Retrieves metadata about a file or directory, including size, modification time,
227
+ * type information, and optionally file hashes.
228
+ *
229
+ * @param path - The path to the file or directory
230
+ * @param options - Options for stat operation
231
+ * @param options.includeHash - Whether to calculate file hash (default: false, only for files)
232
+ * @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)
233
+ * @returns Promise that resolves to file/directory statistics
234
+ * @throws {OPFSError} If the file or directory does not exist or cannot be accessed
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * // Basic stats
239
+ * const stats = await fs.stat('/config/settings.json');
240
+ * console.log(`File size: ${stats.size} bytes`);
241
+ * console.log(`Is file: ${stats.isFile}`);
242
+ * console.log(`Modified: ${stats.mtime}`);
243
+ *
244
+ * // Stats with hash (SHA-1 is fastest)
245
+ * const statsWithHash = await fs.stat('/config/settings.json', {
246
+ * includeHash: true,
247
+ * hashAlgorithm: 'SHA-1'
248
+ * });
249
+ * console.log(`Hash: ${statsWithHash.hash}`);
250
+ * ```
251
+ */
252
+ stat(path: string, options?: {
253
+ includeHash?: boolean;
254
+ hashAlgorithm?: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
255
+ }): Promise<FileStat>;
256
+ /**
257
+ * Read a directory's contents
258
+ *
259
+ * Lists all files and subdirectories within the specified directory.
260
+ *
261
+ * @param path - The path to the directory to read
262
+ * @param options - Options for the readdir operation
263
+ * @param options.withFileTypes - Whether to return detailed file information (default: false)
264
+ * @returns Promise that resolves to an array of file/directory names or detailed information
265
+ * @throws {OPFSError} If the directory does not exist or cannot be accessed
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * // Get simple list of names
270
+ * const files = await fs.readdir('/users/john/documents');
271
+ * console.log('Files:', files); // ['readme.txt', 'config.json', 'images']
272
+ *
273
+ * // Get detailed information
274
+ * const detailed = await fs.readdir('/users/john/documents', { withFileTypes: true });
275
+ * detailed.forEach(item => {
276
+ * console.log(`${item.name} - ${item.isFile ? 'file' : 'directory'}`);
277
+ * });
278
+ * ```
279
+ */
280
+ readdir(path: string): Promise<string[]>;
281
+ readdir(path: string, options: {
282
+ withFileTypes: true;
283
+ }): Promise<DirentData[]>;
284
+ readdir(path: string, options: {
285
+ withFileTypes: false;
286
+ }): Promise<string[]>;
287
+ /**
288
+ * Check if a file or directory exists
289
+ *
290
+ * Verifies if a file or directory exists at the specified path.
291
+ *
292
+ * @param path - The path to check
293
+ * @returns Promise that resolves to true if the file or directory exists, false otherwise
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * const exists = await fs.exists('/config/settings.json');
298
+ * console.log(`File exists: ${exists}`);
299
+ * ```
300
+ */
301
+ exists(path: string): Promise<boolean>;
302
+ /**
303
+ * Clear all contents of a directory without removing the directory itself
304
+ *
305
+ * Removes all files and subdirectories within the specified directory,
306
+ * but keeps the directory itself.
307
+ *
308
+ * @param path - The path to the directory to clear (default: '/')
309
+ * @returns Promise that resolves when all contents are removed
310
+ * @throws {OPFSError} If the operation fails
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * // Clear root directory contents
315
+ * await fs.clear('/');
316
+ *
317
+ * // Clear specific directory contents
318
+ * await fs.clear('/data');
319
+ * ```
320
+ */
321
+ clear(path?: string): Promise<void>;
322
+ /**
323
+ * Remove files and directories
324
+ *
325
+ * Removes files and directories. Similar to Node.js fs.rm().
326
+ *
327
+ * @param path - The path to remove
328
+ * @param options - Options for removal
329
+ * @param options.recursive - Whether to remove directories and their contents recursively (default: false)
330
+ * @param options.force - Whether to ignore errors if the path doesn't exist (default: false)
331
+ * @returns Promise that resolves when the removal is complete
332
+ * @throws {OPFSError} If the removal fails
333
+ *
334
+ * @example
335
+ * ```typescript
336
+ * // Remove a file
337
+ * await fs.rm('/path/to/file.txt');
338
+ *
339
+ * // Remove a directory and all its contents
340
+ * await fs.rm('/path/to/directory', { recursive: true });
341
+ *
342
+ * // Remove with force (ignore if doesn't exist)
343
+ * await fs.rm('/maybe/exists', { force: true });
344
+ * ```
345
+ */
346
+ remove(path: string, options?: {
347
+ recursive?: boolean;
348
+ force?: boolean;
349
+ }): Promise<void>;
350
+ /**
351
+ * Resolve a path to an absolute path
352
+ *
353
+ * Resolves relative paths and normalizes path segments (like '..' and '.').
354
+ * Similar to Node.js fs.realpath() but without symlink resolution since OPFS doesn't support symlinks.
355
+ *
356
+ * @param path - The path to resolve
357
+ * @returns Promise that resolves to the absolute normalized path
358
+ * @throws {FileNotFoundError} If the path does not exist
359
+ * @throws {OPFSError} If path resolution fails
360
+ *
361
+ * @example
362
+ * ```typescript
363
+ * // Resolve relative path
364
+ * const absolute = await fs.realpath('./config/../data/file.txt');
365
+ * console.log(absolute); // '/data/file.txt'
366
+ * ```
367
+ */
368
+ realpath(path: string): Promise<string>;
369
+ /**
370
+ * Rename a file or directory
371
+ *
372
+ * Changes the name of a file or directory. If the target path already exists,
373
+ * it will be replaced.
374
+ *
375
+ * @param oldPath - The current path of the file or directory
376
+ * @param newPath - The new path for the file or directory
377
+ * @returns Promise that resolves when the rename operation is complete
378
+ * @throws {OPFSError} If the rename operation fails
379
+ *
380
+ * @example
381
+ * ```typescript
382
+ * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
383
+ * ```
384
+ */
385
+ rename(oldPath: string, newPath: string): Promise<void>;
386
+ /**
387
+ * Copy files and directories
388
+ *
389
+ * Copies files and directories. Similar to Node.js fs.cp().
390
+ *
391
+ * @param source - The source path to copy from
392
+ * @param destination - The destination path to copy to
393
+ * @param options - Options for copying
394
+ * @param options.recursive - Whether to copy directories recursively (default: false)
395
+ * @param options.force - Whether to overwrite existing files (default: true)
396
+ * @returns Promise that resolves when the copy operation is complete
397
+ * @throws {OPFSError} If the copy operation fails
398
+ *
399
+ * @example
400
+ * ```typescript
401
+ * // Copy a file
402
+ * await fs.cp('/source/file.txt', '/dest/file.txt');
403
+ *
404
+ * // Copy a directory and all its contents
405
+ * await fs.cp('/source/dir', '/dest/dir', { recursive: true });
406
+ *
407
+ * // Copy without overwriting existing files
408
+ * await fs.cp('/source', '/dest', { recursive: true, force: false });
409
+ * ```
410
+ */
411
+ copy(source: string, destination: string, options?: {
412
+ recursive?: boolean;
413
+ force?: boolean;
414
+ }): Promise<void>;
415
+ /**
416
+ * Synchronize the file system with external data
417
+ *
418
+ * Syncs the file system with an array of entries containing paths and data.
419
+ * This is useful for importing data from external sources or syncing with remote data.
420
+ *
421
+ * @param entries - Array of [path, data] tuples to sync
422
+ * @param options - Options for synchronization
423
+ * @param options.cleanBefore - Whether to clear the file system before syncing (default: false)
424
+ * @returns Promise that resolves when synchronization is complete
425
+ * @throws {OPFSError} If the synchronization fails
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * // Sync with external data
430
+ * const entries: [string, string | Uint8Array | Blob][] = [
431
+ * ['/config.json', JSON.stringify({ theme: 'dark' })],
432
+ * ['/data/binary.dat', new Uint8Array([1, 2, 3, 4])],
433
+ * ['/upload.txt', new Blob(['file content'], { type: 'text/plain' })]
434
+ * ];
435
+ *
436
+ * // Sync without clearing existing files
437
+ * await fs.sync(entries);
438
+ *
439
+ * // Clean file system and then sync
440
+ * await fs.sync(entries, { cleanBefore: true });
441
+ * ```
442
+ */
443
+ sync(entries: [string, string | Uint8Array | Blob][], options?: {
444
+ cleanBefore?: boolean;
445
+ }): Promise<void>;
446
+ }
447
+ //# sourceMappingURL=opfs.worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opfs.worker.d.ts","sourceRoot":"","sources":["../src/opfs.worker.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,UAAU;IACnB,gDAAgD;IAChD,OAAO,CAAC,IAAI,CAA0C;IAEtD;;;;OAIG;;IAKH;;;;;;;;;;;;;;;OAeG;IACG,KAAK,CAAC,IAAI,GAAE,MAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAejD;;;;;;;;;;;;;;;;;OAiBG;YACW,kBAAkB;IAehC;;;;;;;;;;;;;;;;;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