Created
November 8, 2017 09:00
-
-
Save noodny/e4727630272877c38d22e0d96087c269 to your computer and use it in GitHub Desktop.
Use CURL to get file size of a given url
This file contains 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
#!/bin/sh | |
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]}" | |
} | |
URL=$1 | |
if [ -z "$URL" ]; then | |
printf "\nUsage:\n\t file-size URL\n\n" | |
exit 0; | |
fi | |
NO_GZIP=$(curl "$URL" --silent --write-out '%{size_download}\n' --output /dev/null) | |
GZIP=$(curl "$URL" --silent -H 'Accept-Encoding: gzip,deflate' --write-out '%{size_download}\n' --output /dev/null) | |
echo "regular: $(bytesToHuman $NO_GZIP)" | |
echo "gzipped: $(bytesToHuman $GZIP)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment