feat: Binary file hex preview in FileViewer#345
Merged
allison-truhlar merged 10 commits intoJaneliaSciComp:mainfrom Apr 9, 2026
Merged
feat: Binary file hex preview in FileViewer#345allison-truhlar merged 10 commits intoJaneliaSciComp:mainfrom
allison-truhlar merged 10 commits intoJaneliaSciComp:mainfrom
Conversation
Previously, clicking a binary file showed nothing until a slow HEAD request completed (which does synchronous file I/O server-side, painful on NFS). Functional links were also absent for binary files. Changes: - isKnownBinaryExtension(): instant binary detection by file extension, bypasses the HEAD request entirely for common binary types (zip, h5, png, pdf, etc.) - useFileBinaryPreviewQuery(): fetches first 512 bytes via HTTP Range header immediately, independent of binary detection, so the hex view appears as soon as the tiny read completes - HexDump.tsx: classic hexdump renderer (offset | hex | ASCII, 16 B/row) with a "Showing first N of M bytes" label for truncated files - FileViewer: always shows a download link in the header immediately, regardless of file type or loading state; uses two-stage binary detection (extension first, HEAD fallback for unknown types) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The .nii.gz special case in isKnownBinaryExtension is redundant because
.gz is already in KNOWN_BINARY_EXTENSIONS, so split('.').pop() catches it.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
KNOWN_BINARY_EXTENSIONS and isKnownBinaryExtension are removed. Binary detection now always uses the HEAD request (X-Is-Binary header), which simplifies the logic at the cost of one extra server round-trip per file. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This is a standalone cosmetic feature unrelated to binary file display. Removes HiOutlineDownload icon, getFileURL wiring, and the wrapper div that was added to accommodate both the JSON toggle and download button. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reformats six files to pass the pre-push ESLint/Prettier hook. No logic changes — only line-wrapping adjustments flagged by prettier/prettier. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
In #308, we removed binary previews completely. This adds a 512-byte preview as a hex display. Flat binary files are common among many Janelia labs due to their simplicity when acquiring data from custom instrumentation. When I asking around if anyone uses NWB files, which are a form of HDF5 files, I got several responses like the following.
The hex display adds some intelligible information about a binary file displayed as hex and is reminiscent of the output of |
- this allows the new binary content query to use this utility instead of raw fetch
- follows pattern for other query keys
allison-truhlar
approved these changes
Apr 9, 2026
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
FileViewercomponent, showing the first 512 bytes via an HTTP Range requestHexDump.tsx— a new component rendering bytes in classic hexdump format (offset | hex | ASCII, 16 bytes/row)useFileBinaryPreviewQueryhook that fetches binary preview bytes using the existing/api/content/endpoint's Range supportFileViewerto detect binary files via the existing HEAD request (X-Is-Binaryheader) and render the hex preview instead of attempting text displayshowJsonTogglecondition (no longer needsmetadataQuery.isSuccessguard)Example output for a ZIP file:
Test plan
.h5,.zip,.png) — hex dump preview renders with offset, hex, and ASCII columnspixi run test-frontend— all unit tests passpixi run node-check— no TypeScript errorspixi run node-eslint-check— no ESLint errors🤖 Generated with Claude Code