Skip to content

Instantly share code, notes, and snippets.

@friartuck6000
Last active October 19, 2017 14:37
Show Gist options
  • Save friartuck6000/062aa206e8a73603cb89f3eaba466bcf to your computer and use it in GitHub Desktop.
Save friartuck6000/062aa206e8a73603cb89f3eaba466bcf to your computer and use it in GitHub Desktop.
Calculate the raw and gzipped size of a file + compression percentage
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