. "$BST_LIB" require xz xz/present tmp=${TMPDIR:-/tmp}/bst-xz.$$ line="the quick brown fox jumps over the lazy dog 0123456789" i=0 while [ $i -lt 64 ]; do printf "%s\n" "$line"; i=$((i+1)); done > "$tmp.in" 2>/dev/null # Compress via the stream form (xz -c > file), NOT the named-file form (xz file): # on the wasm32-hwjs runtime the named-file path bails with "Function not # implemented" -- xz post-write attribute restoration (fchmod/fchown/utimes on # the output) is ENOSYS. The -c stream form touches no file attributes. check xz/compress sh -c "xz -c '$tmp.in' > '$tmp.xz'" # .xz magic is FD "7zXZ" 00; bytes 1-4 are the printable "7zXZ". Read them with # dd (bs/skip/count), not head -c: busybox head has no -c byte-count option. check_out xz/magic "7zXZ" sh -c "dd if='$tmp.xz' bs=1 skip=1 count=4 2>/dev/null" # integrity self-check of the compressed stream check xz/test xz -t "$tmp.xz" # decompress round-trip recovers the original text (unxz alternative, -c) check_out xz/roundtrip "$line" sh -c "unxz -c '$tmp.xz'" # xzcat alternative decompresses too. Invoke it as xzcat.xz -- busybox has an # xzcat applet and ash runs an applet ahead of $PATH, so a bare `xzcat` would # exercise busybox rather than this port (both providers register the name; # update-alternatives gives xz priority 100 over busybox's 50, but that only # decides /usr/bin/xzcat, which applet resolution never consults). xz and unxz # above have no busybox applet and need no such qualification. check_out xz/xzcat "$line" sh -c "xzcat.xz '$tmp.xz'" # the xz on PATH is XZ Utils, not a busybox applet wearing the same name check_out xz/is-xz-utils "XZ Utils" xz --version # byte-for-byte identity of the round-trip unxz -c "$tmp.xz" > "$tmp.out" 2>/dev/null check xz/identical cmp -s "$tmp.in" "$tmp.out" rm -f "$tmp.in" "$tmp.xz" "$tmp.out"