Skip to content

Instantly share code, notes, and snippets.

@leaysgur
Created March 7, 2022 01:15
Show Gist options
  • Save leaysgur/9857c9d7fc1d6fea6c7d388e9090cd1d to your computer and use it in GitHub Desktop.
Save leaysgur/9857c9d7fc1d6fea6c7d388e9090cd1d to your computer and use it in GitHub Desktop.
#!/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