1. The Mobile Browser Storage Crisis
Desktop browsers provide modern disk writing APIs like window.showSaveFilePicker(), which stream data directly to physical files on the hard drive without consuming RAM.
On mobile operating systems (Android and iOS), browser vendors deliberately restrict or disable showSaveFilePicker(). When an application generates large files, it is traditionally forced to accumulate everything into a single Blob object in memory.
A standard smartphone browser tab terminates with an "Aw, Snap!" error when heap allocations exceed 350 MB. Creating a 1 GB encrypted backup in an ordinary web app is impossible on mobile devices without crashing.
2. The Four-Tier Storage Fallback Hierarchy
ZevSafe solves this fragmentation through an intelligent capability-sensing pipeline (js/stream-saver.js):
[ Device Capability Detection ]
|
+--> Has window.showSaveFilePicker?
| YES: --> [ TIER 1: File System Access API (Direct Disk) ]
|
+--> Is Mobile (Android/iOS) && Has OPFS (navigator.storage)?
| YES: --> [ TIER 3: Origin Private File System (OPFS) ]
|
+--> Has Service Worker && Non-Mobile (Firefox / Desktop Safari)?
| YES: --> [ TIER 2: Service Worker StreamSaver Pipeline ]
|
+--> Incognito Mode / Restricted Environment?
FALLBACK: --> [ TIER 4: Memory-Bounded Chunk Fallback ]
3. Tier 1: File System Access API (Desktop Chrome / Edge)
On supported desktop platforms, Tier 1 uses window.showSaveFilePicker to obtain a FileSystemWritableFileStream:
- Allows seeking to byte offset 0 to write the finalized 57-byte header and manifest offset.
- Direct OS-level streaming with zero intermediate buffer staging.
- Zero heap memory growth regardless of output file size.
4. Tier 3: Origin Private File System (Android Chrome & iOS Safari)
On mobile devices where FSA is unavailable, ZevSafe promotes Tier 3 OPFS (Origin Private File System) to primary priority:
- Accesses the private origin sandbox via
navigator.storage.getDirectory(). - Streams 4 MB ciphertext chunks into a temporary file (
zevsafe_stage_*.tmp) using high-speed native file handles. - Once encryption is complete, it seeks to byte 49 to write the final manifest offset, packages the staging file into a clean download trigger, and schedules cleanup after transfer.
- Result: Enables smartphones with only 4 GB of RAM to encrypt and decrypt 5 GB+ files without exhausting heap limits!
5. Tier 2: Service Worker StreamSaver (Firefox & Desktop Safari)
On browsers lacking both FSA and synchronous OPFS handles (like older desktop Firefox builds), Tier 2 establishes an in-memory streaming bridge with the Service Worker:
- The page streams chunks to the Service Worker via a
MessageChannel. - The Service Worker intercepts a virtual download route and streams chunks out as an HTTP response with
Content-Disposition: attachment. - The browser native download manager streams the bytes directly into the user's Downloads folder.
6. Tier 4: Memory Bounded Safe Fallback
If a user opens ZevSafe in a private/incognito window where browsers forbid OPFS and Service Workers, Tier 4 activates:
- Streams chunks into an array of smaller buffer slices.
- Enforces an active memory guardrail: checks available quota via
navigator.storage.estimate(). - If the file exceeds safe memory thresholds, it proactively notifies the user with instructions to open standard mode or use the PC toolkit.