Skip to content

Commit

Permalink
avoid sizeof altogether
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudxain committed Mar 17, 2023
1 parent 5204dd7 commit 7230330
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions .functions
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,12 @@ function phpserver() {
php -S "${ip}:${port}";
}

function sizeof() {
if [ "$(uname -s)" = 'Darwin' ]; then
stat -Lf "%z" -- "$1";
else
stat -Lc "%s" -- "$1";
fi
}

# Compare original and gzipped file size
function gz() {
local origsize=$(sizeof "$1");
local origsize=$(
stat -f"%z" -- "$1" 2> /dev/null; # macOS `stat`
stat -c"%s" -- "$1" 2> /dev/null; # GNU `stat`
);
local gzipsize=$(gzip -c "$1" | wc -c);
local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l);
printf "orig: %d bytes\n" "$origsize";
Expand Down

0 comments on commit 7230330

Please sign in to comment.