opfs-worker 1.1.0 → 1.2.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.
- package/README.md +19 -6
- package/dist/assets/worker-CLvhwwfc.js.map +1 -0
- package/dist/facade.d.ts +141 -0
- package/dist/facade.d.ts.map +1 -0
- package/dist/{helpers-DS5dyURe.js → helpers-CkNHswLp.js} +547 -573
- package/dist/helpers-CkNHswLp.js.map +1 -0
- package/dist/helpers-TAynP0fb.cjs +4 -0
- package/dist/helpers-TAynP0fb.cjs.map +1 -0
- package/dist/index.cjs +753 -878
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1016 -932
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.d.ts +13 -0
- package/dist/raw.d.ts.map +1 -0
- package/dist/raw.js +187 -148
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +7 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/encoder.d.ts +1 -2
- package/dist/utils/encoder.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +2 -22
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +22 -32
- package/dist/worker.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/assets/worker-CvILLJKw.js.map +0 -1
- package/dist/helpers-CKqaiMjI.cjs +0 -4
- package/dist/helpers-CKqaiMjI.cjs.map +0 -1
- package/dist/helpers-DS5dyURe.js.map +0 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ A robust TypeScript library for working with Origin Private File System (OPFS) t
|
|
|
21
21
|
### 🚀 **Performance & Architecture**
|
|
22
22
|
|
|
23
23
|
- **Web Worker-based**: Runs in a separate thread, keeping your main thread responsive
|
|
24
|
+
- **Zero-copy data transfer**: Efficient binary data handling with Comlink transfer
|
|
24
25
|
- **Faster than IndexedDB hacks**: Direct OPFS access without the overhead of database abstractions
|
|
25
26
|
- **Efficient file watching**: Real-time change detection with minimatch patterns, no polling delays
|
|
26
27
|
|
|
@@ -157,6 +158,10 @@ async function extendedExample() {
|
|
|
157
158
|
await fs.writeFile('/image.png', imageData);
|
|
158
159
|
const binaryData = await fs.readFile('/image.png', 'binary');
|
|
159
160
|
|
|
161
|
+
// Text files are automatically handled
|
|
162
|
+
await fs.writeFile('/config.txt', 'Hello, World!');
|
|
163
|
+
const textContent = await fs.readFile('/config.txt'); // Returns string
|
|
164
|
+
|
|
160
165
|
// Use file watching with BroadcastChannel
|
|
161
166
|
await fs.watch('/', {
|
|
162
167
|
recursive: true,
|
|
@@ -219,8 +224,9 @@ async function extendedExample() {
|
|
|
219
224
|
// Create directories
|
|
220
225
|
await worker.mkdir('/data/logs', { recursive: true });
|
|
221
226
|
|
|
222
|
-
// Append to log files
|
|
223
|
-
|
|
227
|
+
// Append to log files (worker works with bytes)
|
|
228
|
+
const logEntry = new TextEncoder().encode(`${new Date().toISOString()}: App started\n`);
|
|
229
|
+
await worker.appendFile('/data/logs/app.log', logEntry);
|
|
224
230
|
|
|
225
231
|
// Watch for changes
|
|
226
232
|
await worker.watch('/data', { recursive: true });
|
|
@@ -354,13 +360,20 @@ The complete API reference is available in the [docs/api-reference.md](docs/api-
|
|
|
354
360
|
|
|
355
361
|
**Entry Points:**
|
|
356
362
|
|
|
357
|
-
- `createWorker(options?)` - Create file system instance with inline worker
|
|
358
|
-
- `
|
|
363
|
+
- `createWorker(options?)` - Create file system instance with inline worker (recommended)
|
|
364
|
+
- `OPFSFileSystem` - High-level facade with automatic encoding detection
|
|
365
|
+
- `OPFSWorker` - Direct webworker class
|
|
359
366
|
|
|
360
367
|
**Core File Operations:**
|
|
361
368
|
|
|
362
|
-
- `readFile(path, encoding?)` - Read files as text or binary
|
|
363
|
-
- `writeFile(path, data, encoding?)` - Write text or binary data
|
|
369
|
+
- `readFile(path, encoding?)` - Read files as text or binary with auto-detection
|
|
370
|
+
- `writeFile(path, data, encoding?)` - Write text or binary data with auto-detection
|
|
371
|
+
- `readText(path, encoding?)` - Read files as text with specified encoding
|
|
372
|
+
- `writeText(path, text, encoding?)` - Write text with specified encoding
|
|
373
|
+
- `appendText(path, text, encoding?)` - Append text with specified encoding
|
|
374
|
+
|
|
375
|
+
**Common Operations:**
|
|
376
|
+
|
|
364
377
|
- `mkdir(path, options?)` - Create directories
|
|
365
378
|
- `readDir(path)` - List directory contents
|
|
366
379
|
- `stat(path)` - Get file/directory statistics
|