AI Briefing
KO

Mounting tar archives as a filesystem in WebAssembly

·2026.04.24 19:13

Key point

Introduced a method to mount tar.gz directly as a filesystem in WebAssembly without extracting it.

Details

Instead of extracting tar.gz, a JSON index containing the file offsets and sizes within the tar is created and mounted directly into Emscripten's WORKERFS.

This approach leverages tar's 512-byte headers and contiguous data structure. tar-vfs-index reads a tar or tar.gz stream to generate file_packager-compatible metadata, recording the start/end byte range for each file.

The mounting procedure is as follows.

  • Fetch the tar.gz and metadata together with fetch().
  • Decompress the tar data using the browser's DecompressionStream('gzip') to create a Blob.
  • Connect it to the virtual filesystem with FS.mount(WORKERFS, { packages: [{ metadata, blob }] }, '/pkg').

This way, when C/C++ code reads a file, only the needed range of the Blob is sliced, so files don't need to be extracted separately. WebR applied this approach to R package distribution, improving loading speed and memory efficiency while still using plain tar.gz on a static server.

Another approach is to append the index to the end of the tarball using the --append option to distribute it as a single file. The loader first separates the embedded metadata, then mounts it the same way.

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.