HeadlinesBriefing favicon HeadlinesBriefing.com

Mounting Tar Archives in WebAssembly Without Extraction

Hacker News •
×

Emscripten’s WORKERFS now supports mounting .tar archives by generating a JSON index of file offsets—no extraction needed in WebAssembly.

WebR’s previous optimization used metadata files to speed up R package loading. This new method extends that idea to WebAssembly, where memory is constrained. The tar-vfs-index npm package reads a tar and outputs a JSON index with filenames, start/end byte offsets, and package size—enabling direct slice-based file access. Alternatively, metadata can be embedded in the tar itself via npx tar-vfs-index --append.

Emscripten’s virtual filesystem allows zero-copy access to Blob objects via WORKERFS, serving reads from the tar’s data stream directly. Browser-native gunzip handles decompression during download, making this efficient for web deployments. This approach avoids unnecessary copying, improving speed and memory usage for applications loading data from tar archives.

The technique leverages Tar’s flat structure, WORKERFS’s blob slicing, and native compression streams to enable a seamless WebAssembly experience.