opfs-worker 1.0.1 → 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 });
@@ -345,17 +351,29 @@ Check out the live demo powered by Vite and hosted on GitHub Pages.
345
351
 
346
352
  The complete API reference is available in the [docs/api-reference.md](docs/api-reference.md) file.
347
353
 
354
+ **Additional Documentation:**
355
+
356
+ - [File Descriptors Guide](docs/file-descriptors.md) - Comprehensive guide to low-level file I/O operations
357
+ - [Types Reference](docs/types.md) - Complete TypeScript type definitions
358
+
348
359
  ### Quick API Overview
349
360
 
350
361
  **Entry Points:**
351
362
 
352
- - `createWorker(options?)` - Create file system instance with inline worker
353
- - `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
354
366
 
355
367
  **Core File Operations:**
356
368
 
357
- - `readFile(path, encoding?)` - Read files as text or binary
358
- - `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
+
359
377
  - `mkdir(path, options?)` - Create directories
360
378
  - `readDir(path)` - List directory contents
361
379
  - `stat(path)` - Get file/directory statistics
@@ -363,6 +381,20 @@ The complete API reference is available in the [docs/api-reference.md](docs/api-
363
381
  - `copy(source, destination, options?)` - Copy files/directories
364
382
  - `rename(oldPath, newPath)` - Rename files/directories
365
383
 
384
+ **File Descriptors (Low-level I/O):**
385
+
386
+ - `open(path, options?)` - Open file and return descriptor
387
+ - `read(fd, buffer, offset, length, position?)` - Read from descriptor (returns `{bytesRead, buffer}`)
388
+ - `write(fd, buffer, offset?, length?, position?)` - Write to descriptor
389
+ - `fstat(fd)` - Get stats by descriptor
390
+ - `ftruncate(fd, size?)` - Truncate file by descriptor
391
+ - `fsync(fd)` - Sync file data to storage
392
+ - `close(fd)` - Close file descriptor
393
+
394
+ **Note**: The `read()` method uses `Comlink.transfer()` for efficient buffer handling. **From the main window**, you must transfer buffer ownership to the worker, and **from the worker**, the buffer is transferred back to you. See [File Descriptors Guide](docs/file-descriptors.md) for complete usage examples.
395
+
396
+ _For detailed file descriptor documentation, see [File Descriptors Guide](docs/file-descriptors.md)_
397
+
366
398
  **Advanced Features:**
367
399
 
368
400
  - `watch(path, options?)` - Watch for file changes with minimatch patterns