Repository navigation
feat: stream files direct-to-disk via OPFS Web Worker to eliminate memory limits (fixes #120, fixes #294) - #525
Open
BemreSTR wants to merge 1 commit into
Conversation
- Implements FileDigesterViaWorker using Origin Private File System (OPFS) and FileSystemSyncAccessHandle in a dedicated Web Worker - Chunks received over WebRTC data channels are streamed zero-copy to disk, keeping RAM consumption near zero regardless of file size - Automatically falls back to FileDigesterViaBuffer (legacy in-memory Blob) when OPFS is unsupported (e.g. insecure contexts or older browsers) - Lifts iOS 200MB transfer limit when OPFS streaming is active - Falls back to standard browser downloads for files > 250MB on iOS to prevent WebKit share sheet jetsam crashes - Handles complete file lifecycle: cleans up OPFS files on dialog dismissal, transfer cancellation, RTC disconnection, or tab close - Fixes schlagmichdoch#120, fixes schlagmichdoch#294
dayowe
added a commit
to dayowe/PairDrop
that referenced
this pull request
Nov 25, 2026
Protect each document's received files with a Web Lock. Reclaim abandoned transfer directories and discard incomplete batches without touching downloads in live tabs. Check available storage at acceptance, acknowledge partitions after their writes finish, and report quota failures to both peers so they can retry. Cover cross-tab cleanup, low space, the memory fallback and a large download in browser tests. Follow-up to the work by BemreSTR in schlagmichdoch#525.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR resolves the long-standing memory limitation and tab crashes when receiving large files (especially on iOS / Safari), addressing #120 and #294.
Instead of storing incoming WebRTC chunks in browser RAM before assembling a
Blob, this PR introduces direct-to-disk streaming via the Origin Private File System (OPFS) andFileSystemSyncAccessHandlein a dedicated Web Worker.RAM usage remains practically zero regardless of file size (multi-gigabyte files can be received without memory pressure).
Why this approach over previous attempts?
A previous exploratory branch (
sw_digester/ PR #267) attempted a massive 30-file / 3,600+ line rewrite of the networking and UI stack, which stalled due to merge conflicts, global state bugs, and queue ordering issues.In accordance with
CONTRIBUTING.md("Stability always comes first", "Radical simplicity"):Key Changes
Dedicated OPFS Worker (
public/scripts/worker/file-digester-worker.js):navigator.storage.getDirectory()andcreateSyncAccessHandle()to write chunks directly to isolated OPFS storage on disk.postMessage(..., [chunk])).Modular File Digester with Graceful Fallback (
public/scripts/network.js):FileDigesterdetects OPFS support at startup viaFileDigester.init().FileDigesterViaWorker.FileDigesterViaBuffer(the existing in-memory Blob mechanism).Lifting iOS Transfer Limits & Crash Protection (
public/scripts/ui.js,network.js):Peer._onFilesTransferRequest) is automatically bypassed when OPFS streaming is active.window.iOS && totalSize > 250MB, PairDrop gracefully falls back to direct browser download instead of crashingnavigator.share.originalName) when sharing or downloading.Lifecycle Management & Zero Disk Leaks:
ReceiveFileDialog.pagehide).Service Worker Cache:
file-digester-worker.jstorelativePathsToCacheinpublic/service-worker.jsfor full offline PWA functionality.Testing & Verification
Automated E2E tests were executed with Puppeteer across multiple headless browser instances:
FileDigester.isStreamingSupportedcorrectly detects OPFS sync handle support.Fixes #120, fixes #294.