opfs-worker 1.3.2 → 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 +89 -106
- package/dist/{facade.d.ts → OPFSFacade.d.ts} +22 -5
- package/dist/OPFSFacade.d.ts.map +1 -0
- package/dist/{worker.d.ts → OPFSWorker.d.ts} +10 -6
- package/dist/OPFSWorker.d.ts.map +1 -0
- package/dist/assets/worker.entry-DUlEoroc.js.map +1 -0
- package/dist/createOPFSWorker.d.ts +17 -0
- package/dist/createOPFSWorker.d.ts.map +1 -0
- package/dist/helpers-DNj8ZoMu.cjs +4 -0
- package/dist/helpers-DNj8ZoMu.cjs.map +1 -0
- package/dist/{helpers-Ca2c767K.js → helpers-WY2jfbOT.js} +221 -221
- package/dist/helpers-WY2jfbOT.js.map +1 -0
- package/dist/index.cjs +296 -285
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +369 -340
- package/dist/index.js.map +1 -1
- package/dist/index.pure.cjs +2 -0
- package/dist/index.pure.cjs.map +1 -0
- package/dist/index.pure.d.ts +6 -0
- package/dist/index.pure.d.ts.map +1 -0
- package/dist/{raw.js → index.pure.js} +241 -186
- package/dist/index.pure.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +11 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.entry.d.ts +2 -0
- package/dist/worker.entry.d.ts.map +1 -0
- package/docs/api-reference.md +815 -0
- package/docs/file-descriptors.md +696 -0
- package/docs/types.md +232 -0
- package/package.json +14 -8
- package/src/OPFSFacade.ts +460 -0
- package/src/OPFSWorker.ts +1544 -0
- package/src/createOPFSWorker.ts +57 -0
- package/src/index.pure.ts +7 -0
- package/src/index.ts +15 -0
- package/src/types.ts +99 -0
- package/src/utils/encoder.ts +205 -0
- package/src/utils/errors.ts +297 -0
- package/src/utils/helpers.ts +465 -0
- package/src/worker.entry.ts +6 -0
- package/dist/assets/worker-1Wh1cr7P.js.map +0 -1
- package/dist/assets/worker-BeJaVyBV.js.map +0 -1
- package/dist/assets/worker-DYYLzR1Y.js.map +0 -1
- package/dist/facade.d.ts.map +0 -1
- package/dist/helpers-BuGfPAg0.js +0 -1439
- package/dist/helpers-BuGfPAg0.js.map +0 -1
- package/dist/helpers-CF7A2WQG.cjs +0 -4
- package/dist/helpers-CF7A2WQG.cjs.map +0 -1
- package/dist/helpers-CIiblZ8d.cjs +0 -4
- package/dist/helpers-CIiblZ8d.cjs.map +0 -1
- package/dist/helpers-CKOebsbw.js +0 -1423
- package/dist/helpers-CKOebsbw.js.map +0 -1
- package/dist/helpers-Ca2c767K.js.map +0 -1
- package/dist/helpers-Dwc92hv9.cjs +0 -4
- package/dist/helpers-Dwc92hv9.cjs.map +0 -1
- package/dist/raw.cjs +0 -2
- package/dist/raw.cjs.map +0 -1
- package/dist/raw.d.ts +0 -13
- package/dist/raw.d.ts.map +0 -1
- package/dist/raw.js.map +0 -1
- package/dist/worker.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OPFS Worker
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
[npm version](https://www.npmjs.com/package/opfs-worker)
|
|
4
4
|
|
|
5
5
|
A robust TypeScript library for working with Origin Private File System (OPFS) through Web Workers, providing a Node.js-like file system API for browser environments.
|
|
6
6
|
|
|
@@ -41,7 +41,7 @@ A robust TypeScript library for working with Origin Private File System (OPFS) t
|
|
|
41
41
|
|
|
42
42
|
- **Complete API**: `readFile`, `writeFile`, `mkdir`, `remove`, `copy`, `rename`, and more
|
|
43
43
|
- **Binary file support**: Handle images, documents, and any binary data seamlessly
|
|
44
|
-
- **Hash support**:
|
|
44
|
+
- **Hash support**: Cheap `etag` by default (`mtime-size`), plus optional content hashes (SHA-1 / SHA-256 / SHA-384 / SHA-512)
|
|
45
45
|
- **File indexing**: Complete file system indexing with metadata and search
|
|
46
46
|
|
|
47
47
|
### 🔄 **Advanced Features**
|
|
@@ -115,37 +115,43 @@ npm install opfs-worker
|
|
|
115
115
|
|
|
116
116
|
**Dependencies:**
|
|
117
117
|
|
|
118
|
-
-
|
|
119
|
-
-
|
|
118
|
+
- Modes 1 and 2 depend on `comlink` (worker communication is handled for you)
|
|
119
|
+
- Mode 3 does not use Comlink — you run the class inside your own worker
|
|
120
|
+
- Modes 1 and 2 ship an inlined worker, so your bundler does not need a `?worker` setup
|
|
120
121
|
|
|
121
122
|
## Quick Start
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
OPFS sync I/O only works inside a dedicated Web Worker. The library covers three common setups:
|
|
124
125
|
|
|
125
|
-
|
|
126
|
+
| | Import | Best when |
|
|
127
|
+
| ---------- | --------------------------------------- | ----------------------------------------------------------------- |
|
|
128
|
+
| **Mode 1** | `createOPFS()` from `opfs-worker` | You want a Node-like `fs` API on the main thread |
|
|
129
|
+
| **Mode 2** | `createOPFSWorker()` from `opfs-worker` | You want the low-level worker API, but still from the main thread |
|
|
130
|
+
| **Mode 3** | `OPFSWorker` from `opfs-worker/pure` | Your code already runs inside a worker |
|
|
126
131
|
|
|
127
|
-
|
|
132
|
+
Modes 1 and 2 both pull Comlink. Mode 3 does not.
|
|
133
|
+
|
|
134
|
+
### Mode 1: Node-like facade (recommended)
|
|
135
|
+
|
|
136
|
+
The usual path. `createOPFS()` starts an inlined worker and returns a facade with a Node-like API — strings, encodings, auto-detection. Comlink stays under the hood.
|
|
137
|
+
|
|
138
|
+
> 1.x alias: `createWorker` still works and returns the same facade — prefer `createOPFS`.
|
|
128
139
|
|
|
129
140
|
```typescript
|
|
130
|
-
import {
|
|
141
|
+
import { createOPFS } from 'opfs-worker';
|
|
131
142
|
|
|
132
143
|
async function basicExample() {
|
|
133
|
-
|
|
134
|
-
const fs = await createWorker();
|
|
144
|
+
const fs = createOPFS();
|
|
135
145
|
|
|
136
|
-
// Write a file
|
|
137
146
|
await fs.writeFile('/config.json', JSON.stringify({ theme: 'dark' }));
|
|
138
|
-
|
|
139
|
-
// Read the file back
|
|
140
147
|
const config = await fs.readFile('/config.json');
|
|
141
|
-
console.log(JSON.parse(config));
|
|
148
|
+
console.log(JSON.parse(config as string));
|
|
142
149
|
}
|
|
143
150
|
|
|
144
|
-
// Extended example with all options
|
|
145
151
|
async function extendedExample() {
|
|
146
152
|
const broadcastChannel = new BroadcastChannel('my-app-events');
|
|
147
153
|
|
|
148
|
-
const fs =
|
|
154
|
+
const fs = createOPFS({
|
|
149
155
|
root: '/my-app',
|
|
150
156
|
namespace: 'my-app:fs',
|
|
151
157
|
hashAlgorithm: 'SHA-256',
|
|
@@ -153,16 +159,13 @@ async function extendedExample() {
|
|
|
153
159
|
broadcastChannel
|
|
154
160
|
});
|
|
155
161
|
|
|
156
|
-
|
|
157
|
-
const imageData = new Uint8Array([58, /* binary data */]);
|
|
162
|
+
const imageData = new Uint8Array([58 /* binary data */]);
|
|
158
163
|
await fs.writeFile('/image.png', imageData);
|
|
159
164
|
const binaryData = await fs.readFile('/image.png', 'binary');
|
|
160
165
|
|
|
161
|
-
// Text files are automatically handled
|
|
162
166
|
await fs.writeFile('/config.txt', 'Hello, World!');
|
|
163
|
-
const textContent = await fs.readFile('/config.txt'); //
|
|
167
|
+
const textContent = await fs.readFile('/config.txt'); // string
|
|
164
168
|
|
|
165
|
-
// Use file watching with BroadcastChannel
|
|
166
169
|
await fs.watch('/', {
|
|
167
170
|
recursive: true,
|
|
168
171
|
include: ['*.json'],
|
|
@@ -170,97 +173,85 @@ async function extendedExample() {
|
|
|
170
173
|
});
|
|
171
174
|
|
|
172
175
|
broadcastChannel.onmessage = (event) => {
|
|
173
|
-
console.log(
|
|
176
|
+
console.log('File changed:', event.data);
|
|
174
177
|
};
|
|
175
178
|
|
|
176
|
-
// Get file statistics with hashing
|
|
177
179
|
const stats = await fs.stat('/image.png');
|
|
178
|
-
|
|
179
|
-
console.log(
|
|
180
|
-
`File size: ${stats.size} bytes`,
|
|
181
|
-
`Hash: ${stats.hash}`
|
|
182
|
-
);
|
|
180
|
+
console.log(`File size: ${stats.size} bytes`, `Hash: ${stats.hash}`);
|
|
183
181
|
}
|
|
184
182
|
```
|
|
185
183
|
|
|
186
|
-
>
|
|
184
|
+
> Watch events go over `BroadcastChannel` (default name `opfs-worker`). Pass `broadcastChannel` to customize. Only watched paths emit events.
|
|
187
185
|
|
|
188
|
-
###
|
|
186
|
+
### Mode 2: Raw worker API from the main thread
|
|
189
187
|
|
|
190
|
-
|
|
188
|
+
Same package entry, same inlined worker but without the facade. You get a Comlink proxy to `OPFSWorker`: bytes in, bytes out. Useful if you want to wrap it yourself or prefer the lower-level API.
|
|
191
189
|
|
|
192
190
|
```typescript
|
|
193
|
-
import
|
|
194
|
-
import { wrap } from 'comlink';
|
|
191
|
+
import { createOPFSWorker } from 'opfs-worker';
|
|
195
192
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
const { fs, dispose } = createOPFSWorker({
|
|
194
|
+
root: '/my-app',
|
|
195
|
+
namespace: 'my-app:fs',
|
|
196
|
+
hashAlgorithm: 'SHA-256',
|
|
197
|
+
maxFileSize: 100 * 1024 * 1024,
|
|
198
|
+
broadcastChannel: 'my-app-events',
|
|
199
|
+
});
|
|
199
200
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
console.log(JSON.parse(config));
|
|
204
|
-
}
|
|
201
|
+
await fs.writeFile('/config.json', new TextEncoder().encode(JSON.stringify({ theme: 'dark' })));
|
|
202
|
+
const bytes = await fs.readFile('/config.json');
|
|
203
|
+
console.log(JSON.parse(new TextDecoder().decode(bytes)));
|
|
205
204
|
|
|
206
|
-
//
|
|
207
|
-
|
|
208
|
-
// Create with all available options
|
|
209
|
-
const worker = wrap(new OPFSWorker({
|
|
210
|
-
root: '/my-app',
|
|
211
|
-
namespace: 'my-app:fs',
|
|
212
|
-
hashAlgorithm: 'SHA-256',
|
|
213
|
-
maxFileSize: 100 * 1024 * 1024, // 100MB
|
|
214
|
-
broadcastChannel: 'my-app-events' // You can't pass a BroadcastChannel instance to the worker, so you must use a broadcast channel name here
|
|
215
|
-
}));
|
|
216
|
-
|
|
217
|
-
// Bulk sync from external data
|
|
218
|
-
const entries = [
|
|
219
|
-
['/data/config.json', JSON.stringify({ version: '1.0' })],
|
|
220
|
-
['/data/users.json', JSON.stringify([{ id: 1, name: 'John' }])]
|
|
221
|
-
];
|
|
222
|
-
await worker.sync(entries, { cleanBefore: true });
|
|
205
|
+
dispose(); // worker.dispose() + terminate()
|
|
206
|
+
```
|
|
223
207
|
|
|
224
|
-
|
|
225
|
-
await worker.mkdir('/data/logs', { recursive: true });
|
|
208
|
+
> Want your own facade? Our `OPFSFacade` is built on `createOPFSWorker` — copy [`src/OPFSFacade.ts`](src/OPFSFacade.ts), swap the imports to `opfs-worker` and change what you need.
|
|
226
209
|
|
|
227
|
-
|
|
228
|
-
const logEntry = new TextEncoder().encode(`${new Date().toISOString()}: App started\n`);
|
|
229
|
-
await worker.appendFile('/data/logs/app.log', logEntry);
|
|
210
|
+
### Mode 3: `OPFSWorker` inside your own worker
|
|
230
211
|
|
|
231
|
-
|
|
232
|
-
await worker.watch('/data', { recursive: true });
|
|
212
|
+
If you already have a worker (or want full control over it), import the class and use it directly. No nested worker, no Comlink. Bundling that worker and talking to the main thread — if you need that at all — is up to you.
|
|
233
213
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
214
|
+
```typescript
|
|
215
|
+
// my-app.worker.ts (this file IS the worker)
|
|
216
|
+
import { OPFSWorker } from 'opfs-worker/pure';
|
|
217
|
+
|
|
218
|
+
const fs = new OPFSWorker({
|
|
219
|
+
root: '/my-app',
|
|
220
|
+
namespace: 'my-app:fs',
|
|
221
|
+
hashAlgorithm: 'SHA-256',
|
|
222
|
+
broadcastChannel: 'my-app-events', // name only — BroadcastChannel instances can't cross the wire
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
await fs.writeFile('/config.json', new TextEncoder().encode(JSON.stringify({ theme: 'dark' })));
|
|
226
|
+
const bytes = await fs.readFile('/config.json');
|
|
227
|
+
console.log(JSON.parse(new TextDecoder().decode(bytes)));
|
|
239
228
|
```
|
|
240
229
|
|
|
241
|
-
|
|
230
|
+
`opfs-worker/pure` does not call Comlink `expose()`, so it will not take over your worker's message port.
|
|
242
231
|
|
|
243
232
|
### Hash Algorithm Configuration
|
|
244
233
|
|
|
245
|
-
|
|
234
|
+
Set once via options / `setOptions()` — used by `stat()`, `index()`, and watch events.
|
|
235
|
+
|
|
236
|
+
Default is `'etag'`: a cheap weak tag from `File.lastModified` + size (no content read). Switch to a SHA algorithm when you need a real content hash.
|
|
246
237
|
|
|
247
238
|
```typescript
|
|
248
|
-
import {
|
|
239
|
+
import { createOPFS } from 'opfs-worker';
|
|
249
240
|
|
|
250
241
|
async function hashExample() {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
// Enable SHA-256 hashing globally
|
|
254
|
-
fs.setOptions({ hashAlgorithm: 'SHA-256' });
|
|
255
|
-
|
|
256
|
-
// Write a file
|
|
242
|
+
// Default: etag (fast, no content read)
|
|
243
|
+
const fs = createOPFS();
|
|
257
244
|
await fs.writeFile('/data.txt', 'Hello World');
|
|
258
245
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
246
|
+
const etagStat = await fs.stat('/data.txt');
|
|
247
|
+
console.log(`ETag: ${etagStat.hash}`); // e.g. "m1abc-c" (mtime36-size36)
|
|
248
|
+
|
|
249
|
+
// Opt into a cryptographic content hash
|
|
250
|
+
await fs.setOptions({ hashAlgorithm: 'SHA-256' });
|
|
251
|
+
const shaStat = await fs.stat('/data.txt');
|
|
252
|
+
console.log(`SHA-256: ${shaStat.hash}`);
|
|
262
253
|
|
|
263
|
-
//
|
|
254
|
+
// Index / watch events also include hash when enabled
|
|
264
255
|
const index = await fs.index();
|
|
265
256
|
for (const [path, stat] of index) {
|
|
266
257
|
if (stat.isFile && stat.hash) {
|
|
@@ -268,7 +259,6 @@ async function hashExample() {
|
|
|
268
259
|
}
|
|
269
260
|
}
|
|
270
261
|
|
|
271
|
-
// Watch events will also include hash information
|
|
272
262
|
const channel = new BroadcastChannel('opfs-worker');
|
|
273
263
|
channel.onmessage = (event) => {
|
|
274
264
|
if (event.data.hash) {
|
|
@@ -277,52 +267,45 @@ async function hashExample() {
|
|
|
277
267
|
};
|
|
278
268
|
}
|
|
279
269
|
|
|
280
|
-
//
|
|
270
|
+
// maxFileSize only applies to SHA-* (content) hashing — etag ignores it
|
|
281
271
|
async function maxFileSizeExample() {
|
|
282
|
-
const fs =
|
|
283
|
-
|
|
284
|
-
// Set custom maximum file size (100MB instead of default 50MB)
|
|
285
|
-
fs.setOptions({
|
|
272
|
+
const fs = createOPFS({
|
|
286
273
|
hashAlgorithm: 'SHA-256',
|
|
287
|
-
maxFileSize: 100 * 1024 * 1024 // 100MB
|
|
274
|
+
maxFileSize: 100 * 1024 * 1024 // 100MB (default 50MB)
|
|
288
275
|
});
|
|
289
276
|
|
|
290
|
-
// Files up to 100MB will be hashed
|
|
291
|
-
// Files larger than this will not have hash information
|
|
292
277
|
const stats = await fs.stat('/large-file.dat');
|
|
293
278
|
if (stats.hash) {
|
|
294
279
|
console.log(`Hash: ${stats.hash}`);
|
|
295
280
|
} else {
|
|
296
|
-
console.log('File too large for hashing');
|
|
281
|
+
console.log('File too large for content hashing');
|
|
297
282
|
}
|
|
298
283
|
}
|
|
299
284
|
```
|
|
300
285
|
|
|
301
286
|
**Supported Hash Algorithms:**
|
|
302
287
|
|
|
303
|
-
- `'
|
|
304
|
-
- `'SHA-256'` -
|
|
305
|
-
- `
|
|
306
|
-
- `'SHA-512'` - Highest security
|
|
307
|
-
- `null` - Disable hashing for maximum performance
|
|
288
|
+
- `'etag'` — **default**. Weak tag from mtime + size; free, no content read
|
|
289
|
+
- `'SHA-1'` / `'SHA-256'` / `'SHA-384'` / `'SHA-512'` — content hashes via Web Crypto (bounded by `maxFileSize`)
|
|
290
|
+
- `null` / `false` — disable hashing
|
|
308
291
|
|
|
309
|
-
**Note:**
|
|
292
|
+
**Note:** Prefer `'etag'` for watch / change-detection. Use SHA only when you need integrity of file bytes. Set to `null`/`false` if you don't need `hash` at all.
|
|
310
293
|
|
|
311
294
|
### Root Path Configuration
|
|
312
295
|
|
|
313
296
|
The file system supports configuring the root path through options. The root path determines where in OPFS the file system's root will be created. All file paths passed to the API are relative to this root path.
|
|
314
297
|
|
|
315
298
|
```typescript
|
|
316
|
-
import {
|
|
299
|
+
import { createOPFS } from 'opfs-worker';
|
|
317
300
|
|
|
318
301
|
async function rootPathExample() {
|
|
319
302
|
// Use default root path '/'
|
|
320
|
-
const fsDefault =
|
|
303
|
+
const fsDefault = createOPFS();
|
|
321
304
|
await fsDefault.writeFile('/config.json', '{}');
|
|
322
305
|
// This creates /config.json in OPFS root
|
|
323
306
|
|
|
324
307
|
// Use custom root path
|
|
325
|
-
const fsCustom =
|
|
308
|
+
const fsCustom = createOPFS({ root: '/my-app' });
|
|
326
309
|
await fsCustom.writeFile('/config.json', '{}');
|
|
327
310
|
// This creates /my-app/config.json in OPFS root
|
|
328
311
|
|
|
@@ -360,9 +343,10 @@ The complete API reference is available in the [docs/api-reference.md](docs/api-
|
|
|
360
343
|
|
|
361
344
|
**Entry Points:**
|
|
362
345
|
|
|
363
|
-
- `
|
|
364
|
-
- `
|
|
365
|
-
- `OPFSWorker` -
|
|
346
|
+
- `createOPFS(options?)` — Mode 1: Node-like facade on the main thread
|
|
347
|
+
- `createOPFSWorker(options?)` — Mode 2: raw `OPFSWorker` proxy on the main thread
|
|
348
|
+
- `OPFSWorker` from `opfs-worker/pure` — Mode 3: use the class inside your own worker
|
|
349
|
+
- `OPFSFacade` — Mode 1 class returned by `createOPFS`
|
|
366
350
|
|
|
367
351
|
**Core File Operations:**
|
|
368
352
|
|
|
@@ -462,7 +446,6 @@ npm run test:coverage
|
|
|
462
446
|
|
|
463
447
|
```bash
|
|
464
448
|
npm run lint
|
|
465
|
-
npm run lint:fix
|
|
466
449
|
```
|
|
467
450
|
|
|
468
451
|
## License
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { BinaryEncoding, DirentData, Encoding, FileOpenOptions, FileStat, OPFSOptions, PathLike, RenameOptions, StringEncoding, WatchOptions } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Mode 1: Node-like facade with encoding helpers and string/binary auto-detection,
|
|
4
|
+
* built on top of the raw worker API from {@link createOPFSWorker}.
|
|
5
|
+
*
|
|
6
|
+
* Use {@link createOPFS} to create one.
|
|
5
7
|
*/
|
|
6
|
-
export declare class
|
|
8
|
+
export declare class OPFSFacade {
|
|
7
9
|
#private;
|
|
8
|
-
promises:
|
|
10
|
+
promises: OPFSFacade;
|
|
9
11
|
constructor(options?: OPFSOptions);
|
|
10
12
|
/**
|
|
11
13
|
* Start watching a file or directory for changes
|
|
@@ -172,4 +174,19 @@ export declare class OPFSFileSystem {
|
|
|
172
174
|
*/
|
|
173
175
|
dispose(): void;
|
|
174
176
|
}
|
|
175
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Mode 1: start an inlined worker and get a Node-like `fs` API on top of it.
|
|
179
|
+
*
|
|
180
|
+
* For the raw worker API without the facade, use {@link createOPFSWorker}.
|
|
181
|
+
* To use the worker class inside your own worker, see `opfs-worker/pure`.
|
|
182
|
+
*/
|
|
183
|
+
export declare function createOPFS(options?: OPFSOptions): OPFSFacade;
|
|
184
|
+
/**
|
|
185
|
+
* @deprecated Use {@link createOPFS}. Kept for 1.x compatibility — still returns the facade.
|
|
186
|
+
*/
|
|
187
|
+
export declare const createWorker: typeof createOPFS;
|
|
188
|
+
/**
|
|
189
|
+
* @deprecated Use {@link OPFSFacade}.
|
|
190
|
+
*/
|
|
191
|
+
export { OPFSFacade as OPFSFileSystem };
|
|
192
|
+
//# sourceMappingURL=OPFSFacade.d.ts.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,MAAM,YAAY,mBAAa,CAAC;AAEvC;;GAEG;AACH,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -8,9 +8,8 @@ import type { DirentData, FileOpenOptions, FileStat, OPFSOptions, RenameOptions,
|
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
|
-
* const fs = new
|
|
12
|
-
* await fs.
|
|
13
|
-
* await fs.writeFile('/data/config.json', JSON.stringify({ theme: 'dark' }));
|
|
11
|
+
* const fs = new OPFSWorker();
|
|
12
|
+
* await fs.writeFile('/data/config.json', new TextEncoder().encode(JSON.stringify({ theme: 'dark' })));
|
|
14
13
|
* const config = await fs.readFile('/data/config.json');
|
|
15
14
|
* ```
|
|
16
15
|
*/
|
|
@@ -25,6 +24,8 @@ export declare class OPFSWorker {
|
|
|
25
24
|
private broadcastChannel;
|
|
26
25
|
/** Configuration options */
|
|
27
26
|
private options;
|
|
27
|
+
/** Shared sync handles per path (OPFS allows only one handle per file) */
|
|
28
|
+
private openHandles;
|
|
28
29
|
/** Map of open file descriptors to their metadata */
|
|
29
30
|
private openFiles;
|
|
30
31
|
/** Next available file descriptor number */
|
|
@@ -44,7 +45,7 @@ export declare class OPFSWorker {
|
|
|
44
45
|
*/
|
|
45
46
|
private notifyChange;
|
|
46
47
|
/**
|
|
47
|
-
* Creates a new
|
|
48
|
+
* Creates a new OPFSWorker instance
|
|
48
49
|
*
|
|
49
50
|
* @param options - Optional configuration options
|
|
50
51
|
* @param options.root - Root path for the file system (default: '/')
|
|
@@ -65,7 +66,7 @@ export declare class OPFSWorker {
|
|
|
65
66
|
*
|
|
66
67
|
* @example
|
|
67
68
|
* ```typescript
|
|
68
|
-
* const fs = new
|
|
69
|
+
* const fs = new OPFSWorker();
|
|
69
70
|
*
|
|
70
71
|
* // Use OPFS root (default)
|
|
71
72
|
* await fs.mount();
|
|
@@ -471,6 +472,9 @@ export declare class OPFSWorker {
|
|
|
471
472
|
open(path: string, options?: FileOpenOptions): Promise<number>;
|
|
472
473
|
/**
|
|
473
474
|
* Internal method to open a file (without locking)
|
|
475
|
+
*
|
|
476
|
+
* Multiple FDs for the same path share one sync access handle (OPFS limit),
|
|
477
|
+
* with independent per-FD positions — similar to Node.js.
|
|
474
478
|
* @private
|
|
475
479
|
*/
|
|
476
480
|
private _openFile;
|
|
@@ -625,4 +629,4 @@ export declare class OPFSWorker {
|
|
|
625
629
|
*/
|
|
626
630
|
createIndex(entries: [string, string | Uint8Array | Blob][]): Promise<void>;
|
|
627
631
|
}
|
|
628
|
-
//# sourceMappingURL=
|
|
632
|
+
//# sourceMappingURL=OPFSWorker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OPFSWorker.d.ts","sourceRoot":"","sources":["../src/OPFSWorker.ts"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAc,YAAY,EAAiB,MAAM,SAAS,CAAC;AAG1I;;;;;;;;;;;;;GAaG;AACH,qBAAa,UAAU;IACnB,gDAAgD;IAChD,OAAO,CAAC,IAAI,CAA6B;IAEzC,uCAAuC;IACvC,OAAO,CAAC,QAAQ,CAAoC;IAEpD,qDAAqD;IACrD,OAAO,CAAC,eAAe,CAAiC;IAExD,mDAAmD;IACnD,OAAO,CAAC,gBAAgB,CAAiC;IAEzD,4BAA4B;IAC5B,OAAO,CAAC,OAAO,CAMb;IAEF,0EAA0E;IAC1E,OAAO,CAAC,WAAW,CAId;IAEL,qDAAqD;IACrD,OAAO,CAAC,SAAS,CAKZ;IAEL,4CAA4C;IAC5C,OAAO,CAAC,MAAM,CAAK;IAEnB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAW1B;;;;;;;OAOG;YACW,YAAY;IAmD1B;;;;;;;;;OASG;gBACS,OAAO,CAAC,EAAE,WAAW;IAQjC;;;;;;;;;;;;;;;;;;;OAmBG;YACW,KAAK;IA6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