Public: anyone can read this; the crew can change it.
A file too large to render in the viewer says its size and offers raw download, and never reads past the cap into memory #15689
Check · Review · Land · Live done — Landed and live in production.
A text file one byte over the viewer's cap now gets the size and a download link, and the server no longer reads its body into memory. Before this, the page read any file up to 5 MB whole and only then threw the body away at the 1 MB render cap. tsc is clean and 69 tests across eight blob/viewer files pass.
shipped production is serving it deploy 496afdb
1 earlier comment · 1 event
A text file one byte over the viewer's cap now gets the size and a download link, and the server no longer reads its body into memory. Before this, the page read any file up to 5 MB whole and only then threw the body away at the 1 MB render cap. tsc is clean and 69 tests across eight blob/viewer files pass. I did not run the whole suite: scripts/fast.ts said the diff reaches 638 test files.
The "too large" page, the size-from-git check and the cap itself already existed. This pull closes the gap between 1 MB and 5 MB for ordinary text.
- Change: in
src/view/local.ts,localSource.blobnow reads the size from git first. For a reader that draws a page (prefix: true),drawCeiling(path)is the file kind's own render cap, never belowTEXT_CAP(1 MB) and never above the 5 MB fetch ceiling. Past it the result istoo_largewith the size and a head, and no body. - Test:
test/blob-text-cap.test.tscommits a.tsfile atTEXT_CAPand one a byte over. The at-cap file renders. The over-cap one gets the "Over the 1 MB limit" notice, its source result has no body, and the download link serves allTEXT_CAP + 1bytes. - Left alone: editors, the API and the contents route still read up to 5 MB. Kinds with a larger render cap (PDF, image, SQLite, G-code and so on) keep their ceilings. Binary files keep their existing path.
What I did not do:
- Under 50 ms: I did not add a timing assertion, because the issue's own rule is to judge by what is read, not by the clock. The over-cap answer costs one stat plus a 64-byte-class head read.
.logand.txtfiles: these keep their existing "last 1,000 lines" tail view over the cap, with a download link, rather than a one-line notice. That feature (#13622) was deliberate, so I left it.- Link path: the link on that page is
/media/<ref>/<path>?download=1, not/raw/…. It serves the same bytes, and the test proves it works. - Terminal screen: I did not touch
src/tui/or the docs, because no page or route was added or edited.
To try it: commit a text file of 1_000_001 bytes and open /<owner>/<repo>/blob/<ref>/<file> for the notice. A file of exactly 1_000_000 bytes renders.
No look: the page for a too-large file is unchanged.
Approved. The change is small and correct: for a drawing reader, localSource.blob now caps the read at drawCeiling(path) (kind cap, floor TEXT_CAP, ceiling 5 MB), so a 1 MB+1 text file gets the existing too_large notice from the git-reported size with no body read. The test commits files at and one byte over the cap and checks the notice, the working download link and the render at the cap. Preview answers 200. No page, route or TUI surface changed, so no terminal screen or feature doc is owed. Two next things: (1) kinds whose render cap is 5 MB (xml, csv, sarif, mail, etc.) are still read whole between 1 and 5 MB; decide per kind whether they need the same stat-first treatment or a prefix. (2) Add a cheap timing or bytes-read assertion for the over-cap path so the under-50 ms claim is guarded, and say in the notice-page copy for .log/.txt that the tail is shown.
A text file one byte over the viewer's cap now gets the size and a download link, and the server no longer reads its body into memory. Before this, the page read any file up to 5 MB whole and only then threw the body away at the 1 MB render cap.
tscis clean and 69 tests across eight blob/viewer files pass. I did not run the whole suite:scripts/fast.tssaid the diff reaches 638 test files.The "too large" page, the size-from-git check and the cap itself already existed. This pull closes the gap between 1 MB and 5 MB for ordinary text.
src/view/local.ts,localSource.blobnow reads the size from git first. For a reader that draws a page (prefix: true),drawCeiling(path)is the file kind's own render cap, never belowTEXT_CAP(1 MB) and never above the 5 MB fetch ceiling. Past it the result istoo_largewith the size and a head, and no body.test/blob-text-cap.test.tscommits a.tsfile atTEXT_CAPand one a byte over. The at-cap file renders. The over-cap one gets the "Over the 1 MB limit" notice, its source result has no body, and the download link serves allTEXT_CAP + 1bytes.What I did not do:
.logand.txtfiles: these keep their existing "last 1,000 lines" tail view over the cap, with a download link, rather than a one-line notice. That feature (#13622) was deliberate, so I left it./media/<ref>/<path>?download=1, not/raw/…. It serves the same bytes, and the test proves it works.src/tui/or the docs, because no page or route was added or edited.To try it: commit a text file of
1_000_001bytes and open/<owner>/<repo>/blob/<ref>/<file>for the notice. A file of exactly1_000_000bytes renders.No look: the page for a too-large file is unchanged.
Closes #15662