File I/O — Desktop and Web

How VU-VERSE handles files on native desktop builds versus WebAssembly (browser) builds.

Overview

File handling differs significantly between native desktop apps and browser-based WebAssembly builds. Desktop builds can access local files and mounted storage directly, while web builds run inside a sandbox and must use browser APIs, network fetches, or an emulated filesystem.

Desktop (Native) File Handling

  • Uses Qt-native file APIs: `QFile`, `QDir`, `QStandardPaths` for platform-consistent file dialogs and persistence.
  • VTK readers (e.g., `vtkHDFReader`) can open files directly from disk or from paths provided by the UI.
  • Supports large files and memory-mapped access where available; can take advantage of OS-level I/O and GPU drivers.

Web (WASM) File Handling

Browser sandboxing prevents direct arbitrary disk access; common patterns include:
  • Network fetch / streaming: fetch files over HTTP(S), preferably with range requests or server-side streaming for large datasets.
  • In-memory / virtual FS (Emscripten MEMFS): load files into an emulated filesystem for libraries that expect POSIX paths.
  • IndexedDB: persist downloaded assets in the browser for offline reuse and to avoid re-downloading large datasets.
  • File picker / user upload: allow users to select local files via `` and stream them into the WASM runtime.
  • For very large datasets prefer server-side tiling, pre-processing, or cloud-hosted object stores with range-GET endpoints.

VU-VERSE Current (Virtual FS) Approach

VU-VERSE uses a virtual filesystem pattern for the browser build: files are fetched (or provided via file picker) and populated into an emulated POSIX-like filesystem (Emscripten MEMFS) so existing VTK readers can operate with minimal changes.

  • Files are typically downloaded into memory (or streamed into MEMFS) and then opened by VTK code using standard file paths.
  • The bridge exposes QML/JS hooks: trigger download, stream chunks into MEMFS, and notify C++ when the file path is ready for reading.
  • Tradeoffs: MEMFS keeps compatibility with existing C++ readers but is limited by browser memory and can be slower for extremely large datasets; IndexedDB helps but adds complexity.