opfs-worker 1.1.0 → 1.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/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
- await worker.appendFile('/data/logs/app.log', `${new Date().toISOString()}: App started\n`);
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
- - `OPFSWorker` - Direct worker class for manual setup
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