Created
March 7, 2022 01:15
-
-
Save leaysgur/9857c9d7fc1d6fea6c7d388e9090cd1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
bytesToHuman() { | |
b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}iB) | |
while ((b > 1024)); do | |
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))" | |
b=$((b / 1024)) | |
let s++ | |
done | |
echo "$b$d ${S[$s]}" | |
} | |
compare() { | |
echo "URI: ${1}" | |
SIZE=$(curl -so /dev/null "${1}" -w '%{size_download}') | |
SIZE_HUMAN=$(bytesToHuman "$SIZE") | |
echo "Uncompressed size : $SIZE_HUMAN" | |
SIZE=$(curl --compressed -so /dev/null "${1}" -w '%{size_download}') | |
SIZE_HUMAN=$(bytesToHuman "$SIZE") | |
echo "Compressed size : $SIZE_HUMAN" | |
} | |
compare https://stackoverflow.com/q/9190190/1480391 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment