. "$BST_LIB" require brotli brotli/present tmp=${TMPDIR:-/tmp}/bst-brotli.$$ 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 (brotli -c > file), NOT the named-file form # (brotli file): on the wasm32-hwjs runtime the named-file path restores the # output's attributes (fchmod/utimes) and bails with "Function not implemented" # -- those calls are ENOSYS. The -c stream form touches no file attributes. check brotli/compress sh -c "brotli -c '$tmp.in' > '$tmp.br'" # brotli's stream is headerless (no magic bytes) -- prove it actually shrank the # highly-repetitive input instead of storing it. insz=$(wc -c < "$tmp.in" 2>/dev/null) brsz=$(wc -c < "$tmp.br" 2>/dev/null) if [ -n "$brsz" ] && [ "$brsz" -lt "$insz" ]; then bst_ok brotli/smaller else bst_notok brotli/smaller "br=$brsz in=$insz"; fi # integrity self-check of the compressed stream check brotli/test brotli -t "$tmp.br" # decompress round-trip recovers the original text check_out brotli/roundtrip "$line" sh -c "brotli -d -c '$tmp.br'" # byte-for-byte identity of the round-trip brotli -d -c "$tmp.br" > "$tmp.out" 2>/dev/null check brotli/identical cmp -s "$tmp.in" "$tmp.out" rm -f "$tmp.in" "$tmp.br" "$tmp.out"