Mounting tar archives as a filesystem in WebAssembly

(jeroen.github.io)

40 points | by datajeroen 3 hours ago

5 comments

  • Lerc 12 minutes ago
    I did some similar shenanigans when I did a silly little system on NeoCities https://lerc.neocities.org/

    It uses IndexedDB for the filesystem.

    Rather Dumbly it is loading the files from a tar archive that is encoded into a PNG because tar files are one of the forbidden file formats.

  • Ecco 1 hour ago
    How about using a format that has actually been designed to be a compressed read-only filesystem? Something like a SquashFS or cramfs disk image?
    • johannes1234321 22 minutes ago
      When looking at established file formats, I'd start with zip for that usecase over tarballs. zip has compression and ability to access any file. A tarfule you have to uncompress first.

      SquashFS or cramps or such have less tooling, which makes the usage for generating, inspecting, ... more complex.

    • stingraycharles 1 hour ago
      Sometimes (read: very often) you can’t choose the format. Obviously if squashfs is available that is a better solution.
  • sillysaurusx 2 hours ago
    Only peripherally relevant, but also see Ratarmount: https://github.com/mxmlnkn/ratarmount

    It lets you mount .tar files as a read only filesystem.

    It’s cool because you basically get random access to the tarball without paying any decompression costs. (It builds an index saying exactly where so-and-so is for every file.)

  • haunter 7 minutes ago
    Now I want to try how does that work with BTFS which in a similar vein mounts a torrent file or magnet link as a read only directory https://github.com/johang/btfs
  • phiresky 1 hour ago
    I'm a bit disappointed that this only solves the "find index of file in tar" problem, but not at all the "partially read a tar.gz" file problem. So really you're still reading the whole file into memory, so why not just extract the files properly while you are doing that? Takes the same amount of time (O(n)) and less memory.

    The gzip-random-access problem one is a lot more difficult because the gzip has internal state. But in any case, solutions exist! Apparently the internal state is only 32kB, so if you save this at 1MB offsets, you can reduce the amount of data you need to decompress for one file access to a constant. https://github.com/mxmlnkn/ratarmount does this, apparently using https://github.com/pauldmccarthy/indexed_gzip internally. zlib even has an example of this method in its own source tree: https://github.com/gcc-mirror/gcc/blob/master/zlib/examples/...

    All depends on the use case of course. Seems like the author here has a pretty specific one - though I still don't see what the advantage of this is vs extracting in JS and adding all files individually to memfs. "Without any copying" doesn't really make sense because the only difference is copying ONE 1MB tar blob into a Uint8Array vs 1000 1kB file blobs

    One very valid constraint the author makes is not being able to touch the source file. If you can do that, there's of course a thousand better solutions to all this - like using zip, which compresses each file individually and always has a central index at the end.