How we broke through the browser's limits to open 4 GB files
It started with a file we could not open — on the tool we built. A wedding photographer's archive: one RAR5 file of 4,648,486,424 bytes (4.33 GiB) holding 1,134 full-resolution JPEGs. Everything under roughly a gigabyte worked and had for months; this file sat there while our own viewer refused it. And because ZipTool's entire premise is that your files never leave your machine — no upload, no server, no exceptions — "just add an upload path for big files" was not an option. The browser tab had to do it.
This post is the full log of how that happened: what actually breaks at 4 GB, the one-line fix that unblocked most of it, the streaming engine the rest required, the porting traps that cost days and failed silently, the verification harness that lied to us, and the limits that are still real. It is written the way we would want to read it — numbers over adjectives, failure modes included, the key code inline, and the receipts at the end.
The short version of the outcome: that same archive now opens end-to-end in a browser tab. A one-time local staging copy takes about half a minute, the full entry list of all 1,134 photos appears in about 15 milliseconds, any single photo extracts in about 40 milliseconds, and the engine's working memory stays flat at 16 MiB from the first entry to the last. Zero bytes of it are ever uploaded — you can pull the network cable after the page loads and nothing changes. Drop your own file on the rar viewer or the zip viewer and watch, or read on for how it works.
The file that broke our own tool
Big archives did not fail for one reason; they failed for three, stacked. Understanding the stack is the whole problem, so here it is in the order we hit it.
First, our own front door. ZipTool deduplicates loaded archives by fingerprinting their content — a SHA-1 of the bytes, which means reading the whole file into memory as one ArrayBuffer. On a 4.33 GiB archive, that single allocation dies before a single byte of archive structure is even parsed.
Second, the rar engine itself. Our decoder was a WebAssembly build of unrar 6.x (from the open-source node-unrar-js project — its JS I/O layer was genuinely good). Its contract was the whole archive resident in one Uint8Array. Same wall, one layer deeper.
Third, the dead end: that wasm build was three years old, its upstream project unmaintained, and the beta build we found shipped byte-identical output to the production one. There was no drop-in upgrade to a newer unrar. If we wanted rar 7.x, we were going to compile it ourselves.
- Our content fingerprint read the whole file into one
ArrayBuffer— dead at ~2 GiB before parsing begins. - The rar engine held the entire archive in one
Uint8Array— the same wall one layer down. - The upstream wasm engine was three years stale with no upgrade path — self-compiling became the plan.
Measure first: three ceilings in every tab
Before designing anything, we measured what a browser tab can actually hold. The numbers below are from the engine we ship (measured on Chrome 150; Firefox and Safari sit in the same territory), not from forum folklore:
A single ArrayBuffer allocation tops out between 1.5 and 2 GiB. Chrome accepted a 1.5 GiB allocation and refused 2 GiB outright — RangeError, nothing allocated, no recovery. Any design that reads a whole file into one buffer inherits this wall.
A 32-bit WebAssembly module can address at most 4 GiB of memory total — code, decompressor state, and data combined. An engine that loads the archive into its heap cannot physically accept a file larger than that, and in practice dies a gigabyte or two earlier.
And the arithmetic: whole-file-in-memory designs need the archive resident at least once, often twice — once to fingerprint, once to extract. A 4.5 GB archive on that path means 4.5 to 9 GB of RAM inside one browser tab. The tab gets killed, or the fan wins and the page loses.
// Measured on the engine we ship (Chrome 150):
new ArrayBuffer(1.5 * 1024 ** 3) // ok
new ArrayBuffer(2 * 1024 ** 3) // RangeError, nothing allocated- One
ArrayBuffer: 1.5 GiB accepted, 2 GiBRangeError— measured, repeatable. - wasm32 addressing: 4 GiB ceiling for code plus state plus data, combined.
- Whole-file designs multiply the archive size by two at exactly the wrong moment.
The fix that unblocked everything except rar
The first fix was almost embarrassing. The fingerprint wall was self-inflicted: for files of 1 GiB and up, we stopped hashing content entirely and switched to an identity fingerprint — name, size, and modification time. It costs zero memory and is instant, and deduplication within a session works exactly as before (you rarely load two different archives that share a name, a byte size, and a mtime).
That one change removed the front-door ceiling for every format. And zip turned out to need nothing else, because the format did half the work for us: a zip ends with a central directory — an index of every entry at a known position near the end of the file. The viewer seeks to it and reads it directly; it never scans the gigabytes in between. Listing a 4 GB zip costs about the same as listing a 40 MB one. Archives past 4 GiB are necessarily zip64 and parse natively.
Measured, on real archives: a 4.3 GB zip of 1,000 photos lists all 1,000 entries in about 15 seconds and extracts any single photo in about 2; a 4.6 GB zip with a single giant entry lists its contents in 48 seconds. RAR was not so cooperative.
// Before: the front door read the whole file just to hash it
const digest = sha1(await file.arrayBuffer()) // dies at ~2 GiB
// After: at 1 GiB and up, identity stands in for content
if (file.size >= 1024 ** 3) {
const identity = file.name + '|' + file.size + '|' + file.lastModified
return 'id:' + sha1(identity)
}- Files ≥1 GiB: identity fingerprint (name + size + mtime) instead of a content hash — zero memory, instant.
- Zip needs no staging at all: the central directory is random-access by design; zip64 parses natively.
- Measured: 4.3 GB / 1,000 photos → listing ~15 s, single-file extraction ~2 s; 4.6 GB single-entry → listing 48 s.
rar: build a real streaming engine
The unrar contract could not be satisfied by seeking alone — the engine expects a seekable file, not a browser Blob reader, and the old build's whole-archive-in-the-heap design was the exact shape the ceilings forbid. So the new design inverts it: the archive never enters wasm memory at all. It stays on your disk, and unrar gets a file-like object that fetches slices on demand.
When a big rar arrives, the browser first copies it once into OPFS — the Origin Private File System, a private sandboxed storage area the browser keeps on your local disk, per site. Not a server, not a cloud: your machine, managed by your browser. The copy streams in chunks with a progress bar, about 30 seconds for the 4.33 GiB archive, and memory stays flat while it happens.
A Web Worker then opens the staged copy with a FileSystemSyncAccessHandle — the synchronous read primitive native code expects — and hands it to the engine. When the decompressor wants the next chunk, the worker reads exactly that slice off disk, straight into the small window of wasm memory it works in. Across the whole 4.33 GiB archive, that window was measured flat at 16 MiB. The archive is 275 times larger than the memory holding it open.
The engine itself is the official unrar 7.3.2 — the extractor from the format's authors — compiled to WebAssembly by us (emscripten, -DRARDLL -DSILENT, no filesystem, no console UI). Format fidelity is not a claim we make; it is the consequence of running the reference implementation. One detail deserves its own sentence: across the JS boundary, 64-bit file handles and offsets are split into lo/hi halves — that unglamorous pair is what survives seeks past 4 GiB.
None of this is user-visible. Rar files of 1 GiB and up switch to the streaming path automatically; smaller ones keep the in-memory path, which is faster when the file is small anyway. Staged copies are kept in a small cache (two engines, two minutes idle) so reopening the same archive is instant and switching between zips does not re-copy anything.
const writable = await fileHandle.createWritable()
const reader = blob.stream().getReader()
for (;;) {
const { done, value } = await reader.read()
if (done) break
await writable.write(value)
reportProgress((written += value.byteLength))
}
await writable.close()// unrar requests size bytes of the archive at pos. Serve them
// straight from disk into the wasm heap window — the only archive
// bytes in memory are the ones this line is about to fill.
const n = source.read(mod.HEAPU8.subarray(buf, buf + size), pos)
pos += n
return n// A 64-bit offset does not fit the 32-bit wasm ABI. This
// unglamorous arithmetic is what survives seeks past 4 GiB.
jsSeek(handleLo, handleHi, offsetLo, offsetHi) {
return Module.extractor.seek(
(handleLo >>> 0) + handleHi * 0x100000000,
(offsetLo >>> 0) + offsetHi * 0x100000000,
)
}- Stage once into OPFS — browser-local, per-site, streamed in chunks (~30 s for 4.33 GiB) with a progress bar.
- A worker serves reads on demand via
FileSystemSyncAccessHandle; the wasm window stays flat at ~16 MiB. - The engine is official unrar 7.3.2 compiled to wasm by us — the reference extractor, running locally.
- 64-bit handles and offsets split lo/hi across the boundary — the detail that survives >4 GiB seeks.
- ≥1 GiB switches automatically; staged copies are cached so reopening is instant.
Porting unrar 7.x: the traps that failed silently
The port itself is small — a File class with the OS I/O swapped for JavaScript callbacks, some filesystem stubs, an embind surface. What made it take days was that every failure mode was silent: error codes stayed zero while nothing worked. Four traps, in the order they got us:
The silent veto. unrar 7.x split its UI sources into several files; without the -DSILENT define, the console UI compiles in — and quietly blocks extraction when running inside a worker. Error code: 0. Symptom: everything succeeds and nothing extracts. A build flag was the difference.
The gate named `LinksToDirs`. Among the filesystem stubs was one we defaulted to returning false, because in wasm there are no symlinks to convert. Except unrar 7.3.2 uses that return value as the "proceed to extract" gate: false means skip every file. Silently. With error code 0, again.
The missing rewind. Our JavaScript-side close(fd) did not reset the archive file descriptor's position. A second open on that handle read the RAR signature at stale end-of-file, reported "damaged archive" — and then crashed through an error path's string handling into a wasm out-of-bounds access that pointed everywhere except the actual one-line bug.
The harness that lied. We verified in Node before the browser, and Node's fs.read silently short-reads past 2 GiB — it stops at size minus 2^32 and reports success. The engine was correct; the harness under-read. We chased a phantom "wall at 83 files" through two engine versions that were both fine. The lesson now lives in the harness: every read is chunked, every chunk's length is asserted, and no layer above the one under test is trusted.
The build is pinned and reproducible — the upstream source tarball and the emsdk version are fixed, and a rebuild reproduces the shipped wasm byte-for-byte. The tests load the shipped artifact directly, so a broken rebuild fails in CI, not in production.
// The archive fd is reused across opens. Without the rewind, the
// next open reads the RAR signature at the previous end-of-file:
// "damaged archive", then a wasm out-of-bounds crash pointing
// anywhere except here.
close(fd) {
if (fd === ARCHIVE_FD) pos = 0
}// Node's fs.read silently short-reads past 2 GiB; the phantom
// "wall at 83 files" lived here, not in the engine.
let read = 0
while (read < length) {
const n = readSync(fd, buf, read, length - read, at + read)
if (n <= 0) throw new Error('short read at ' + read)
read += n
}- Without
-DSILENT, the console UI vetoes extraction in a worker — error code 0 throughout. LinksToDirsreturning false = "skip every file" in 7.3.2 — also silent, also error code 0.- A stale file position after close surfaces as "damaged archive" plus a misleading wasm crash.
- Node
fs.readshort-reads past 2 GiB silently — an unverifying harness will blame a correct engine.
The numbers
All of the following was measured on the real archive — the 4.33 GiB RAR5 with 1,134 JPEGs — in Chrome, on an ordinary laptop, through the real user interface (a scripted drag-and-drop onto the page, the same path a real drop takes):
Staging: about 30 seconds, once, with a progress bar — a local disk-to-disk copy, not an upload. Reopening the same archive later: instant, from the cached staged copy. Listing after staging: about 15 milliseconds for all 1,134 entries, because headers are read by seeking, not scanning — and the list matched bsdtar's exactly, 1,134 of 1,134. Extracting one photo: about 40 milliseconds for a 3.6 MB image, and the bytes matched a reference extraction exactly, all 3,819,555 of them.
The memory story is the one we are proudest of: the engine's working set stayed at 16 MiB, flat, from the first entry to the last — no curve that bends upward as the archive grows. And the privacy property is structural: staging, listing, and extraction all proceed with the network disconnected after page load. Nothing in the pipeline has a server to talk to.
- Staging 4.33 GiB: ~30 s once (local copy, progress bar); reopen: instant from cache.
- Listing 1,134 entries: ~15 ms — headers by seeking; matches
bsdtar1,134/1,134. - One photo (3.6 MB): ~40 ms, byte-exact against a reference extraction.
- Working set: 16 MiB, flat, first entry to last.
- Offline: page load is the only step that needs the network.
What still does not work
An engineering log that omits the remaining walls is marketing, so here are ours, explicitly:
Single-entry extraction on the rar streaming path is capped at 1 GiB per file. Extraction materializes the one file you asked for in memory, and a single entry larger than a tab can hold is the case that fails — with a clear message, not a crash. An archive of many normal files is unaffected at any total size. Streaming extraction directly to disk, which would lift this, is the next mountain.
Password-protected rar archives are not supported, at any size. We do not prompt for, store, or process rar passwords; a desktop tool remains the honest answer there. (Password-protected zip and 7z are decrypted locally, when you supply the password.)
The zip side inherits one boundary from the ceilings above: a single entry too large for browser memory cannot be extracted — though it still lists, previews, and searches fine inside archives of any size. And the streaming rar path needs OPFS synchronous handles, shipped in current Chrome, Edge, Firefox, and Safari 16.4+; on a browser without them we say so plainly, and archives under 1 GiB keep working through the standard path.
Finally, the eternal caveat: a zip bomb is not a size limit, it is a malice limit. The classic one is 42 KB and decompresses to petabytes. No architecture makes untrusted archives safe; open files from sources you trust, in any tool.
- Single rar entry: extraction capped at 1 GiB — honest error beyond, streaming-to-disk is future work.
- Password-protected rar: not supported at any size (zip and 7z passwords are, locally).
- A zip entry larger than browser memory lists but cannot be extracted.
- Streaming path needs OPFS sync handles: current Chrome/Edge/Firefox, Safari 16.4+; plain message otherwise.
Why the architecture is the product
Step back and the whole thing reduces to one observation: a size cap on an upload-based tool is a budget line. Someone pays for storage and bandwidth per gigabyte, so someone caps you — commonly at 100 or 200 MB. The cap is not a technical limit; it is an invoice.
We have no server in the pipeline. No storage bill, no bandwidth bill, and therefore no number to cap you at. The "4 GB" in this post's title is not a limit we chose — it is simply the size of the archive that walked in the door the day the ceiling annoyed us enough. The same property is the privacy property: a tool that cannot upload your file also cannot leak it, retain it, or read it, and the airplane-mode test above is the proof you can run yourself.
If you have a file that other tools refuse, try it: drop it on the rar viewer or the zip viewer. The capability pages — open large RAR files and open large zip files — have the user-facing details, and the privacy argument in full is at why client-side is safer than uploading.
- A size cap on an upload tool is an invoice, not a technical limit — commonly 100–200 MB.
- No server in the pipeline means no budget to cap: the ceiling is your machine, stated honestly.
- The same design is the privacy guarantee — verifiable with a network tab or airplane mode.