compare.bash 631 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. ## Adapted from https://stackoverflow.com/a/47508760
  3. set -e
  4. bytesToHuman() {
  5. b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}iB)
  6. while ((b > 1024)); do
  7. d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
  8. b=$((b / 1024))
  9. let s++
  10. done
  11. echo "$b$d ${S[$s]}"
  12. }
  13. compare() {
  14. echo "URI: ${1}"
  15. SIZE=$(curl -so /dev/null "${1}" -w '%{size_download}')
  16. SIZE_HUMAN=$(bytesToHuman "$SIZE")
  17. echo "Uncompressed size : $SIZE_HUMAN"
  18. SIZE=$(curl --compressed -so /dev/null "${1}" -w '%{size_download}')
  19. SIZE_HUMAN=$(bytesToHuman "$SIZE")
  20. echo "Compressed size : $SIZE_HUMAN"
  21. }
  22. compare ${1}