mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2025-12-12 20:11:29 -06:00
Improve compression script with summary/analysis
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
multicompress() {
|
multicompress() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
@@ -15,6 +16,30 @@ multicompress() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commas() {
|
||||||
|
sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'
|
||||||
|
}
|
||||||
|
|
||||||
|
get_size() {
|
||||||
|
find ./dist/ -type f -name $1 -print0 | du --files0-from=- -bc | tail -n1 | awk '{print $1}' | commas
|
||||||
|
}
|
||||||
|
|
||||||
export -f multicompress
|
export -f multicompress
|
||||||
|
|
||||||
|
# find only non-compressed files in dist folder
|
||||||
|
FILES=$(find ./dist/ -type f ! -name '*.gz' ! -name '*.br' ! -name '*.zst')
|
||||||
|
|
||||||
# create pre-compressed variants gzip, zstd, brotli for dist files
|
# create pre-compressed variants gzip, zstd, brotli for dist files
|
||||||
find ./dist/ -type f ! -name '*.gz' ! -name '*.br' ! -name '*.zst' -exec bash -c 'multicompress "$0"' {} \;
|
echo "$FILES" | xargs -n1 -P0 bash -c 'multicompress "$@"' _
|
||||||
|
|
||||||
|
# calculate sizes
|
||||||
|
ORIGINAL_SIZE=$(echo "$FILES" | tr '\n' '\0' | du --files0-from=- -bc | tail -n1 | awk '{print $1}' | commas)
|
||||||
|
GZIP_SIZE=$(get_size '*.gz')
|
||||||
|
ZSTD_SIZE=$(get_size '*.zst')
|
||||||
|
BROTLI_SIZE=$(get_size '*.br')
|
||||||
|
|
||||||
|
export LC_NUMERIC="C.utf8"
|
||||||
|
printf "Original size: %s bytes\n" $ORIGINAL_SIZE
|
||||||
|
printf "Gzip size: %s bytes\n" "$GZIP_SIZE"
|
||||||
|
printf "Zstd size: %s bytes\n" "$ZSTD_SIZE"
|
||||||
|
printf "Brotli size: %s bytes\n" "$BROTLI_SIZE"
|
||||||
|
|||||||
Reference in New Issue
Block a user