fix: support exporting recordings larger than 2 GiB#520
Conversation
Node.js fs.readFile throws ERR_FS_FILE_TOO_LARGE for files >2 GiB. The read-local-file IPC handler used readFile, causing exports to fail when the source recording exceeded that limit. Replace readFile with fileHandle.read in 64 MiB chunks — no size limit. Also change createReadableMediaResourceFile to fall through to URL-based fetch when readLocalFile fails, rather than throwing immediately.
📝 WalkthroughWalkthroughChunked-reading replaces single-call fs.readFile in the Electron IPC handler (reads in 64 MiB segments, returns ChangesLarge file handling with fallback
Sequence Diagram(s)sequenceDiagram
participant Renderer
participant IPC_Handler
participant FileSystem
participant Network
Renderer->>IPC_Handler: readLocalFile(path)
IPC_Handler->>FileSystem: fs.open(resolved)
FileSystem-->>IPC_Handler: fileHandle
IPC_Handler->>FileSystem: fs.stat(resolved)
FileSystem-->>IPC_Handler: size
IPC_Handler->>IPC_Handler: allocate Buffer(size)
loop Read 64 MiB chunks
IPC_Handler->>FileSystem: fileHandle.read(buffer, offset, chunkSize)
FileSystem-->>IPC_Handler: bytesRead
end
IPC_Handler->>FileSystem: fileHandle.close()
alt Success
IPC_Handler-->>Renderer: {success: true, data: buffer}
Renderer->>Renderer: create File from Buffer
else Failure
IPC_Handler-->>Renderer: {success: false, error}
Renderer->>Network: resolveMediaResourceUrl + fetch(url)
Network-->>Renderer: Response -> create File
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@electron/ipc/register/assets.ts`:
- Around line 124-134: The code uses Buffer.allocUnsafe(fileSize) and may return
uninitialized tail bytes if the file is truncated (fileHandle.stat() -> fileSize
then reads fewer bytes), so change the return to only include the bytes actually
read: after the read loop return the buffer trimmed to offset (e.g., use
buffer.slice(0, offset) or similar), referencing fileHandle, stat, fileSize,
buffer, offset and bytesRead to locate the logic; this preserves the performance
advantage of allocUnsafe while ensuring no uninitialized memory is exposed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: c8517073-efae-43b9-ac43-9dad5dddbe44
📒 Files selected for processing (2)
electron/ipc/register/assets.tssrc/lib/exporter/localMediaSource.ts
Description
Export fails with
RangeError [ERR_FS_FILE_TOO_LARGE]when the source recording exceeds 2 GiB. Theread-local-fileIPC handler usedfs.readFile, which has a hard ~2 GiB limit in Node.js. This caused both legacy and Lightning (Beta) exports of long recordings to fail.Motivation
Users recording tutorials commonly produce recordings over 2 GiB. The error was unrecoverable — there was no fallback and the export dialog showed a cryptic range error with no guidance.
Type of Change
Related Issue(s)
#493
Screenshots / Video
Error before fix:
Testing Guide
ERR_FS_FILE_TOO_LARGEChecklist