. "$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 check_out xz/xzcat "$line" sh -c "xzcat '$tmp.xz'" # 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"