Storage System
Opal Editor’s storage system provides a unified abstraction over multiple storage backends through theDisk class. This enables seamless switching between IndexedDB, Origin Private File System (OPFS), in-memory storage, and local directory mounting.
Architecture
Core Class: Disk
Location:~/workspace/source/src/data/disk/Disk.ts
Abstract Base Class
Disk Types
Storage Backends
IndexedDB Disk
Location:~/workspace/source/src/data/disk/IndexedDbDisk.ts
Persistent storage using @isomorphic-git/lightning-fs.
- ✅ Persistent across browser sessions
- ✅ Works in all modern browsers
- ✅ No user permissions required
- ⚠️ Storage quotas apply (~50-100MB typical)
- ⚠️ Slower than OPFS
OPFS Directory Mount Disk
Location:~/workspace/source/src/data/disk/OPFsDirMountDisk.ts
Mount a local directory using the File System Access API.
- ✅ Real file system access
- ✅ Survives browser restarts (after re-permission)
- ✅ Can access existing folders
- ✅ Changes visible to other apps
- ⚠️ Requires user permission
- ⚠️ Handle persistence requires re-verification
Memory Disk
In-memory storage for temporary operations.- ✅ Very fast
- ✅ No storage quotas
- ✅ Useful for previews/temp files
- ❌ Data lost on page reload
File Operations
Reading and Writing
Creating Files and Directories
Renaming and Moving
Copying
Deleting
File Tree System
Accessing the File Tree
Filtering and Iteration
Virtual Files
Virtual files exist in the tree but not on disk.Indexing System
File Tree Indexing
Index Listeners
Event System
Disks use both local and remote events for cross-tab synchronization.Event Types
Write Events
Advanced Operations
Batch Find-Replace
Path Utilities
Initialization and Lifecycle
Initialize Disk
Cleanup
Serialization
Factory Pattern
Context Pattern
Disk Context
Each disk type has an associated context that manages:- File system interface
- File tree instance
- Mutex for concurrency
Switching Contexts
Database Layer
Location:~/workspace/source/src/data/db/DBInstance.ts
Disks use IndexedDB for metadata persistence through the ClientDb singleton:
Best Practices
Always Initialize
Use Path Helpers
Handle Index Events
Cleanup Resources
Use Quiet Operations for Performance
Common Patterns
Local Directory Workspace
Temp Disk for Preview
Cross-Disk Copy
Error Handling
Related Systems
- Workspace System - Uses disk for file storage
- Git System - Reads/writes via disk.fs
- Build System - Reads source from disk