-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add script to generate compression heatmaps
Add script to wrap gzthermal¹ and generate compression efficiency heatmap images for files and/or URLs. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ¹ http://encode.ru/threads/1889-gzthermal-pseudo-thermal-view-of-Gzip-Deflate-compression-efficiency
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/bin/bash | ||
|
||
# DESCRIPTION: | ||
# | ||
# Generate compression efficiency | ||
# heatmap images for files / URLs. | ||
# | ||
# USAGE: | ||
# | ||
# get-compression-heatmap URL/FILE ... | ||
# | ||
# USEFUL LINKS: | ||
# | ||
# http://encode.ru/threads/1889-gzthermal-pseudo-thermal-view-of-Gzip-Deflate-compression-efficiency | ||
|
||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
|
||
get_script() { | ||
|
||
declare -r OS_NAME="$(uname -s)" | ||
local script="gzthermal" | ||
|
||
# http://encode.ru/threads/1889-gzthermal-pseudo-thermal-view-of-Gzip-Deflate-compression-efficiency | ||
|
||
if [ "$OS_NAME" == "Darwin" ]; then | ||
script="$script/osx" | ||
elif [ "$OS_NAME" == "Linux" ]; then | ||
script="$script/linux" | ||
|
||
if [ "$(uname -m)" == "x86_64" ]; then | ||
script="${script}-64" | ||
else | ||
script="${script}-32" | ||
fi | ||
fi | ||
|
||
printf "%s" "$(dirname "${BASH_SOURCE}")/$script" | ||
|
||
} | ||
|
||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
|
||
main() { | ||
|
||
declare -r script=$(get_script) | ||
|
||
local cmd="" | ||
local tmpFile="" | ||
|
||
# Check if `cURL` is installed | ||
if [ ! -x "$(command -v "curl")" ]; then | ||
printf "Please install cURL!\n" | ||
exit; | ||
fi | ||
|
||
while [ $# -ne 0 ]; do | ||
|
||
tmpFile="/tmp/$(mktemp -u XXXXX).gz" | ||
|
||
# Check if the current command line arguments is a local file | ||
if [ -f "$1" ]; then | ||
cmd="cat" | ||
|
||
# If it's not, assume it is a URL | ||
else | ||
cmd="curl -sSL" | ||
fi | ||
|
||
printf " * %s\n" "$1" | ||
|
||
# Generate the heatmap image | ||
${cmd} "$1" | tee >(gzip > "$tmpFile") &> /dev/null \ | ||
&& ${script} "$tmpFile" \ | ||
&& rm -rf "$tmpFile" \ | ||
&& mv "gzthermal-result.png" "$(printf '%s.png' "$1" | sed -e 's/\//-/g')" \ | ||
|
||
shift | ||
|
||
done | ||
|
||
} | ||
|
||
main "$@" |
Binary file not shown.
Binary file not shown.
Binary file not shown.