-
Notifications
You must be signed in to change notification settings - Fork 0
/
gz99
50 lines (42 loc) · 1.16 KB
/
gz99
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
44
45
46
47
48
49
50
#!/bin/bash
set -e
command -v advdef > /dev/null || echo advdef is not installed. Install for a better compression ratio
command -v 7z > /dev/null || echo 7z is not installed. Install for a better compression ratio
if [ -z "$1" ]
then
echo "USAGE: $0 OUTPUT.gz"
echo "Compresses stdin to OUTPUT.gz"
exit 1
fi
OUT=$1
time gzip -9 > $OUT.new
mv $OUT.new $OUT
ORIG_HASH=`gunzip < $OUT`
accept_new(){
if [ ".`gunzip < $OUT.new`" = ".$ORIG_HASH" ]
then
oldsize=$(stat -f%z "$OUT")
newsize=$(stat -f%z "$OUT.new")
if [ $oldsize -gt $newsize ]
then
echo "$oldsize->$newsize: Saved $((oldsize-newsize)) bytes."
mv -f $OUT.new $OUT
else
echo "$oldsize->$newsize: No savings, new file discarded."
fi
else
echo $OUT.new corrupt. Deleting.
rm $OUT.new
fi
}
echo Finished GZIP compression, you now have a complete gz file
#echo You can stop here, but we will try to make the file smaller for you.
#rm $OUT.new || true
#time 7z a $OUT.new -mx=9 -tgzip $OUT
#gunzip < $OUT | time 7z a $OUT.new -mx=9 -tgzip -si
#time 7z a dummy -mx=9 -tgzip -so -si $OUT.new $OUT
#accept_new
#cp $OUT $OUT.new
#echo Trying advdef compression
#time advdef -4 -z $OUT.new # instead link?
#accept_new