How to Read a 2GB ZIP File in the Browser Without Crashing Mobile RAM (Zero Dependencies)
If you call await file.arrayBuffer() on a 1.5 GB Google Takeout or WhatsApp chat export ZIP inside a mobile browser, the tab dies before your parser runs a single line. Most "year-in-review" web tools dodge that limit b
If you call await file.arrayBuffer() on a 1.5 GB Google Takeout or WhatsApp chat export ZIP inside a mobile browser, the tab dies before your parser runs a single line.
Most "year-in-review" web tools dodge that limit by asking users to upload the entire archive to a backend server. When I built WrapMyChats to generate private 2026 Wrapped cards for ChatGPT, Gemini, Claude, and WhatsApp chats, uploading raw personal chat histories was a non-starter. Everything had to run strictly in local browser memory, even with Airplane Mode turned on.
The trick is that a ZIP archive is indexed from the end of the file, and modern browsers already ship the two APIs you need to random-access a single file inside it with zero npm packages: Blob.slice() and DecompressionStream("deflate-raw").
Why JSZip + arrayBuffer() blows up on large archives
A typical Google Takeout Gemini export or a WhatsApp "With Media" export ZIP might be 1–2 GB, while the actual chat transcript (MyActivity.html, conversations-000.json, or _chat.txt) is only 5–20 MB. The other 98% is photos, voice notes, and video attachments.
Reading the whole ZIP into memory wastes gigabytes of RAM just to reach one text entry.
The 3-Slice Random Access Pattern
A ZIP file stores its directory table (the Central Directory) near the tail of the file, pointed to by a 22-byte End of Central Directory (EOCD) record (0x06054b50).
Instead of loading the whole File, you only make 3 small Blob.slice() reads:
- Read at most the last
65,557bytes (64 KBmax comment + 22-byte EOCD) to find0x06054b50. - Read the Central Directory range (
cdOffsettocdOffset + cdSize) to list every filename, byte offset, and compressed size. - Slice only the single chat entry's compressed bytes and pipe them into
DecompressionStream("deflate-raw").
Here is the core slice wrapper and EOCD reader I use in production:
function createSliceSource(file) {
return {
size: file.size,
async readRange(start, length) {
const s = Math.max(0, start);
const e = Math.min(file.size, s + Math.max(0, length));
const ab = await file.slice(s, e).arrayBuffer();
return new Uint8Array(ab);
},
};
}
function findEocdOffset(view) {
for (let pos = view.byteLength - 22; pos >= 0; pos -= 1) {
if (view.getUint32(pos, true) === 0x06054b50) return pos;
}
return -1;
}
Once you locate the target entry in the Central Directory, skip its local file header (30 + fileNameLen + extraLen bytes), slice compressedSize bytes, and inflate them natively:
async function inflateRawBytes(compressedBytes) {
const ds = new DecompressionStream("deflate-raw");
const writer = ds.writable.getWriter();
writer.write(compressedBytes);
writer.close();
const reader = ds.readable.getReader();
const chunks = [];
let total = 0;
while (true) {
const { value, done } = await reader.read();
if (done) break;
chunks.push(value);
total += value.byteLength;
}
const out = new Uint8Array(total);
let offset = 0;
for (const chunk of chunks) {
out.set(chunk, offset);
offset += chunk.byteLength;
}
return out;
}
In a real 2026 Google Takeout export test, the entire parse completes in 4 Blob.slice() calls, never touching a single image or video byte inside the ZIP.
Three Real-World Edge Cases That Broke Early Versions
Reading the ZIP spec is the easy part. Real user exports get messy fast:
-
ZIP64 overflows: Archives with large offsets set
cdOffsetto0xffffffff. Check 20 bytes before the EOCD for the ZIP64 locator signature (0x07064b50) and read the 64-bit offsets withDataView.getBigUint64(). -
Sharded OpenAI exports: Newer ChatGPT exports split large histories across
conversations-000.json,conversations-001.json, etc. Reading only the first match silently drops months of prompts, and walking every node double-counts edited drafts unless you follow thecurrent_nodeparent chain. -
Localized filenames and timestamps: Google Takeout translates both folder names and HTML filenames into the account's UI language (for example,
Takeout/我的活动/Gemini Apps/我的活动记录.html), and WhatsApp switches betweenMM/DD/YY,DD/MM/YYYY, andYYYY/MM/DDdepending on OS locale.
Try It Offline
If you want to inspect the technique in action, open WrapMyChats (or the dedicated WhatsApp Wrapped analyzer), switch on Airplane Mode or watch the DevTools Network tab, and drop an export ZIP in. Zero bytes leave the browser tab.
If you've run into browser quirks with DecompressionStream("deflate-raw") on older Safari builds or huge multi-part archives, drop them in the comments.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.