|
| 1 | +# `bsdtar-wasm` |
| 2 | + |
| 3 | +[](https://matrix.to/#/#haskell.wasm:matrix.org) |
| 4 | + |
| 5 | +This repo hosts a `wasm32-wasi` build of the `bsdtar` CLI from the |
| 6 | +[libarchive](https://libarchive.org) project, with |
| 7 | +[`zstd`](https://facebook.github.io/zstd) support. It can be used to |
| 8 | +extract a `.tar.zst` archive in the wasi vfs, useful when: |
| 9 | + |
| 10 | +- You need to download a large binary artifact, and the default |
| 11 | + gzip/brotli compression provided by the CDN is not good enough |
| 12 | +- You need to set up a vfs with many files, and issuing one `fetch` |
| 13 | + per file can become a bottleneck |
| 14 | + |
| 15 | +## How to use |
| 16 | + |
| 17 | +### The wasm modules |
| 18 | + |
| 19 | +There are two `wasm32-wasi` modules available here: |
| 20 | + |
| 21 | +- [`bsdtar.wasm`](https://haskell-wasm.github.io/bsdtar-wasm/bsdtar.wasm) |
| 22 | +- [`zstd.wasm`](https://haskell-wasm.github.io/bsdtar-wasm/zstd.wasm) |
| 23 | + |
| 24 | +They are command modules without any custom imports/exports, fully |
| 25 | +single-threaded, compiled with LLVM ThinLTO and optimized by |
| 26 | +`wasm-opt`, with `simd128` feature enabled. `bsdtar.wasm` only |
| 27 | +supports `zstd`, doesn't support other filters like `xz` or `gzip`. |
| 28 | + |
| 29 | +Simply run them and pass the right CLI arguments as well as the right |
| 30 | +input (either stdin or a file in the wasi vfs), then check the exit |
| 31 | +code and use the output. |
| 32 | + |
| 33 | +Prefer `zstd.wasm` when only decompressing a single file, otherwise |
| 34 | +use `bsdtar.wasm`. |
| 35 | + |
| 36 | +### The wasi implementation |
| 37 | + |
| 38 | +The wasm modules work fine with `wasmtime` and `node`/`uvwasi`. But |
| 39 | +for browsers, the only wasi implementation that works right now is |
| 40 | +[`haskell-wasm/browser_wasi_shim`](https://github.com/haskell-wasm/browser_wasi_shim), |
| 41 | +which can be directly imported from this |
| 42 | +[URL](https://esm.sh/gh/haskell-wasm/browser_wasi_shim). Upstream npm |
| 43 | +release lacks some important bugfixes at the moment. |
| 44 | + |
| 45 | +## Building |
| 46 | + |
| 47 | +The wasm-enabled forks of the relevant projects are available at: |
| 48 | + |
| 49 | +- [`haskell-wasm/zstd`](https://github.com/haskell-wasm/zstd) |
| 50 | +- [`haskell-wasm/libarchive`](https://github.com/haskell-wasm/libarchive) |
| 51 | + |
| 52 | +Start from `install-wasi.sh` in the above repos. |
| 53 | + |
| 54 | +The wasm patches are based on upstream release branches instead of |
| 55 | +development branches, and there's currently no plan to upstream them |
| 56 | +due to limited time. That being said, the heavylifting is done by |
| 57 | +upstream and the wasm patches are just bandaids to get things working |
| 58 | +for my use-case; feel free to use them as starting points for building |
| 59 | +whatever you have in mind. |
0 commit comments