[PR #11312] fix(app): binary file handling in file view #13738

Closed
opened 2026-02-16 18:18:34 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11312

State: closed
Merged: Yes


Related Issues

Addresses #11126 - Extension-based binary detection

Fixes app freeze for all binary files with recognized extensions (93 types).
Note: Extensionless binaries require content-based detection (follow-up needed).

What this PR addresses:

  • Binary files with extensions (.exe, .apk, .bin, etc.) → Fixed
  • Uppercase extensions → Fixed
  • App freeze on binary files → Fixed for most cases

What remains for follow-up:

  • Extensionless binaries (common on macOS/Linux)
  • Content-based detection (null byte, non-printable ratio)
  • See issue for full suggested implementation using tool/read.ts logic

What does this PR do?

1. Binary file handling

Prevents rendering garbage text and freezing when opening binary files. Added detection for 90+ binary extensions: exe, dll, pdb, apk, ipa, wav, mp3, mp4, avi, zip, tar, gz, pdf, doc, docx, and more.

  • Backend returns type: "binary" immediately without loading file content
  • Frontend displays "Binary file (content cannot be displayed)" with the filename

Before: App would freeze when clicking binaries (.exe, .apk, etc.) or on startup if these files were open in the previous session.

image

After: App instantly shows binary file placeholder without loading content.
image

Also prevents attempting to render video, audio, and other non-image binary content:
Before:
image

After:
image

  1. Uppercase/mixed case extension support
    Fixes images with uppercase extensions (.PNG, .JPG, .GIF) or mixed case (pNG, JPg, etc.) not rendering
    Added explicit image extension detection (png, jpg, gif, webp, svg, etc.)
    Maps extensions to correct MIME types regardless of case
    SDK type updates - Updated FileContent.type from "text" to "text" | "binary" to support new backend response

Before: extension case sensitive
image
image
image

After: no difference in file name extension case
image
image

  1. SDK type updates
    Updated FileContent.type from "text" to "text" | "binary" in SDK v1 and v2 to support the new backend response format.

  2. Localization
    Added translation key session.files.binaryContent for 15 languages

How did you verify your code works?

  • TypeScript: All packages pass typecheck

  • Test suite: 721 pass (+2), 61 fail (-2) — 2 previously failing tests now pass
    loads config from .opencode directory (was timing out)
    deduplicates duplicate instructions from global and local configs (was timing out)

  • E2E tests: All 22 tests pass

  • Manual testing:

    • Clicking .exe, .apk, .zip shows "Binary file" message instantly
    • .PNG, .JPG, .GIF, .pNG, jPG render correctly as images
    • videos, audio files also render "Binary file"
    • No app freeze when opening binary files or restarting with them open
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11312 **State:** closed **Merged:** Yes --- ### Related Issues Addresses #11126 - Extension-based binary detection Fixes app freeze for all binary files with recognized extensions (93 types). Note: Extensionless binaries require content-based detection (follow-up needed). **What this PR addresses:** - Binary files with extensions (.exe, .apk, .bin, etc.) → Fixed - Uppercase extensions → Fixed - App freeze on binary files → Fixed for most cases **What remains for follow-up:** - Extensionless binaries (common on macOS/Linux) - Content-based detection (null byte, non-printable ratio) - See issue for full suggested implementation using tool/read.ts logic ### What does this PR do? ## 1. **Binary file handling** Prevents rendering garbage text and freezing when opening binary files. Added detection for 90+ binary extensions: exe, dll, pdb, apk, ipa, wav, mp3, mp4, avi, zip, tar, gz, pdf, doc, docx, and more. - Backend returns type: "binary" immediately without loading file content - Frontend displays "Binary file (content cannot be displayed)" with the filename **Before**: App would freeze when clicking binaries (.exe, .apk, etc.) or on startup if these files were open in the previous session. <img width="456" height="171" alt="image" src="https://github.com/user-attachments/assets/82ac9cee-815e-413d-b6c6-0be0fefd08f7" /> **After**: App instantly shows binary file placeholder without loading content. <img width="633" height="590" alt="image" src="https://github.com/user-attachments/assets/3f4ed551-e654-42ed-9d32-e01e6b96a20e" /> Also prevents attempting to render video, audio, and other non-image binary content: **Before**: <img width="494" height="99" alt="image" src="https://github.com/user-attachments/assets/325f9fd1-6db5-41b9-81f9-ece213637aeb" /> **After**: <img width="581" height="524" alt="image" src="https://github.com/user-attachments/assets/fa457790-d70c-4d6e-916b-f361befb688d" /> 2. **Uppercase/mixed case extension support** Fixes images with uppercase extensions (.PNG, .JPG, .GIF) or mixed case (pNG, JPg, etc.) not rendering Added explicit image extension detection (png, jpg, gif, webp, svg, etc.) Maps extensions to correct MIME types regardless of case SDK type updates - Updated FileContent.type from "text" to "text" | "binary" to support new backend response Before: extension case sensitive <img width="354" height="268" alt="image" src="https://github.com/user-attachments/assets/3b7294e2-49b9-4d89-97e8-e406457dd3d9" /> <img width="409" height="195" alt="image" src="https://github.com/user-attachments/assets/e994c52b-dea8-49ee-81d2-bfe354130477" /> <img width="366" height="220" alt="image" src="https://github.com/user-attachments/assets/07cd1031-7d30-4c2e-bed1-3f9e6583c526" /> After: no difference in file name extension case <img width="494" height="236" alt="image" src="https://github.com/user-attachments/assets/ead53b56-4633-4a09-a543-0396cbed945b" /> <img width="303" height="221" alt="image" src="https://github.com/user-attachments/assets/6d494d3f-f652-4da1-a1cf-fb6083d52655" /> 3. **SDK type updates** Updated FileContent.type from "text" to "text" | "binary" in SDK v1 and v2 to support the new backend response format. 4. **Localization** Added translation key session.files.binaryContent for 15 languages ### How did you verify your code works? - **TypeScript:** All packages pass typecheck - **Test suite:** 721 pass (+2), 61 fail (-2) — 2 previously failing tests now pass loads config from .opencode directory (was timing out) deduplicates duplicate instructions from global and local configs (was timing out) - **E2E tests:** All 22 tests pass - **Manual testing:** - Clicking .exe, .apk, .zip shows "Binary file" message instantly - .PNG, .JPG, .GIF, .pNG, jPG render correctly as images - videos, audio files also render "Binary file" - No app freeze when opening binary files or restarting with them open
yindo added the pull-request label 2026-02-16 18:18:34 -05:00
yindo closed this issue 2026-02-16 18:18:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13738