Skip to content

Instantly share code, notes, and snippets.

@ewdurbin
Created July 25, 2012 03:00
Show Gist options
  • Save ewdurbin/3174127 to your computer and use it in GitHub Desktop.
Save ewdurbin/3174127 to your computer and use it in GitHub Desktop.
zomg/ compression
#!/bin/bash
compress()
{
find $1 -type d > foo
echo "files" >> foo
for file in `find $1 -type f`; do
size=$(ls -l $file | awk '{print $5}')
echo -e "$size\t$file" >> foo
done
}
decompress()
{
files=0
while read line; do
if [ "$line" == "files" ]; then
files=1
fi
if [ "$files" == "1" ]; then
echo $line
read size filename <<< `echo $line`
dd if=/dev/null of=$filename bs=1 seek=$size > /dev/null 2>&1
else
read dir <<< `echo $line`
mkdir -p $dir
fi
done < $1
}
while getopts "c:x" opt; do
case $opt in
c) COMPRESS=1 ;;
x) DECOMPRESS=1 ;;
esac
done
if [ $COMPRESS ]; then
shift $(($OPTIND - 2))
compress $1 $2
fi
if [ $DECOMPRESS ]; then
shift $(($OPTIND - 1))
decompress $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment