-
Notifications
You must be signed in to change notification settings - Fork 109
/
gzipped-size
executable file
·43 lines (36 loc) · 1.01 KB
/
gzipped-size
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
#
# Print statistics on gzipped vs uncompressed size of files
#
# Example:
# $ cat dotfiles-install.gif | gzipped-size .gitattributes - README.md
# .gitattributes : 560 bytes (versus 973 bytes)
# stdin : 312712 bytes (versus 329123 bytes)
# README.md : 682 bytes (versus 1184 bytes)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/cross-platform-utils.bashlib
FILES="$@"
MAX_NAME_SZ="$(for f in "$FILES"; do echo $f|wc -c; done | sort -n | tail -1)"
handle_stdin(){
local tmp=$(mktemp)
local gz_sz="$(tee $tmp | gzip -c - | wc -c)"
local sz="$(wc -c $tmp)"
print_stats "stdin" $tmp
}
print_stats(){
local name="$1"
local file="$2"
printf "%-${MAX_NAME_SZ}s : %s bytes (versus %s bytes)\n" "$name" "$(gzip -c $file | wc -c)" "$(util.size $file)"
}
if [[ -z $FILES ]]; then
handle_stdin
exit
fi
for f in $@; do
if [[ $f == "-" ]]; then
handle_stdin
else
print_stats "$f" "$f"
fi
done
# vim: set ft=sh