October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

Handling Files Over 2 GB with WebAssembly in the Browser

Process files over 2 GB in the browser by keeping only bounded chunks in memory, carrying parser state across chunks, and writing output incrementally. WebAssembly's memory limits are address-space limits, not file-size limits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To process a file larger than 2 GB in WebAssembly in the browser, you do not load the file into memory. You read it in bounded byte ranges or stream chunks, pass each chunk through WebAssembly, keep only the parser or codec state needed to continue, and write output incrementally to a destination that accepts it. The file’s total size and the amount of memory held at any moment are separate questions, and the design only works when you keep them separate. The WebAssembly memory limits you will read about describe address space, not how large a file you can handle.

Why file size and memory use are different problems

A WebAssembly module’s linear memory is a contiguous range of addresses the module can read and write. Its maximum size limits how much the module can address at one time. It says nothing about how big an input file may be. A 6 GB video can be transcoded, hashed, or scanned in a browser tab if the program only ever holds a few megabytes of it. A 300 MB file can still fail if the program copies it three times.

As an Amazon Associate I earn from qualifying purchases.

The practical question is therefore a budget: how many bytes must exist simultaneously for the algorithm to make progress? Every design decision in this guide follows from that number. If the algorithm can work on one region and discard it before reading the next, the file can be arbitrarily large. If it needs random access across the whole file, a Wasm memory limit is no longer the binding constraint; the algorithm itself must change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The limits that matter and what they mean

The WebAssembly JavaScript Interface defines memory in pages. One page is 65,536 bytes (64 KiB). The maximum sizes are:

#1 Best Overall
Sale
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty
Memory type Maximum pages Maximum size What the limit does not promise
32-bit memory (wasm32) 65,536 4 GiB That an allocation of this size will succeed on a given device or browser.
64-bit memory (memory64) 262,144 16 GiB That the browser will allocate this much, or that every shipping browser supports memory64.

The specification states that implementations can run out of resources below these maxima. In practice, the usable limit depends on the browser, the operating system, the other tabs competing for memory, and whether the page is running on a 32-bit or 64-bit browser build. These maxima are upper bounds on the formal model, not a measurement of what a reader’s laptop will allocate.

Two further points follow from the page-based model. Memory is always requested in whole pages, so a request for a few bytes more than a page boundary costs a full 64 KiB. And a file size that is a multiple of your chunk size is not required; the last chunk is simply shorter.

Input: reading the file in bounded ranges

A File is a subtype of Blob. The mistake that causes most out-of-memory failures is calling file.arrayBuffer() on the whole file, which asks the browser to materialize every byte at once. Use one of two bounded primitives instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds | USB Flash Drive, Up to 15x Faster than standard 2.0, Password Protection, Durable, Sleek Metal Casing, USB 3.0, Silver/Black
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]
  • Byte ranges with slice(). file.slice(start, end) returns a new Blob that refers to the selected bytes. Reading that Blob is what loads data, so the slice itself is cheap. You control the window by changing start and end.
  • Streaming with stream(). file.stream() returns a ReadableStream of raw bytes. You consume chunks as they arrive, and the browser delivers them in pieces rather than as one buffer. This suits sequential algorithms such as compression, hashing, and line-oriented parsing.

Choose the method by access pattern. Sequential processing fits the stream. Processing that needs to jump between offsets (for example, reading a container’s index at the end of the file first) fits repeated slice() calls. A minimal sequential loop using slices looks like this:

const CHUNK_BYTES = 16 * 1024 * 1024; // an example size, not a recommendation
for (let offset = 0; offset < file.size; offset += CHUNK_BYTES) {
  const end = Math.min(offset + CHUNK_BYTES, file.size);
  const bytes = new Uint8Array(await file.slice(offset, end).arrayBuffer());
  await processChunk(bytes, offset === 0, end === file.size);
}

The chunk size should come from measurement on your target devices, not from a universal figure. Larger chunks reduce per-call overhead; smaller chunks lower peak memory. Sources for this topic do not establish an optimal size for any algorithm, so measure peak memory with your own workload.

Two rules keep input bounded:

  • Do not queue chunks faster than they are consumed. With streams, read the next chunk only after the previous one has been processed. An unbounded array of pending chunks reintroduces the whole file in memory.
  • Carry parser or codec state across chunk boundaries. A record, token, or compressed block may straddle two chunks; keep the unfinished tail and prepend it to the next chunk rather than discarding it.

The WebAssembly boundary: copying in, reusing buffers, and memory growth

Each chunk must be copied into Wasm linear memory before the module can read it. Keep that copy bounded by reusing one input region rather than allocating a new one per chunk. The usual pattern is to reserve an input buffer once, write each chunk into it, call the module, then reuse the same region for the next chunk.

Rank #3
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers
  1. Allocate a fixed input region in linear memory sized to your chunk limit, plus any output buffer you need.
  2. Create a Uint8Array view over memory.buffer at that region and set() the chunk bytes into it.
  3. Call the exported processing function, passing the region’s pointer and length.
  4. Read any output from Wasm memory, write it to the output destination, and release or reuse the buffers before accepting the next chunk.

Growth needs care. When linear memory grows, the ArrayBuffer exposed as memory.buffer is replaced, and the old buffer is detached. Any typed array or DataView created before growth still points at the detached buffer and will report zero length or throw on access. After any call that might grow memory, read memory.buffer again and recreate every view. A common pattern is a small helper that always derives views from the current buffer instead of caching them.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Avoid holding a second full-size copy in either JavaScript or Wasm memory. A pattern that reads a chunk into a JavaScript array and then copies it into Wasm, while keeping the original array alive for a later step, doubles the working set. Drop references to chunk arrays as soon as their bytes are in Wasm memory.

Output: writing results incrementally

If the output is also large, write it to disk as it is produced rather than assembling it in memory. In supporting browsers, the File System API provides this through a writable stream:

Rank #4
Sale
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.
  1. Obtain a FileSystemFileHandle from a user action, typically a save-file picker.
  2. Call handle.createWritable() to create a FileSystemWritableFileStream.
  3. Call write() with each output chunk, in order.
  4. Call close() to commit the written data. Output is not committed to the file until the stream is closed.
  5. If processing fails or the user cancels, call abort() on the stream so the partial output is discarded rather than committed.

This API has constraints that affect design:

  • It requires a secure context (HTTPS or localhost in typical deployments).
  • It requires the user’s permission. A call made without an activation from the user, or after permission is refused, cannot write.
  • Each write() can fail with QuotaExceededError when the origin’s storage quota is exhausted. Treat this as an expected failure path, not an exception to log and ignore.
  • The documentation for these APIs does not promise a maximum output file size. Test writes of your expected output size on the browsers and devices you support.

Where the API is unavailable, check for it with feature detection and fall back to a different path. Options include generating a Blob download for outputs that fit comfortably in memory, or sending input to a server for processing when browser-side streaming is not possible.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Memory64: when a larger address space is the right tool

The memory64 proposal extends WebAssembly to 64-bit memory indexes, allowing linear memory larger than 4 GiB. The JavaScript Interface’s maximum for this memory type is 16 GiB, as noted above. WebAssembly.org’s portability guidance describes wasm64 in the same terms: larger linear memory with 64-bit pointers or indices.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Memory64 changes the address model. It does not change what your algorithm needs to hold at once. A program that streams a 3 GB file in 16 MiB chunks gains nothing from memory64, and it adds a compatibility requirement. Use memory64 only when the algorithm genuinely needs one contiguous working set larger than 4 GiB, such as a large in-memory index that cannot be partitioned.

Best Value
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.

Browser support must be checked directly. The memory64 proposal’s implementation-status table listed Firefox and V8/Chrome as done and Safari with an unknown status when reviewed. That table is maintained in the proposal repository and is not a per-version shipping compatibility list, so verify current browser versions before relying on it. Feature-detect at runtime: attempt to instantiate a module that declares a 64-bit memory, and choose a fallback path if it fails.

Comparing the two approaches

Approach Memory behavior Portability and constraints When it fits
Chunked processing with wasm32 Holds a bounded input region and working data; the whole file is never resident. Relies on the Blob slice() and stream() APIs; requires careful backpressure, state carry-over, and bounded copies. The default for files above 2 GB when the algorithm can run incrementally.
Memory64 with a larger in-memory working set Allows a formal linear address space up to 16 GiB, but actual allocation depends on the device and browser. Browser support must be verified per version; the implementation-status table is not a shipping compatibility guarantee. Only when the algorithm needs one addressable working set beyond 4 GiB and target browsers have been verified.

These are not interchangeable ways to handle larger files. Chunking is a memory-management strategy. Memory64 changes the size of the address space available to a single module.

Failure modes and how to handle them

  • Whole-file reads. Any call to arrayBuffer(), text(), or equivalent on the complete File defeats the design. Search your code for these calls on the input.
  • Accumulating chunks. Collecting processed output in a JavaScript array and combining it at the end reproduces the file size in memory. Write output as you go.
  • Stale views after growth. Errors reading zero-length arrays or access to detached buffers usually mean a typed array was created before a memory growth and not refreshed.
  • Algorithms that need global access. Whole-file indexing, random access across the full input, or a sort over all records cannot be made bounded by chunking alone. These need a redesign, intermediate storage on disk, or a server-side path.
  • Cancellation and failure during writing. If the user cancels or processing throws, call abort() on the writable stream. Without this, you may leave the user with a confusing state about what was saved.
  • Permission and quota failures. Permission denial and QuotaExceededError should show a specific message and offer a retry or alternative, not a generic crash.

Testing before you ship

Test on the device classes and browsers your users actually run. Use files that are above 2 GB, not only the largest file you expect in normal use, so that boundary arithmetic, offset handling, and final partial chunks are exercised. Watch peak memory during the run rather than only checking that the output is correct. Verify that output bytes match a reference implementation on a smaller file that you can also process in one piece, because chunk-boundary bugs often appear only on the seam between chunks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Confirm the behavior when permission is refused, when the storage quota is reached partway through writing, and when the user closes the tab during processing. Each of these leaves a different state, and each should end with either a complete committed output or no output at all.

“

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.