Last active
October 19, 2017 14:37
-
-
Save friartuck6000/062aa206e8a73603cb89f3eaba466bcf to your computer and use it in GitHub Desktop.
Calculate the raw and gzipped size of a file + compression percentage
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
function gzsize { | |
if [[ $1 =~ :// ]]; then | |
real=$(curl -L $1 2>/dev/null | wc -c | xargs) | |
gzipped=$(curl -L $1 2>/dev/null | gzip | wc -c | xargs) | |
else | |
real=$(cat $1 | wc -c | xargs) | |
gzipped=$(cat $1 | gzip | wc -c | xargs) | |
fi | |
compression=$(awk -v a=$real -v b=$gzipped 'BEGIN { printf "%.2f", (1 - b / a) * 100 }') | |
echo "Real: $real" | |
echo "Gzipped: $gzipped" | |
echo "Compression: $compression%" | |
} | |
alias gzs='gzsize' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment